WordPress.org

Ready to get started?Download WordPress

Forums

Posts not appearing on page when certain categories selected (3 posts)

  1. jandreasen
    Member
    Posted 1 year ago #

    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.

    Thanks,

    Jerri

  2. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    Might it be simpler to create specific category templates?

    http://codex.wordpress.org/Category_Templates

  3. jandreasen
    Member
    Posted 1 year ago #

    I don't know. My WordPress knowledge isn't that extensive. And this is a site that's already coded by someone else. I'd be afraid to introduce something like that in the fear that it would break the site entirely.

    Based on the info I was able to provide above, do you think my solution was appropriate? I'm not sure what the effect/intent of the <?php query_posts('cat=-5,-6'); ?> code is vs. the <?php query_posts('cat=1'); ?> code I substituted.

    Thanks,

    Jerri

Topic Closed

This topic has been closed to new replies.

About this Topic