• Hello,

    I have a site with about 10 or so categories. Some general announcements must be published under all the categories making my post meta very clunky listing out each of the categories with the_category.

    Is there a way to force the_category to display “ALL” (and maybe link back to my blog url) if the post is published under all categories?

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You could replace the_category with something like this:

    <?php if (in_category('ALL')) { ?>
       <a href="<?php bloginfo('url'); ?>" >ALL</a>
    <?php } else {
       the_category(', ');
    } ?>

    a bit intensive to get and compare the numbers of categories:
    post vs. blog:

    <?php
    $the_post_cats = wp_get_post_categories(get_the_ID());
    $all_the_cats = get_categories();
    if(count($the_post_cats)==count($all_the_cats)) { echo '<a href="'.get_bloginfo('url').'" >ALL</a>'; }
    else { the_category(', ');
    } ;
    ?>

    Can you just assign the category ‘ALL’ as a second category to each of the general announcement posts and use the code I showed earlier? That way you won’t need to change the code if you add new general announcement categories.

    Otherwise, you might be able to use something like this:

    <?php if (in_category('ga-1') && in_category('ga-2') && in_category('ga-3') && ... ) { ?>
       <a href="<?php bloginfo('url'); ?>" >ALL</a>
    <?php } else {
       the_category(', ');
    } ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘the_category display ALL if posted under all categories’ is closed to new replies.