• Greetings,

    I am still a greenie on PHP coding, how can i make a short code that counts the numbers of post (all post)?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • schulte

    (@schulte)

    Nunivo,

    What exactly are you trying to accomplish? Display the total amount of published posts?

    Thread Starter Buddypressnewb

    (@nunivo)

    @schulte

    I am busy with job site that counts the active jobs and resumes. I also want something that counts the number of post (articles).

    The theme that i use supports short codes (on the frontpage), for the above the theme developer made a short code. But a counter for post is behind their support (that’s understandable).

    A fuction code that generates this short code, would solve my problem.

    Thank you.

    schulte

    (@schulte)

    Nunivo,

    Place the following at the end of your themes functions.php file and then add something like Number of Posts: [post_count] on your post or page to display the number of published posts.

    function my_post_count() {
    	$count_posts = wp_count_posts();
    	$published_posts = $count_posts->publish;
    
    	return $published_posts;
    }
    add_shortcode('post_count', 'my_post_count');
    add_filter('my_post_count', 'do_shortcode');
    /* End Shortcode Post Count [post_count] */

    lifted from from Digital Raindrops: https://wordpress.org/support/topic/inserting-a-variables-value-into-a-post

    Thread Starter Buddypressnewb

    (@nunivo)

    @schulte

    Many thanks a friend of my helped me with adjusting the code, this is code that he gave me:

    function my_post_count() {
    $count_posts = wp_count_posts();
    $published_posts = $count_posts->publish;

    return $published_posts;
    }
    add_shortcode(‘my_post_count’, ‘my_post_count’);

    Thanks for the help.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Post Counter Short Code’ is closed to new replies.