WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] how to hide category listing in post (29 posts)

  1. dkblackhawk
    Member
    Posted 5 years ago #

    i have looked everywhere and cant find it. Someone help me please

  2. MichaelH
    Member
    Posted 5 years ago #

    You mean when it displays the posts on your blog?

    Or when you are writing post you don't want to see the category choices?

  3. MichaelH
    Member
    Posted 5 years ago #

    Here's the text from your other thread, which I deleted:

    here it goes.

    all of my posts have to be in a category called featured. I found a way to get rid of it showing on the header but now i need to find out how to get rid of it when people view posts. I don't need to cancel out all categories from the posts. Just a selection.

  4. MichaelH
    Member
    Posted 5 years ago #

    If you want to delete categories from displaying with your post...

    If you are using the WordPress Default theme, you would delete:
    Posted in <?php the_category(', ') ?>
    from the wp-content/themes/default/index.php file.

    See also:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy
    the_category()

  5. dkblackhawk
    Member
    Posted 5 years ago #

    ok i don't want to delete all of the catergories from the post. I mean by when you view a post it shows the catergories i just want to exclude some catergories from showing in the list. Yes i mean from when i display posts.

  6. MichaelH
    Member
    Posted 5 years ago #

    Might look at Category Access allows you to limit, by user, what categories the person sees when edit posts.
    http://www.coppit.org/code/

  7. dkblackhawk
    Member
    Posted 5 years ago #

    ok let me break it down...

    I don't want to hid the posts or catergories

    I want to hide a CERTAIN CATEGORY listing that shows below all of the text in my post. I just don't want it to list certain catergories. If you want ill get you a picture of what i mean.

    http://i42.tinypic.com/wb4by1.png

  8. MichaelH
    Member
    Posted 5 years ago #

    Okay I missed you saying "when I display posts".

    Anyway, look at the template tag, get_the_category().

    Resources:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

  9. dkblackhawk
    Member
    Posted 5 years ago #

    well after going through all of the stuff and tried pratically everything i got nothing.

  10. MichaelH
    Member
    Posted 5 years ago #

    So take all the code from your template, including what you did try, and post it in a pastebin and report the link back here.

    A link to see your site would be helpful also.

  11. dkblackhawk
    Member
    Posted 5 years ago #

    pastebin http://pastebin.com/m533cb97d
    site: http://www.insanegaming.co.cc
    edit: the ones i tried i had deleted but i tried all from the_category

  12. MichaelH
    Member
    Posted 5 years ago #

    Since you didn't show what you tried not too sure what didn't work for you but you would replace <?php the_category(', '); ?> with something like

    <?php
    foreach((get_the_category()) as $category) {
        if ($category->cat_name != 'cat_to_exclude') {
        echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> ';
    }
    }
    ?>
  13. dkblackhawk
    Member
    Posted 5 years ago #

    got it working after trial and error thanks a bunch :D

  14. NathanSpike
    Member
    Posted 5 years ago #

    Hello,
    Where i put the ID to hide a category ? , thx a lot!!

  15. NathanSpike
    Member
    Posted 5 years ago #

    up

  16. NathanSpike
    Member
    Posted 5 years ago #

    up!!

  17. NathanSpike
    Member
    Posted 5 years ago #

    UPPP

  18. t31os
    Member
    Posted 5 years ago #

    Check the docs or create a properly contexted question that explains what you want to do...

    Bumping a post with Up!! UPP!! etc is not going to earn you any special help.

  19. NathanSpike
    Member
    Posted 5 years ago #

    I have already check the codex but , I don't understand where i can put the ID category I want to hide in the code of MichaelH !

    If you can help me thx a lot :x

    i replace the code <?php the_category(', '); ?> , and i don't know where I place the "exclude=204" (204 it s the number of my category )

  20. t31os
    Member
    Posted 5 years ago #

    Replace...

    cat_to_exclude

    with the name of the category...

    Using Michael's example...

    You use the category name and not the ID... it's quite self explanatory if you look at the code...

    <?php
    // For each of the categories, create them as category variables
    foreach((get_the_category()) as $category) {
        // If the category is NOT the cat_name (category name) then echo some stuff
        // So grab all... except where they match cat_name (exclude basically)
        if ($category->cat_name != 'cat_to_exclude') {
        echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> ';
    }
    }
    ?>

    I added a few comments in there (the code will still work), but it should be obvious.

  21. NathanSpike
    Member
    Posted 5 years ago #

    oh ok, thx a lot :)
    it works !

  22. Derek090
    Member
    Posted 5 years ago #

    Hello,

    This was really helpful.

    How do I go about hiding more than 1 category using this method?

  23. Derek090
    Member
    Posted 5 years ago #

    Bump

    Any assistance would be greatly appreciated.

    WP Themes

  24. t31os
    Member
    Posted 5 years ago #

    Yeah you should be able to do something like this... (untested)

    Change this line...
    if ($category->cat_name != 'cat_to_exclude') {

    To...

    if ($category->cat_name != 'cat_to_exclude' or 'another_cat_to_exclude') {

    Let me know if that works for you...

  25. hyperdude
    Member
    Posted 4 years ago #

    I tried this but it didn't work

    if ($category->cat_name != 'Past Project' or 'Current Project') {

  26. t31os
    Member
    Posted 4 years ago #

    Try this instead then..

    if ($category->cat_name != 'cat_to_exclude' || $category->cat_name != 'another_to_exclude') {

  27. Brutal
    Member
    Posted 4 years ago #

    Hmm.. Can't get that last one working either..

    if ($category->cat_name != 'uncategorized' || $category->cat_name != 'featured') {

    This hides "uncategorized" just fine, but "featured" still shows up.

  28. laulaulau
    Member
    Posted 4 years ago #

    Did anyone figure out how to hide more than one category?

    Any help would be appreciated. Thanks.

  29. goddesskarla
    Member
    Posted 4 years ago #

    Or you could use a plug-in .. Advanced Category Excluder

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.