WordPress.org

Forums

Custom next page link outside loop, access to paged variable - get_query_var? (29 posts)

  1. Jaymis
    Member
    Posted 8 years ago #

    I've been working for quite a few months on a redesign of http://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 http://treehugger.com/.

    You can see my version on http://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 http://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 - http://wordpress.org/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?

  2. Ryan Fitzer
    Member
    Posted 8 years ago #

    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?

  3. vkaryl
    Member
    Posted 8 years ago #

    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.

  4. Ryan Fitzer
    Member
    Posted 8 years ago #

    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.

  5. Joshua Sigar
    Member
    Posted 8 years ago #

    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.

  6. Ryan Fitzer
    Member
    Posted 8 years ago #

    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.

  7. Ryan Fitzer
    Member
    Posted 8 years ago #

    Pastebin no workie. Here's a link:
    http://ryanfitzer.com/help.txt

  8. Ryan Fitzer
    Member
    Posted 8 years ago #

    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.

  9. Joshua Sigar
    Member
    Posted 8 years ago #

    nm. be back.

  10. Joshua Sigar
    Member
    Posted 8 years ago #

    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.

  11. Ryan Fitzer
    Member
    Posted 8 years ago #

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

  12. Joshua Sigar
    Member
    Posted 8 years ago #

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

  13. Ryan Fitzer
    Member
    Posted 8 years ago #

    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:
    http://ryanfitzer.com/sidebar.txt

    Thanks for your time BTW.

  14. moshu
    Member
    Posted 8 years ago #

    [If anybody needs pastebin - try "our" own: http://wordpress.pastebin.ca/ ]

  15. Joshua Sigar
    Member
    Posted 8 years ago #

    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.

  16. Ryan Fitzer
    Member
    Posted 8 years ago #

    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:
    http://ryanfitzer.com/main/

  17. Joshua Sigar
    Member
    Posted 8 years ago #

    Hmm, I know why it gave that error but no clue what caused it.

    Disable ALL plugins one by one. It could be plugin 'cause I have same code with no error.

  18. Ryan Fitzer
    Member
    Posted 8 years ago #

    Will do. One Sec....

  19. Ryan Fitzer
    Member
    Posted 8 years ago #

    Not much help as disabling some plugins causes a the full page to go down (call to undefined function). Any ideas on a workaround that I could link to directly (I'm currently using home.php instead of index.php). I tried to set up index.php with a normal loop and then link it href="?index.php". No luck as it still goes to home.php. I understand the template hierarchy for the most part but haven't figured this out yet.

  20. Joshua Sigar
    Member
    Posted 8 years ago #

    Getting "call to undefined function" as you disable plugins is normal. So, do you know which plugin causes the error you mentioned?

  21. Ryan Fitzer
    Member
    Posted 8 years ago #

    Not sure I understand how to debug the page when disabling one plugin causes a fatal error (call to undefined function was just a little error). When the whole page goes down, I can't debug any plugin. As far as I can tell, to fully debug this I would have to strip all code that is specific to a plugin out of the page. Is this what you would recommend?

  22. Joshua Sigar
    Member
    Posted 8 years ago #

    You would disable plugin one by one until you dont get that error below. No need to delete any code.

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

  23. Ryan Fitzer
    Member
    Posted 8 years ago #

    I tried that, but deleting one (ex: fold_page_list plugin) ends any processing of any of the scripts below. Here's list of what plugins I'm using. Not sure it will help. Sorry for any frustration.

    * Todo List Plugin (admin)
    * Customizable Post Listings
    * Fold Page List
    * podPress
    * Post Image
    * Random Posts
    * Recent Posts
    * Sideblog WordPress Plugin

  24. Joshua Sigar
    Member
    Posted 8 years ago #

    well, then, I guess you have to remove all code used by plugins. Then start adding it one by one until you get the error. I'm not gonna look into those plugins you list--too much.

  25. Ryan Fitzer
    Member
    Posted 8 years ago #

    Thanks for the help. I give it a try in the morning. ZZZZZZZZZZZZ.......

  26. Ryan Fitzer
    Member
    Posted 8 years ago #

    Awake and working again. Got something working. I had to compromise a bit but that's ok. Thanks so much for your help alphaoide.

    I need one more tweak to get this going. I have pasted the code here:
    http://wordpress.pastebin.ca/174379

    Here's the thing. I'm trying to exclude multiple categories in WordPress loop w/o screwing up the post nav at the bottom. I've got it working but the only problem is when the newest post is in the excluded category, the loop returns nothing. I realize I need to provide an "else" statement to tell the loop to go back to a post that is in the allowed categories, but I'm not sure how to go about it. Any help would be great. Thanks.

  27. Ryan Fitzer
    Member
    Posted 8 years ago #

    There might be another way. This page talks about putting this in the loop

    <?php if (in_category('3')) continue; ?>

    I've tried it verbatim with no luck. I know there has to be a way to exclude mulitiple cats in the loop and still be able to use the post navigation. I'm gonna keep looking.

  28. Ryan Fitzer
    Member
    Posted 8 years ago #

    Real quick. I'm thinking now the loop is working correctly but since I have my home page set to show only 1 post, it just doesn't show anything. I have to make this section show only one post though. Back to the search.

  29. Ryan Fitzer
    Member
    Posted 8 years ago #

    I've found that the SideBlog Plugin does a great job of excluding cats from the standard loop. I'm going to see if I can use this to my advantage.

Topic Closed

This topic has been closed to new replies.

About this Topic