• Resolved ryanfurtner

    (@ryanfurtner)


    If I can just store the total number of post snippets as a variable and use it in my template, I will have finally finished a project I’ve been working on all week!

    Is it possible to get?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi Ryan

    Thanks for getting in touch!

    If you are done with the site (and won’t be adding more snippets), the simplest solution would be to just count them and add the number statically in your theme.

    If your snippets change, you will want to get this dynamically I assume? In that case you will need to get the snippet data and count the amount of snippets. Snippets are stored as an option in the WordPress options table. You will need some coding experience to get that data and amount. Can you handle that?

    By the way, Johan and I have agreed that I will take over development of Post Snippets. You can read more on https://www.postsnippets.com. When version 3.0 comes out the snippets will be stored differently, so if you use the dynamic method you will probably need to change that.

    Please let me know if you have any issues or suggestions!
    And let me know if that helped ??

    Kind regards
    David

    Thread Starter ryanfurtner

    (@ryanfurtner)

    Right okay, I’ll take a look at counting wordpress options dynamically. Is there an option name like post_snippets or something? To put me on the right track?

    I’m making a template that I will be using for turnkey website clients so it needs to be dynamic.

    I’m assuming you’ll be changing over to a custom post type, which will be awesome!

    Hi Ryan

    It’s post_snippets_options, you’ll need to unserialize the contents and then count the items in the array.

    Yes, CPT’s, it should be a nice improvement indeed.

    Greetings
    David

    Thread Starter ryanfurtner

    (@ryanfurtner)

    					<?php
    					$snippetCount = 0;
    				    $post_snippets = get_option( 'post_snippets_options' );
    				    foreach ($post_snippets  as $snippet )
    				        $snippetCount++;
    					?>
    

    Thanks David!

    Awesome!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘I need to get the total number of snippets’ is closed to new replies.