• th90

    (@th90)


    Hi Everybody;
    i have a problem with function the_category();
    how to show up a category (404) even if has no posts inside itself using function the_category.
    (when creating a navigation menu)
    tnx.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter th90

    (@th90)

    more details :
    i have created a category named cat1.
    the cat1 has a subcategory named subcat1;
    if cat1 has no posts but subcat1 has posts, querying the cat1 will result the navigation taxonomy like this:
    home>cat1>subcat1
    instead of
    home>cat1

    Thread Starter th90

    (@th90)

    Since I have registered in WordPress support,
    I have started 2-3 support request topics and in none of them have got answer!
    Why?
    This is one of wordpress support problems perhaps it makes harder to work with wordpress.

    esmi

    (@esmi)

    WordPress is free software and this free, volunteer-staffed forum is the only support resource available via www.ads-software.com. Queries are answered as and when volunteers are able. If that’s not suitable for your needs, perhaps you need to consider hiring someone?

    Or you could try using the search here at www.ads-software.com to find your own solutions. Hint: try searching on the_category().

    Michael

    (@alchymyth)

    i have a problem with function the_category();

    the_category() shows categories of a post:

    no post – no output

    https://codex.www.ads-software.com/Function_Reference/the_category

    it is definitively not clear to me what you are trying to show or change.

    if cat1 has no posts but subcat1 has posts, querying the cat1 will result the navigation taxonomy like this:

    what is the code used for that?
    can you provide a link to your site where this behaviour can be seen?

    Thread Starter th90

    (@th90)

    Thanks for response dear esmi and alchymyth.
    Yes I know wordpress is a free cms and i think wordpress is one of the best cmses.
    however.
    i use
    <?php the_category(' ? ','multiple'); ?>
    to show all categories(main and subs) of a post as navigation links.
    i captured images and explained the problem detailed.
    img 1: (Querying the post page)
    https://ul.mypersianweb.com/images/img1_6704.jpg
    img 2: (Querying the subcat1 page)
    https://ul.mypersianweb.com/images/img2_7055.jpg
    img 3:(Querying the cat1 page, Problem with navbar while using the function get_category() for creating navbar links, Cat 1 has no posts, therefore navbar shows first subcat too that has a post)
    https://ul.mypersianweb.com/images/img3_3998.jpg

    Michael

    (@alchymyth)

    what is the code for the nav bar?

    is that sort of a breadcrumb nav?

    Thread Starter th90

    (@th90)

    Yes.
    and only the category part of navbar has problem that i said.
    for showing categories with links in navbar i use
    <?php the_category(' ? ','multiple'); ?>
    for example:
    for category pages i use this code:

    <?php if ( is_category() ) { ?>
    	<a href="<?php echo get_option('home'); ?>">Home</a> ?
    	<?php the_category(' ? ','multiple'); ?>
    <?php } ?>

    maybe a change in the_category() function solves the problem.

    Michael

    (@alchymyth)

    the code the_category() cannot be used outside of the loop; https://codex.www.ads-software.com/Function_Reference/the_category

    please formulate in detail what you want to see in the breakdcrumb, and consider a different way of programming it.

    for instance, at the start of a category archive template:
    – the category ID in a category archive is get_query_var('cat');
    – the category name is single_cat_title();
    – the link url to that category is get_category_link(get_query_var('cat'));

    you can find details about these functions if you do a web search with the keywords ‘Codex WordPress’ plus the function name.

    Thread Starter th90

    (@th90)

    Thanks alchymyth.
    I use the_category() inside the loop and the navbar is inside the loop too.
    but using the_category() works fine (and automatically does what must do, no need to extra codes) , except while the category has no posts, it does not work functionally and i think there is a problem with this function.
    however, we can use other ways for coding navbar.
    but why the_category does not work functionally?
    Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Show category even if has no posts ; the_category() function’ is closed to new replies.