Forums

[resolved] Exclude category by name?????Helppppppp (9 posts)

  1. Shinigami.Azura
    Member
    Posted 1 year ago #

    Hello

    The problem is that I want to exclude a category from a wp_list_category by name. It seems that can´t be done by name, only by id. Is there any way to exlude that category. Please HELPME

    Here is what I want:
    wp_list_category( 'title_li=&depth=0&exclude=1,featured' )

    Thanks in advance for any help

  2. dskallman
    Member
    Posted 1 year ago #

    You can add a 1,#,#,# will exclude all the category IDs you don't want.

    If your theme allows it may be best to use custom menus under Appearance > Menus

  3. alchymyth
    The Sweeper
    Posted 1 year ago #

    you might need to make an intermediate step to get the category id from the category name; for instance http://www.wprecipes.com/wordpress-function-get-category-id-using-category-name

  4. James Laws
    Member
    Posted 1 year ago #

    What's the problem with simply excluding it with the ID? I guess what I'm asking is what special are you trying to accomplish that the name is preferable to the ID?

  5. Shinigami.Azura
    Member
    Posted 1 year ago #

    James:
    Because I set the category ¨featured¨ in the index as a featured category, that only appear in the home page, with a code that is something like this:

    query_post= new WP_query('category_name=featured&pos_per_post=1')

    I want that featured category out of the menu. But i don't know how. I tried make a variable and then calling the id, but exclude don't allow me to call a variable in the code wp_list_category( 'title_li=&depth=0&exclude=1,featured' ).
    Maybe I'm calling it in the wrong way???

    alchymyth: I going to try that way thanks for the help.

    dskallman: the point is a site with a custom menu. That featured category is killing me. Thanks for the help.

  6. alchymyth
    The Sweeper
    Posted 1 year ago #

    wp_list_category( 'title_li=&depth=0&exclude=1,featured' ).

    ->> needs to read: wp_list_categories()

    how to use a variable in wp_list_categories():

    $cat_name = 'featured';
    $term = get_term_by('name', $cat_name, 'category');
    $featured_id =  $term->term_id;
    wp_list_categories( 'title_li=&depth=0&exclude=1,' . $featured_id );

    btw:
    watch your spelling of the wordpress functions - you made a few typos here in the thread - make sure you don't repeat them in your code, as typing errors are often difficult to trouble shoot.

  7. Shinigami.Azura
    Member
    Posted 1 year ago #

    alchymyth, arigatoooooooooooooo I love you, you are the best, i can't belive it is done, thank you for the help. Very apreciate (^-^)

  8. MichaelH
    Volunteer
    Posted 1 year ago #

    Don't forget the native WordPress function get_cat_ID

  9. sprmrkt
    Member
    Posted 1 year ago #

    i need a filter not for the whole category name but a part of it.
    if cat_name contains substring then show it. but i cannot work out the proper php syntax mixing the great code above and strpos()

    any ideas?

Topic Closed

This topic has been closed to new replies.

About this Topic