• I’ve been working for quite a few months on a redesign of https://createdigitalmusic.com – migrating from Mambo to WordPress in the process.

    One of the features of our new template is little inter-post navigation links, as seen on https://treehugger.com/.

    You can see my version on https://createdigitalmusic.com, they show up as little up and down arrows underneath the red date header box for each post.

    When on a home template page they let you go up and down between posts, and when on a single page they are next_post and previous_post links. This is all good.

    However, for the bottom post on pages using the home template, I’d like the Next button (down arrow) to point to the next page, so https://createdigitalmusic.com/page/2/.

    Over several sessions of trying and forum searching I haven’t been able to achieve this.

    I thought my problem may be something like this – https://www.ads-software.com/support/topic/57912 – as I use a custom query to run the loop twice. However I’m using a query like this:

    <?php $my_query = new WP_Query('category_name=highlight&showposts=3');
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID;?>
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_excerpt(); ?></a>
    <?php endwhile; ?>

    … in the header, followed by a normal loop to run the main posts.

    I may have missed something very obvious, but I haven’t been able to get wordpress to create a link to the next page.

    I was thinking I could just get php to create a “hardcoded” link to /page/#/, # being the current page number + 1, but I haven’t been able to find how to access the paged…

    So, while writing that my brain put everything together and told me that I already did know how to access the paged variable, it’s mentioned in the forum topic I linked above. However it doesn’t seem to work as I expected. I’m using this:

    <?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>

    Which from that topic seems like it should return “1” if query variable “paged” is empty, or another number if query variable “paged” has something in it. However for me it’s returning “1” every time.

    Any pointers to fix this?

Viewing 15 replies - 1 through 15 (of 28 total)
  • This is something I’ve had a problem with as well. My custom loop starts with:

    <?php query_posts('cat=1,2,3,4,5,7&showposts=1'); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    None of the post navigation tags works for me either. Any ideas out there?

    During a marathon session to program a custom query_posts setup, I was informed that use of multiple/custom loops causes the nav links to fail. Apparently there is no solution.

    Thanks for the notice vkaryl. I guess I could hard code a link to a page with a normal loop and exclude it from the wp_list_pages function. Oh well.

    The code below will work ($page will have the correct value of page number), if you place it before any of the custom loop.

    <?php $page = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>

    Anyway, there is solution, if you just pastebin your full code, and tell me what you want to accomplish.

    Thanks alphaoide, I’ll do that. Pastebin seams to be little slow for some reason (I hit send about 5 mins ago and it still doin’ its thing) but I’ll post the link as quick as possible.

    Pastebin no workie. Here’s a link:
    https://ryanfitzer.com/help.txt

    What I need is a way to get to the earlier entries from the content area (between the ‘<– Begin Content –>’ and <-- End Content -->. There is a section below that uses a random posts plugin. I only need the nav in the first loop. Thanks for the help.

    nm. be back.

    Step 1.
    Go to Options > Reading, and set “Show at most” at “1”

    Step 2.
    Replace your line below…

    <?php query_posts('cat=1,2,3,4,5,7&showposts=1'); ?>

    … with the following…

    <?php $wp_query->set('cat', '1,2,3,4,5,7'); ?>
    <?php query_posts(''); ?>

    Step 3.
    Add the page navigation. Below is taken from default theme

    <div class="navigation">
    <div class="alignleft"><?php next_posts_link('&laquo; Previous Entries') ?></div>
    <div class="alignright"><?php previous_posts_link('Next Entries &raquo;') ?></div>
    </div>

    Step 4.
    Didn’t work for you? Well, then you forgot to tell me something.

    Will this affect my search results (the admin setting)? I will be using a search.php. I’ll give it try right now.

    I believe (since I’ve never really installed it) the following plugin lets you specify different number of posts per page for different views.
    https://mattread.com/projects/wp-plugins/custom-query-string-plugin/

    Problem:
    WordPress database error: [Not unique table/alias: 'wp_post2cat']

    I’ve gotten this before and I think it is a plugin clash (maybe?).

    My sidebar has a little voodoo in it as well. Here’s a link:
    https://ryanfitzer.com/sidebar.txt

    Thanks for your time BTW.

    [If anybody needs pastebin – try “our” own: https://wordpress.pastebin.ca/ ]

    Let me see the first problem first. So, is it that “random post” which gives you that error? If not, well, then find out which plugin. After you find it, give me the link to that plugin so I could find what the author did wrong.

    No errors on the random stuff or the sidebar (drawer, actually). It’s in the main loop (“The Latest” section). Here’s a direct link to the site in development:
    https://ryanfitzer.com/main/

Viewing 15 replies - 1 through 15 (of 28 total)
  • The topic ‘Custom next page link outside loop, access to paged variable – get_query_var?’ is closed to new replies.