Support » Fixing WordPress » I want only one category on my front page but it will not display

  • Resolved dsharp2590

    (@dsharp2590)



    Hello, I’m having trouble with my site: http://www.pollutionfacts.net

    I want only one category to show up in my home page. Category is #7, I used these exact instructions to do this: https://premium.wpmudev.org/blog/one-category-wordpress-homepage/

    This is my code:

    function my_home_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '7'); } } add_action( 'pre_get_posts', 'my_home_category' );

    Not only is it not showing the right category, I don’t even seen category 7 at all. Any help is appreciated. Thanks!

    • This topic was modified 2 years, 2 months ago by  dsharp2590.
Viewing 8 replies - 1 through 8 (of 8 total)
  • The code looks fine, are sure you have posts in the category 7 ??

    Yes, when I go to categories in my dashboard, I have a post category titled “facts”, when i hover over it, it says …category&tagID=7… on the bottom of my browser. Yet none of them show up, regardless of the code. Like only categories 1 and 5 show up, but category 7 does not.

    This is interesting. I had some unused categories under blog posts, and then i deleted them (they had no posts). For some reason this caused no categories at all to show up on the front page. It’s like it doesn’t seem to want to recognize that Blog posts are category 5 and Facts is category 7, so it just shows nothing at all.

    • This reply was modified 2 years, 2 months ago by  dsharp2590.

    Mmmmh!! can you please activate the default theme and tell us if the issue still exist 😀

    Ok I activated the default Twenty Eleven theme, copy/pasted the same code into it’s functions.php. And this is how it looks right now… It shows category 5 but not 7 still, it’s as though the code did nothing.

    I’m checking back hours later, it just seems to be the same for the twenty eleven theme as the other theme i was using before “zeeMagazine”. It shows nothing.

    I figured it out. I was using a plugin to exclude categories from my sidebar and I excluded that one it seemed to also alter the front page, so I removed the plugin. Thanks anyway!

    Glad you figured it out

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘I want only one category on my front page but it will not display’ is closed to new replies.