WordPress.org

Ready to get started?Download WordPress

Forums

If Query Post Returns 1 Post (2 posts)

  1. Nasir Zia
    Member
    Posted 1 year ago #

    Hi,
    I have been using Query Post for a newsticker which I have created so that the user navigate through the number of news by simply pressing Next & Previous buttons.
    But in case if there is only 1 news (i.e, only 1 post returned then there is no point of having Prev and Next button).

    I will simply assign css attribute Display: none to the prev and next button if there is only 1 post. But how to find out if the query post returned just 1 post.

    query_posts('post_type=post&cat=20&post_status=publish&order=DESC');
    
    while (have_posts()): the_post();

    Thanks

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    Try it with this:

    query_posts('post_type=post&cat=20&post_status=publish&order=DESC');
    global $wp_query;
    $post_count = $wp_query->post_count;
    if($post_count <= 1) {
    // only one post'
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags