felixkarlsson
Member
Posted 2 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('>') ?>
felixkarlsson
Member
Posted 2 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('>') ?>
felixkarlsson
Member
Posted 2 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
felixkarlsson
Member
Posted 2 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.
felixkarlsson
Member
Posted 2 years ago #
Can you elaborate that?
I can't see how that would solve the problem, sorry.
Thanks!
Felix Karlsson
This will put the "next" or ">" for your pages.
felixkarlsson
Member
Posted 2 years ago #
Weird, it doesnt work? :S
Works for me. See it in action on my site. Click on my profile to get to see it working on my site.
Thanks,
felixkarlsson
Member
Posted 2 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
felixkarlsson
Member
Posted 2 years ago #
I really need to solve this people, any suggestions?
Thanks
Felix Karlsson
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? :)
felixkarlsson
Member
Posted 2 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
Hey felixkarlsson do you have the code for what you did? I would like to try it out too.
Thanks.
felixkarlsson
Member
Posted 2 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 ' >';}
?>
felixkarlsson
Member
Posted 2 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!
In which file do you insert it?
Thanks.