• Resolved cdlenfert

    (@cdlenfert)


    Hi, this is my first post on the forum and my first WordPress site. I’ll try to be as specific as possible, but please forgive any noobisms.

    My site is https://www.lenfertdesign.com
    My theme is Cumulus v.1.2 (Demo)

    My issue is with the Previous Entries and Next Entries navigation on my portfolio.php page and archive.php pages. You can see there are a couple different outcomes when clicking on Previous Entries.

    1. https://lenfertdesign.com/work/
    in this case it simply reloads the same 2 posts regardless of the page/url position

    2. https://lenfertdesign.com/magazines/
    in this case I get a “page not found” error. This is the archive for the category “magazines”

    An example of the links working on the theme demo can be found here

    In the WP/Dashboard/Settings/Reading/Blog pages to show at most, I’ve set to 2 posts. I have 7 posts in the category “portfolio” and 3 posts in the category magazines. That way I will see the Previous Entries link. In portfoilo.php this code queries the posts.

    <?php
    query_posts('category_name=Portfolio');
    global $more;
    $more = 0;

    looking at other forum posts (all over a year old) I’ve also tried this code to replace the code above. Either way the result is the same.

    <?php
    if (is_home()) {
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("category_name=Portfoilo");
    }
    ?>

    This is all the code for the navigation links.

    <div class="navigation">
    		<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
    
            <div class="alignleft"><?php next_posts_link('&larr; Previous Entries') ?></div>
            <div class="alignright"><?php previous_posts_link('Next Entries &rarr;') ?></div>
            <!--<?php } ?>-->
    		</div>

    Some ideas:
    My portfolio page is actually my “work” page and I’m not sure if the page naming has some effect on things, but I don’t expect that would be the case for the archive page for the “magazines” category.

    I’m not sure what the if(function_exists(‘wp_pagenavi’)… is doing if anything. When I comment it out, I still get the same result and I can’t seem to find that function anywhere to examine it. Most of what I’ve read seems to point at the query on the specific pages overpowering a previous query that gives pagination details.

    Again I’m very new to wordpress & php, but I can find and report any details or code that might be helpful to anyone who has an idea how to fix this issue. I’m in day 2 of troubleshooting and hitting a wall.

Viewing 15 replies - 1 through 15 (of 15 total)
  • For the portfolio paging problem, you have to actually pass the $paged variable to query_posts():

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("category_name=Portfoilo&paged=$paged");

    For the archives problem, try switching to the default permalinks. If this works, switch back to the pretty permalinks. If this fails, try the default theme to eliminate a theme problem.

    Thread Starter cdlenfert

    (@cdlenfert)

    vtxyzzy, thanks for the reply. I updated the code on my portfolio.php page to this:

    <?php
    if (is_home()) {
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("category_name=Portfoilo&paged=$paged");
    }
    ?>

    Should that be passing the $paged variable correctly? I’m still getting the same result so maybe I’m not putting it in right.

    I changed the permalinks to the defaults but soon realized that I don’t know how to get to my magazines archive page. Before I had a link of lenffertdesign.com/magazines but now how can I tell what it is? I tried using the widgets option to add a categories sidebar but that didn’t show up on any of my pages.

    Thread Starter cdlenfert

    (@cdlenfert)

    I was able to get the Previous Entries and Next Entries working on the Category Archive pages.
    I turned on the default permalinks (ugly is right for sure)

    I manually added a category list to my sidebar.php file.

    If you click on Services you’ll see the category list. Clicking on Magazines or Portfolio from the list takes you to the archive page for that category and the navigation works great.

    However when you click directly on the work page, the posts with a category of portfolio are pulled in correctly, but the navigation still doesn’t work. There seems to be an issue with the fact that the posts are pulled in on a portfolio template page vs. a category archive page.

    Perhaps I need to change the php code in the navigation on this template page to pull the correct posts. Maybe something more specific than what is there now.

    <?php next_posts_link('&larr; Previous Entries') ?>

    Thread Starter cdlenfert

    (@cdlenfert)

    I also read the following from this page:

    Usage Note

    Place a call to query_posts() in one of your Template files before The Loop begins. The wp_query object will generate a new SQL query using your parameters. When you do this, WordPress ignores the other parameters it receives via the URL (such as page number or category). If you want to preserve that information, you can use the $query_string global variable in the call to query_posts().

    I am a little confused.

    Is it correct that your archive pages are working? What did you change there?

    For the work page, what is the template? Are you using this code?

    <?php
    if (is_home()) {
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("category_name=Portfoilo&paged=$paged");
    }
    ?>

    If so, why are you using the if (is_home()) test? Try taking that out.

    If the pagination is working for magazines, but not for portfolio, what is the difference in the templates?

    Thread Starter cdlenfert

    (@cdlenfert)

    I’m admittedly a little confused myself. But I’ll try to clear things up.

    My Work page on the site uses the portfolio.php template
    – previous/next don’t work on this page

    Magazines and Portfolio category pages use the archive.php template
    – previous/next do work on these pages
    – I was able to make these work by changing the permalinks to default, after changing them back to custom permalinks they continue to work

    This was the original query code on the portfolio.php file

    <?php
    query_posts('category_name=Portfolio');
    global $more;
    $more = 0;
    ?>

    This is the current code i’m trying (but doesn’t work)

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("category_name=Portfoilo&paged=$paged");
    ?>

    This is the code on the archive.php file that query’s the posts (very different)

    <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
     	  	<?php /* If this is a category archive */ if (is_category()) { ?>
    		<h1 class="pagetitle">LD <?php single_cat_title(); ?></h1>

    I think I understand what it’s doing, but when I tried using this in my portfolio.php file it fails to grab any posts.

    The code you showed for the archive.php file is not actually doing a query – the query is probably done before the archive.php file is called.

    I think the problem is that you have a typo in the category_name:

    Portfoilo instead of Portfolio

    Thread Starter cdlenfert

    (@cdlenfert)

    I corrected the typo but I’m still having the issue. I’m not sure why it would have even pulled any posts considering the misspelling of the category name.

    I noticed the following code in the posts.php file in the them folder. This is the template used for the Blog page, which was working on the demo.

    <?php
    $limit = get_option('posts_per_page');
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('showposts=' . $limit . '&paged=' . $paged);
    $wp_query->is_archive = true; $wp_query->is_home = false;
    ?>

    It has references to post limits and paged variable. It’s a little over my head but maybe this could be modified to make my portfolio query work.

    Please put your portfolio.php file in a pastebin and post a link to it here so I can see the whole file.

    Thread Starter cdlenfert

    (@cdlenfert)

    Here are pastebins for:
    portfolio.php
    archive.php
    posts.php

    thank you for taking the time to look at this

    OK – the problem is that you have used HTML comments in an attempt to comment out PHP.

    Remove the two query_posts sections that are inside the HTML comments – leave only the first query_posts.

    To comment out PHP, you must use /* and */ like this:

    <?php
    /*
    query_posts('category_name=Portfolio');
    global $more;
    $more = 0;
    */
    ?>
    Thread Starter cdlenfert

    (@cdlenfert)

    I completely removed the commented sections of code and it worked.

    this is the final working query code.

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("category_name=Portfolio&paged=$paged");
    global $more;
    $more = 0;
    ?>

    Thank you so much for all your help. I guess what I don’t get it why I’m able to use the HTML comment tags to remove the sidebar from the portfolio.php template file, but not comment out other PHP code with it. I’ll be more specific with commenting in the future and do some additional research.

    Using the HTML commenting stops any output from showing up on the screen, but does not stop the execution of the code. Perhaps this will help clear things up. If you run this code:

    <!--<?php
    $t = 'XXXXXX';
    echo "You won't see $t here!";  // This is echoed between comments
    ?>-->
    echo "But, you will see $t here!";

    it will output:

    But, you will see XXXXXX here!

    So, the value of $t is set even though the first echo is not seen on the screen. If you examine the source of the page, you will see it between the comment markers.

    Now, if your questions have been answered, please use the dropdown at top right to mark this topic ‘Resolved’.

    Thread Starter cdlenfert

    (@cdlenfert)

    I see. Thanks for clearing that up.

    You are welcome.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Previous Entries Next Entries Navigation pulling the same 2 posts’ is closed to new replies.