Forums

[resolved] "Previous Entries" link calls up current posts only (10 posts)

  1. DavidBorrink
    Member
    Posted 1 month ago #

    I click on "previous" entries, and the same current entries come up on the page, with a "newer entries" link on the bottom. I have 10 entries on the Reading dashboard panel. I set it to 25 and got 25 posts. So I know my older post can be called up, but it should work by the "previous posts" link.

    http://brightideaspress.com/?page_id=5 is the link. It's a page set up to be the blog page.

  2. DavidBorrink
    Member
    Posted 1 month ago #

    Also, my index.php file is set up to display only two parent categories, "Author" and "Topics" (We utilize posts for product listings on other custom pages under other parent categories, so "Author" and "Topics" are used for true blog posts).

  3. DavidBorrink
    Member
    Posted 1 month ago #

    My custom code for calling up the two true blog post parent categories is like this:

    <?php
       if (is_home()) {
          query_posts('cat=10,17');
       }
    	?>

    Would this be affecting the way the "previous" and "newer" entries links work?

  4. t31os_
    Member
    Posted 1 month ago #

    By doing this..

    query_posts('cat=10,17');

    You are dropping any other query vars, because you're not maintaining the queried parameters..

    You just need to add the paged variables and it should be good to go.. however i'd suggest just using a basic function to set the categories before the query runs... assuming your code above is the only area(in that file) where you call query_posts, then something like so..

    function home_filter($query) {
    	if($query->is_home) $query->set('cat','10,17');
    }
    add_filter('pre_get_posts', 'home_filter');
  5. DavidBorrink
    Member
    Posted 1 month ago #

    Thanks for responding.

    I placed your code example in my functions.php file and made sure my category numbers were correct. I went to the blog page and clicked on "older posts" and it didn't work. I still have the ten most current posts.

    I note you used "home" in your code example. The blog page for this site isn't the home page, but an inside page set to be the blog page. Would that be an issue? Should "home" in your code be replaced with a page id number?

    There is a page called "home" but that's a custom splash page for this site. With special content created in specific post IDs and placed there.

  6. t31os_
    Member
    Posted 1 month ago #

    $query->is_home

    is the pre-query equivalent of..

    is_home()

    ..as per your code..

    If you are using query_posts in any of the files being used to render the page, you either need to drop those statements (if they're not needed) or add in the paged variable.

    $paged = get_query_var('paged') ? get_query_var('paged') : 1;

    and

    query_posts('YOUR-EXISTING-PARAMETERS-HERE&paged='.$paged);
  7. DavidBorrink
    Member
    Posted 1 month ago #

    Forgive me if I sound naive, but the "paged" reference isn't making sense to me (and I find the codex hard to search and find things to help me understand them).

    I've seen other forum answers refer to a need to drop statements, but I'm not understanding what's being dropped or why. If I want my blog page to call up index.php, and do a query for categories 10 and 17, which are parent categories covering "authors" and "topics", then do I also need a conditional statement to exclude all other parent categories as well?

    I know my query of using only the two category numbers is working fine, and if I change my number of posts displayed from 10 to 20, I get 20 posts from those two categories, but when I click on "older posts" I don't get older posts, only the same current posts in whatever number I set in the dashboard.

    Is this something that I need to modify in the functions.php file or do I need to add something in the index.php template which is used for my "blog" page? Or am I not modifying the right file?

  8. t31os_
    Member
    Posted 1 month ago #

    Paged is just a setting that defines the LIMIT clause in the mysql query, which in essence gives you paging.

    The issue with using..

    query_posts('parameters')

    ..is that by making that declaration you instruct WordPress to drop all existing queried parameters. In alot of cases this is fine, but imagine for a moment that index.php also handled category pages to..

    When a link is clicked to view a category (example: yoursite.com/?cat=1), a query variable is waiting to be placed into the query. The query would normally place any query variable into the query for you.

    You can retain these variables by using..

    query_posts($query_string.'&YOUR_PARAMETERS');

    ..as $query_string contains all the current queried vars(variables). This way you can add you own stuff whilst not effecting what would usually happen behind the scenes (so to speak).

    It's up to you how you fix the problem, my previous replies state how to do this.

    1. Drop query_posts, and add the filter i posted into your functions file.
    2. Add the paged variable to your query_posts line.

    Bear in mind, when you don't declare query_posts in a given file, WordPress deals with the paging for you, as well as any other query variables that need to be dealth with.

    If you'd like a break down on anything else, please be specific about what doesn't make sense, and i'll do my best to explain.

  9. DavidBorrink
    Member
    Posted 1 month ago #

    I see in your 1. 2. instructions to drop the query_posts and use the function. Okay. That's what I wasn't doing: dropping the query. I'll give that a try.

  10. DavidBorrink
    Member
    Posted 1 month ago #

    It worked.

    So I understand what happened: My query

    <?php
       if (is_home()) {
          query_posts('cat=10,17');
       }
    	?>

    was telling the page to call up the categories and overrode what the new function was trying to do. Adding that function, and removing my query from index.php was all that was needed to make the blog "older entries" work properly.

    Thanks for your help!

Reply

You must log in to post.

About this Topic