WordPress.org

Ready to get started?Download WordPress

Forums

Show category even if has no posts ; the_category() function (10 posts)

  1. th90
    Member
    Posted 1 year ago #

    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.

  2. th90
    Member
    Posted 1 year ago #

    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

  3. th90
    Member
    Posted 1 year ago #

    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.

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    WordPress is free software and this free, volunteer-staffed forum is the only support resource available via wordpress.org. 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 wordpress.org to find your own solutions. Hint: try searching on the_category().

  5. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    i have a problem with function the_category();

    the_category() shows categories of a post:

    no post - no output

    http://codex.wordpress.org/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?

  6. th90
    Member
    Posted 1 year ago #

    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)
    http://ul.mypersianweb.com/images/img1_6704.jpg
    img 2: (Querying the subcat1 page)
    http://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)
    http://ul.mypersianweb.com/images/img3_3998.jpg

  7. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    what is the code for the nav bar?

    is that sort of a breadcrumb nav?

  8. th90
    Member
    Posted 1 year ago #

    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.

  9. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    the code the_category() cannot be used outside of the loop; http://codex.wordpress.org/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.

  10. th90
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.