Support » Fixing WordPress » Category pages displays regular blog posts

  • Resolved KIntheHouse



    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. 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.

Viewing 13 replies - 1 through 13 (of 13 total)
    both display only posts from those categories. What else do you expect?

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

    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’)))

    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!

    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?

    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.

    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

    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!

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

    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

    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!

    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. 🙂

    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

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Category pages displays regular blog posts’ is closed to new replies.