Forums

How to make the blog show posts from only one specific category (19 posts)

  1. iluvpinkerton
    Member
    Posted 2 years ago #

    I have different sections of my site and I want posts from specific categories to show up in specific sections. All of the sections work properly except the main blog, which shows all the different categories.

    I added the same query that I did to the templates for the other sections - so I can't seem to figure out why this is happening.

    Blog is here:
    http://www.peainthepodcast.com/blog

    Journal Section:
    http://www.peainthepodcast.com/pregnancy-journals

    Resource Section:
    http://www.peainthepodcast.com/resources

    This is the code I use:

    <?php query_posts('cat=145'); if (have_posts()) : while (have_posts()) : the_post(); ?>

    Please help

  2. jessn
    Member
    Posted 2 years ago #

    Is the blog page using a page template or the default index.php?

  3. iluvpinkerton
    Member
    Posted 2 years ago #

    The blog is using a page template. I put all of the posts that I want to have show up on the blog in a "blog" category. I use the same page template that I use for all of the other sections then changed the category ID to only show posts under the "blog category."

    So I'm not sure why every post from all categories still shows up.

  4. iluvpinkerton
    Member
    Posted 2 years ago #

    any ideas?

  5. vtxyzzy
    Member
    Posted 2 years ago #

    See the reply by MichaelH in this thread.

    Also, any Template assigned the Page will be ignored and the theme's index.php (or home.php if it exists) will control the display of the posts.

    If your theme does not have a home.php, you might try renaming your template to home.php.

  6. iluvpinkerton
    Member
    Posted 2 years ago #

    ok I renamed the template page that is assigned to the blog to "index.php" and it's still showing posts from all categories.

    Not sure what else to do

  7. iluvpinkerton
    Member
    Posted 2 years ago #

    should i rename it to home.php? I figured if i named it index.com that would work....?

  8. vtxyzzy
    Member
    Posted 2 years ago #

    A quote from the thread I cited earlier:

    The blog page will use home.php if it exists. If not it will use index.php.

    It will ignore whatever template you assign in the Template module of that particular page.

    So, if you have a home.php, it will be used. If not, index.php will be used.

    Try renaming to home.php, with no template name. if that does not work, can you post the code in the pastebin and put a link to it here so we can see the code?

  9. iluvpinkerton
    Member
    Posted 2 years ago #

    I changed the name to home.php and the blog seems to reflect the code that I have. However, it is still showing posts from ALL categories even though I'm trying to only query the posts under the BLOG category.

    Here is my code:
    http://wordpress.pastebin.com/vFTKx4h4

    please help! am I using the query_posts code wrong or something?

    http://peainthepodcast.com/blog

  10. vtxyzzy
    Member
    Posted 2 years ago #

    I don't see anything wrong with the code, but I only see one post on the page. Is that right?

  11. iluvpinkerton
    Member
    Posted 2 years ago #

    No that isn't right....it looks like it's only showing the "blog" page without the template. The page in wordpress has no content because it's supposed to pull in the php content from template.

  12. vtxyzzy
    Member
    Posted 2 years ago #

    What are your settings in Admin->Settings->Reading for 'Front page displays:'?

  13. iluvpinkerton
    Member
    Posted 2 years ago #

    Front page displays: Homepage
    Front page displays: Blog

    I have a template set up for the Blog page.

  14. rainer23
    Member
    Posted 2 years ago #

    This is explained here: Display posts from only one category by name:

    query_posts('category_name=Staff Home');

    http://codex.wordpress.org/Template_Tags/query_posts
    * Display only a single post on your homepage (a single Page can be done via Settings -> Reading).
    * Show all posts from a particular time period.
    * Show the latest post (only) on the front page.
    * Change how posts are ordered.
    * Show posts from only one category.
    * Exclude one or more categories.

  15. vtxyzzy
    Member
    Posted 2 years ago #

    @iluvpinkerton, a template will be ignored for the blog page! It will use home.php if it exists. Otherwise, it will use index.php.

    Use the code you posted in the pastebin as home.php, and see if it won't work.

  16. iluvpinkerton
    Member
    Posted 2 years ago #

    @vtxyzzy sorry for the confusion...i did do that...The code for the blog was in the index.php, I just forgot to take the template name out. So I just deleted the template name and renamed the file "home.php" and it still didn't work.

    Here is the code: http://pastebin.com/EeEKfm20

    I appreciate your help!(and patience)

    @rainer23 thanks for the code...if I can ever get the blog to show up again, we'll see if it worked!

  17. vtxyzzy
    Member
    Posted 2 years ago #

    Put back an original copy of index.php - you need that.

  18. iluvpinkerton
    Member
    Posted 2 years ago #

    done. still not working

  19. vtxyzzy
    Member
    Posted 2 years ago #

    The only other thing I can suggest is to restore from a backup.

Topic Closed

This topic has been closed to new replies.

About this Topic