Forums

Exclude a certain category in a post (4 posts)

  1. jasoncho3
    Member
    Posted 1 year ago #

    Hello,

    I added two categories to an article

    (ex. Posted in 'General' and 'Design')

    However, I do not want 'General' to display.

    Any thoughts?

  2. Monkeyboy
    Member
    Posted 1 year ago #

    I'd like to know how to do this as well.

  3. SpankMarvin
    Member
    Posted 1 year ago #

    There might be a way to do this using get_the_tags. Modifying the codex example:

    <?php
    $ignore_tags = array("general", "another-tag-slug");
    $posttags = get_the_tags();
    if ($posttags) {
    foreach($posttags as $tag) {
    if( !in_array($tag->slug, $ignore_tags) ) {
    echo $tag->slug . ' ';
    }
    }
    }
    ?>

    Referencing the codex, you could presumably do this by defining id numbers too. I haven't tested the above but would imagine it'd work?

    J

  4. SpankMarvin
    Member
    Posted 1 year ago #

    Incidentally, is there a reason why you are not just removing the 'general' tag from these posts, or in fact removing the tag entirely?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags