Navigation with get_posts template tag
-
I’m trying to do something and I’m starting to believe it’s not possible. Maybe someone will confirm that.
I’m building a new theme using Hybrid and a child theme. I added a top navigation bar that is fixed, so it stays at the top as you scroll down the page. I want it to display the titles of the posts that are showing on the page.
I have it working, but I can’t get it to display just the posts on the current page (I have it paginated with just 2 posts to figure this out).
This is the stuff I have in my functions.php file:
function news_page_nav() { global $post; $args_pages = array( 'post_type' => 'post', 'numberposts' => 0, 'post_status' => 'publish', 'order' => 'DESC', 'nopaging' => false, ); $myposts = get_posts($args_pages); echo '<div id="top-nav">' . "\n\t\t\t"; echo '<div id="post-nav">' . "\n\t\t\t"; echo '<ul class="top-anchors">'; foreach($myposts as $post) : setup_postdata($post); ?> <li><a href="#post-<?php the_ID(); ?>"><?php the_title(); ?></a></li> <?php endforeach; echo '</ul>'; echo "\n\t</div><!-- #post-nav -->\n"; echo "\n\t</div><!-- #top-nav -->\n"; }
As you can see, it’s outputting a list of the titles (with anchored links) of the posts. Unfortunately, I can’t get it to paginate with the posts. I don’t understand the
$nopaging
parameter and what exactly it’s supposed to do. Any ideas?
- The topic ‘Navigation with get_posts template tag’ is closed to new replies.