WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Category pages displays regular blog posts (14 posts)

  1. KIntheHouse
    Member
    Posted 6 years ago #

    Hi,

    I have a weird problem with my category pages displaying just blog posts and not the category posts. I do have a custom sidebar.php that changes based on the post category using a second (3 loops in some) loop.
    http://pastebin.ca/1166440 should show where I am going with this.

    Single posts, pages, blog page all work fine. It's just the category pages that do not work right.

    I have tried to wrap my head around multiple loops in WP and have a feeling that's the reason but I could be wrong.

    I don't have any special .htaccess rules that could be causing a redirect. I am using a custom permalink with %postname%, in case that helps.

  2. moshu
    Member
    Posted 6 years ago #

    http://www.shankrila.com/category/pedro-report/
    and
    http://www.shankrila.com/category/tech-stuff/
    both display only posts from those categories. What else do you expect?

  3. KIntheHouse
    Member
    Posted 6 years ago #

    moshu, sorry that is a different site I am having this problem with and not on my personal blog.

  4. CyberCoder
    Member
    Posted 6 years ago #

    K, check your brackets, PHP can be very funny about that.

    example: php if ( is_category('41') || in_category('41'))

    Maybe should be php if ( (is_category('41')) || (in_category('41')))

  5. KIntheHouse
    Member
    Posted 6 years ago #

    Hey buddy, I'll definitely try it but it might be worth noting that I am not having any problems with this particular part of the code itself. The sidebar displays the posts from the particular category I am viewing but the content area just displays posts from the blog instead of that category!

  6. CyberCoder
    Member
    Posted 6 years ago #

    Not sure K, just taken shots in the dark at what stands out, although, after further review, your bracketing should work.

    Is the code in the sidebar the same as the code in the page?

    Which one fires first?

    Are you sure about the combo of is_category and in_category?

  7. KIntheHouse
    Member
    Posted 6 years ago #

    Oh, I appreciate the help!

    I didn't publish the full sidebar.php code in pastebin as it's kind of long and unwieldy. But, it pretty much checks for various categories and does the same over again and the final else prints the dynamic sidebar code.

    The theme I am using doesn't have a category.php to investigate. So, by template hierarchy I guess it would use index.php for category pages.

    This is again the reason why I think my sidebar loops (even though I have tried to use custom loops instead of using wp_query) could be resetting the main loop!

    And all the theme files fire the sidebar.php before the content.

  8. CyberCoder
    Member
    Posted 6 years ago #

    2 suggestions.

    1.) Take the call to the sidebar out and see if that has an impact.

    2.) Double Check your Theme, if there is no Category.php, it goes to Archive.php, and then Index.php

  9. KIntheHouse
    Member
    Posted 6 years ago #

    Your pointer about the is_category and in_category has sent me on the right track now, I think. in_category is supposedly meant for only inside the main loop. I will see if I modification to that code makes any difference. Thanks!

  10. moshu
    Member
    Posted 6 years ago #

    in_category is for single post view and is_category for category archives (if by "category page" we all mean category archives/listing).

  11. KIntheHouse
    Member
    Posted 6 years ago #

    moshu, exactly what I am trying to do! I just need the sidebar to display a certain set of posts in the sidebar on both occasions - a single post of a certain category or if I am displaying category archive page for that category. So, I am using:
    is_category('41') || in_category('41')

    And this is the part Cybercoder was asking if it's ok to use it like this. The Codex indicates I need to do some special treatment to use in_category outside the loop

    http://codex.wordpress.org/Template_Tags/in_category#Use_OUTSIDE_The_Loop

  12. KIntheHouse
    Member
    Posted 6 years ago #

    Hey guys.. the problem is solved!

    It's crazy how I solved it. I just created a category.php file and put the same loop as in index.php and it works now!!

    I was testing with a stripped down version of sidebar.php with no multiple loops but just the dynamic sidebar, and the category archive pages wasn't loading. So, I created a category.php file and now it works!

    Thanks for your help guys!

  13. garryconn
    Member
    Posted 6 years ago #

    Sheesh.... I am glad you got that one fixed. Why can't we just be normal WordPress bloggers??? :)

    You had some excellent support on this one K... David, that is very cool that you helped. :)

  14. KIntheHouse
    Member
    Posted 6 years ago #

    Garry.. I sure had the 2 best pair of eyes looking at this issue! :-) Most fellow bloggers doesn't know that we blog because we love to tinker with WordPress under the hood! so shhhhh LOL

Topic Closed

This topic has been closed to new replies.

About this Topic