Forums

[resolved] Exclude certain categories from the frontpage (6 posts)

  1. nemo-maritime
    Member
    Posted 3 years ago #

    I need help excluding some posts in certain categories from the frontpage/homepage of my WordPress site.

    I have tried using this code

    <?php
       if (is_home()) {
          query_posts("cat=-45, -119");
       }
    ?>

    in the index.php of my theme right above the
    <?php get_header(); ?>
    It did block out the categories from appearing from my main page, and it kept it accessible from the sidebar. HOWEVER, it gave me an issue with navigation of older posts on the site; the part where u look at older posts with the "older posts" link. The issue was that if I went to any other page of my site, it showed the same list of posts on any of the pages, or "older posts" link I clicked. Whole issue is documented here.

    So what I am looking for is help with excluding the categories with some other code, or someone explaining what could be causing the issue.

  2. stvwlf
    Member
    Posted 3 years ago #

    Hi

    This code fixes the issue of same posts being shown on all pages

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
          query_posts("cat=-45,-119&paged=$paged"); ?>
  3. nemo-maritime
    Member
    Posted 3 years ago #

    Yep! That did it. Thank you very much

  4. nemo-maritime
    Member
    Posted 3 years ago #

    Just notices a little part that came extra with the code. It now shows everything like it should, still, but on the fron page, after the title, it adds "Part 1". How can I get rid of just that part? The url is perfect, its just the title bar itself shows, "Part 1" after the site title, and only for the post list. Same thing with page 2, it shows "Part 2" in the title

  5. stvwlf
    Member
    Posted 3 years ago #

    Sounds like that is programmed into your theme. Is it the category/php template that is being used? If so, examine the code on it and see if the title is being modfied in the theme.

    I'm not familiar with this issue.

  6. nemo-maritime
    Member
    Posted 3 years ago #

    Hello,

    Not sure what is meant by "category/php template", still learning : )

    I did look into the source code. I put the code you gave me into the index.php file, and I looked at where the title was comming from, and the code for the title, from the header.php, was:

    <title>
    <?php
    if (is_home()) { echo bloginfo('name'); }
    elseif (is_404()) { bloginfo('name'); echo ' - Oops, this is a 404 page'; }
    else if ( is_search() ) { bloginfo('name'); echo (' - Search Results');}
    else { bloginfo('name'); echo (' - '); wp_title(''); }
    ?>
    </title>

    Dont see a part about Part 1, or Part 2 and so on.

Topic Closed

This topic has been closed to new replies.

About this Topic