• Resolved Shunarjuna

    (@shunarjuna)


    I am using a plugin shortcode to display a list of blog posts by users on their own custom post type (sort of a user profile page).
    I am using this code to display the number of posts
    <h3><?php the_author(); ?> has contributed <?php the_author_posts(); ?> articles to the blog</h3>
    and below that goes the shortcode.
    How do I display this only if the user has made contributions to the blog. At the moment it says “(User) has contributed 0 articles to the blog” or “(User) has contributed 1 articles to the blog”
    I would also like it to use the singular “article” if the number is 1.
    Samples: http://www.teachmemusic.com.au/listings/more-test/
    http://www.teachmemusic.com.au/listings/test-required-fields/

    about half way down the page.
    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Change the function that you’re using, and it will work the way that you want it to (with a few small logic changes added).

    <?php $articles = get_the_author_posts(); ?>
    <?php if ($articles > 0): ?>
        <h3><?php the_author(); ?> has contributed <?php echo $articles; ?> articles to the blog</h3>
    <?php endif; ?>
    Thread Starter Shunarjuna

    (@shunarjuna)

    That’s excellent. Thank you so much. You’re a champion!

    I would also like it to use the singular “article” if the number is 1.

    adapt the one line:

    <h3><?php the_author(); ?> has contributed <?php echo $articles; ?> article<?php echo ($articles != 1?'s':''); ?> to the blog</h3>

    Thread Starter Shunarjuna

    (@shunarjuna)

    Wow, that’s perfect now. You rock.
    I was actually using elseif then repeating the line with “article” instead of “articles”
    Your way is much much better, thank you.

    Thread Starter Shunarjuna

    (@shunarjuna)

    Just closing the thread.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display number of posts by user, only if they have any.’ is closed to new replies.