WordPress.org

Support

Support » How-To and Troubleshooting » the_category display ALL if posted under all categories

the_category display ALL if posted under all categories

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.
Skip to toolbar