• Resolved shinigamiazura

    (@shinigamiazura)


    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

Viewing 8 replies - 1 through 8 (of 8 total)
  • 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

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

    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?

    Thread Starter shinigamiazura

    (@shinigamiazura)

    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.

    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.

    Thread Starter shinigamiazura

    (@shinigamiazura)

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

    Don’t forget the native WordPress function get_cat_ID

    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?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Exclude category by name?????Helppppppp’ is closed to new replies.