WordPress.org

Ready to get started?Download WordPress

Forums

Pagination (18 posts)

  1. felixkarlsson
    Member
    Posted 4 years ago #

    Hello!
    I'm having a problem with my pagination.
    I want it to work like this:
    The output: <1>
    The left arrow is a link for privious entries, the right arrow for next entries, and the "1" is the pagenumber.

    And if there's no privious entries for instance, i want the arrow to still be there, but un-clickable.
    This is my current code (It's ofcourse not working at the moment):

    <?php if(count(next_posts_link()) > 0): echo "the link..."; ?>
            <?php else: echo "the link, but unclickable"; ?>
            <?php endif; ?>
           //Below this is working
               <?php next_posts_link('<') ?>
    		   <?php if(!empty($_GET["paged"])) { echo '<strong>'.$_GET["paged"].'</strong>'; } else { echo "<strong> 1 </strong>"; } ?>
    		   <?php previous_posts_link('>') ?>
  2. felixkarlsson
    Member
    Posted 4 years ago #

    //Some code here that will find out if there is newer entries...
    <?php next_posts_link('<') ?>
    <?php
    if(!empty($_GET["paged"])) {
    echo '<strong>'.$_GET["paged"].'</strong>';
    }
    else { echo "<strong> 1 </strong>"; }
    ?>
    //Some code here that will find out if there is privious entries...
    <?php previous_posts_link('>') ?>
  3. Shane G
    Member
    Posted 4 years ago #

  4. felixkarlsson
    Member
    Posted 4 years ago #

    No sorry, those can't help me.
    Because I just want one left arrow, and one right arrow.
    (Or i don't want, but my client does...)

    And even if there's no "Next page", I want the arrow to still be there, but not as a link.
    So the thing I need is some function that will find out if there is a "next link" or "previous link"...

    Thanks!

    Felix Karlsson

  5. felixkarlsson
    Member
    Posted 4 years ago #

    Anyone?

  6. Inv_Trdr
    Member
    Posted 4 years ago #

    Try adding "<?php wp_link_pages(array('before' => '<p>Pages: ', 'after' => '</p>', 'next_or_number' => 'number')); ?>" to the page and single PHP files.

  7. felixkarlsson
    Member
    Posted 4 years ago #

    Can you elaborate that?
    I can't see how that would solve the problem, sorry.

    Thanks!

    Felix Karlsson

  8. Inv_Trdr
    Member
    Posted 4 years ago #

    This will put the "next" or ">" for your pages.

  9. felixkarlsson
    Member
    Posted 4 years ago #

    Weird, it doesnt work? :S

  10. Inv_Trdr
    Member
    Posted 4 years ago #

    Works for me. See it in action on my site. Click on my profile to get to see it working on my site.
    Thanks,

  11. felixkarlsson
    Member
    Posted 4 years ago #

    Oh, but I don't want it like that. :P
    I just want "< number >"
    number = The page that you're at
    The arrows are the next-link and previous-link.

    And even though there is no next/previous link, there should be an unclickable arrow.

    Don't know how to explain it better.

    Ex. <1>

    Thanks

    Felix Karlsson

  12. felixkarlsson
    Member
    Posted 4 years ago #

    I really need to solve this people, any suggestions?

    Thanks

    Felix Karlsson

  13. Mark / t31os
    Moderator
    Posted 4 years ago #

    If you have this..

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    Divide the IF and WHILE conditions like so..

    <?php if (have_posts()) : ?> 
    
    	<?php while (have_posts()) : the_post(); ?>

    Then place this between them..

    <?php
    $totalposts = $wp_query->found_posts;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $per_page = get_query_var('posts_per_page');
    $last_page = ceil($totalposts / $per_page);
    
    if($paged > 1) { previous_posts_link('<'); }
    else { echo '<';}
    
    echo $paged;
    
    if($last_page > $paged) { next_posts_link('>'); }
    else { echo '>';}
    ?>

    That what you're after? :)

  14. felixkarlsson
    Member
    Posted 4 years ago #

    That's exactly what I want! :D
    But I use the next link first, so I go back to earlier entries with "<" :)

    Thanks a lot!
    You're my hero ;)

    Felix Karlsson

  15. Inv_Trdr
    Member
    Posted 4 years ago #

    Hey felixkarlsson do you have the code for what you did? I would like to try it out too.
    Thanks.

  16. felixkarlsson
    Member
    Posted 4 years ago #

    Hey!

    I use this:

    <?php
    	$totalposts = $wp_query->found_posts;
    	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	$per_page = get_query_var('posts_per_page');
    	$last_page = ceil($totalposts / $per_page);
    
    	if($last_page > $paged) { next_posts_link('< '); }
    	else { echo '< ';}
    
    	echo "<strong>" .$paged. "</strong>";
    
    	if($paged > 1) { previous_posts_link(' >'); }
    	else { echo ' >';}
    ?>
  17. felixkarlsson
    Member
    Posted 4 years ago #

    But there is a problem, it doesn't work with my month archive. And I don't know how to solve it yet. Any ideas? :)

    You can visit this page to see what i mean: http://www.gumpalalla.se (strong material).

    Click "September" and try to change page. (It shows the same page again) :(

    Thankful for help!

  18. Inv_Trdr
    Member
    Posted 4 years ago #

    In which file do you insert it?
    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic