• I’ve moved my ‘posts’ from the home page to the blog page on my website.

    I would like to start upkeeping a selective feed of news for my readers by using posts. I would like to exclude those ‘feed’ posts from the blog page but include them on the Business News page. The blog page posts are categorized ‘blog’ and the Business News page posts will be categorized ‘business news’.

    But, I’ve searched and I just can’t find the straight information on how to accomplish this. Any help would be appreciated.

    WP2.8.1
    Theme: decoder 0.9.1

    Thanks,
    ~Steve

Viewing 6 replies - 1 through 6 (of 6 total)
  • There are a couple ways I think…

    Here is one:

    I have another site that has a page called “news” that displays a limited number posts categorized as “news” within that page and adds the next/previous links to reach the rest of the posts in that category.

    Basically all I did was make a copy of my theme’s index.php and renamed it news.php.

    Then I added this at the very top, to designate it as a template.

    <?php /*
    
    Template Name: News Page
    
    */ ?>

    And then right before this line:
    <?php if (have_posts()) : ?>

    I inserted (note that I used your current business news category name “bnews”):

    <?php query_posts('category_name='.'bnews'.get_option('posts_per_page')); ?>

    This calls posts from the category titled “bnews” and limits the number of posts per page to the number you setup in your WordPress settings.

    Then you just login to your wordpress, edit your “Business News” page and tell it to use your new “News Page” template.

    As for excluding that category from the main page, you’d have to add a query_posts to the index.php in order to exclude your “bnews” category.

    Placed above your <?php if (have_posts()) : ?> in the index.php, you’d need something like this:

    <?php query_posts('category_name=-bnews'); ?>

    Can somebody smarter than me check that please..

    Thread Starter stevenswv

    (@stevenswv)

    Ok I did each of those steps and with the new template loaded the Business News page is now displaying “No Posts matched your criteria” and the Blog page is now ONLY displaying the bnews posts and no others.

    I don’t know if I didn’t something wrong but I copied the code posted here into my templates so I don’t know what could be happening. I’ve left these changes on my site so they can be reviewed.

    Thanks,
    ~Steve

    Thread Starter stevenswv

    (@stevenswv)

    Ok I used this:

    <?php query_posts($query_string . ‘&cat=-5’); ?>

    In place of this:

    <?php query_posts(‘category_name=-bnews’); ?>

    To exclude the Business News category from the Blog page and that worked great! So, I replaced this:

    <?php query_posts(‘category_name=’.’bnews’.get_option(‘posts_per_page’)); ?>

    With this:

    <?php query_posts(‘category_name=bnews’); ?>

    Thinking it might do the job but it didn’t. All it did was bring back the original pages writing but there are no posts under it.

    So I still can’t get the news.php template working correctly…Any Ideas?

    Thanks,
    ~Steve

    Thread Starter stevenswv

    (@stevenswv)

    Ok new update…After some searching I replaced this:

    <?php query_posts('category_name=bnews'); ?>

    Which I put in Before

    <?php if (have_posts()) : ?>

    But after some reading I decided to use:

    <?php
       if (is_page()) {
          query_posts('cat=3');
       }
    ?>

    I also, changed the position so now it looks like this:

    <?php if (have_posts()) : ?>
    
    <?php
       if (is_page()) {
          query_posts('cat=25');
       }
    ?>
    
    		<?php while (have_posts()) : the_post(); ?>

    So now the page displays the posts in the Business News category BUT the page content is now gone, which I would like to display above the posts as a page description.

    Also if anyone could tell me the best way to put a maximum amount of posts displayed on the page I would appreciate it.

    Thanks,
    ~Steve

    So now the page displays the posts in the Business News category BUT the page content is now gone, which I would like to display above the posts as a page description.

    Sorry, didn’t realise you intended to have posts & news page content.

    If that’s the case, then you’d want to have something along these lines (note that my category is “news” and this particular page is set to query posts with the same category name as page name, so just change that part to your current query):
    http://wordpress.pastebin.ca/1502518

    FYI: This bit of code (get_option('posts_per_page')) tells the page to only load as many posts per page as specified in your wordpress settings, but you can remove it and replace it with some pagination paramater mentioned in the following link. Also, you may not need the bit about the “post_status” – I’m not even sure why that’s in there.

    Also if anyone could tell me the best way to put a maximum amount of posts displayed on the page I would appreciate it.

    Pagination parameters: http://codex.wordpress.org/Template_Tags/query_posts#Pagination_Parameters

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Including and Excluding Posts on Pages’ is closed to new replies.