WordPress.org

Ready to get started?Download WordPress

Forums

Conditional based on amount of post in cat (2 posts)

  1. mkjar
    Member
    Posted 2 years ago #

    I am building a featured content gallery in my template which will be generated by a category like 'slideshow-1'.

    I want to set up a conditional statement so in the case that I only have one post in the 'slideshow-1' category the template will then load just the featured image styled to look like a static version of the slider instead of the actual slider.

    something like
    if ( cat='slideshow-1' has more than one post){
    // show slider
    }
    else (cat='slideshow-1' has only one post) {
    // show static featured image and title excerpt.
    }

    My question is there a conditional for 'more than 1 post in cat' or ' 'just one1 post in cat'?

    thanks!

  2. James Laws
    The WP Ninjas
    Posted 2 years ago #

    You could do something like this... (Where '1' is the id of the category you are checking.

    $cat_count = get_category('1')->count;
    if( $cat_count == 1 ) {
       // DO STUFF
    }

Topic Closed

This topic has been closed to new replies.

About this Topic