I need some help with some code written by someone who’s long gone. I know the WordPress backend and PHP just enough to get an idea of where a problem is, but not enough to figure out how to fix the problem.
The site in question has 4 categories for posts:
Company News (cat ID 5)
Event (cat ID 6)
Home page (cat ID 7)
News (cat ID 1) (default post page)
The client has only 11 posts, some with just one category assigned, and some with up to 3. They just created 2 new posts and assigned them both to the Company News, Home Page, and News categories. The posts displayed on the Company News and Home Page pages, but not on the News page.
After some testing I found that if just the News category was selected, the posts would show up on the News page. I looked at the template for the News page and found this code:
<h2>Latest News</h2> <div class="posts"> <?php query_posts('cat=-5,-6'); ?> <?php while (have_posts()) : the_post(); ?> <article class="blog-post"> <div class="post-date"><?php the_date(); ?></div> <h3 class="title"> <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a> </h3> (....etc....)
So… is the
<?php query_posts('cat=-5,-6'); ?>line preventing the page from showing the posts with the News category (cat ID 1) assigned to them because they also have the Company News category (cat ID 5) assigned to them? I think the intention was to prevent duplicate posts on the News page — especially since the News page is the default post page.
I resolved the problem by deleting the
<?php query_posts('cat=-5,-6'); ?>line and replacing it with
<?php query_posts('cat=1'); ?>. But will that prevent uncategorized posts from appearing on the News page? Or are uncategorized posts assigned the News category by default since it’s the default post page?
I just want to make sure I did the right thing, and won’t screw something else up down the line.
- The topic ‘Posts not appearing on page when certain categories selected’ is closed to new replies.