Hi Caroline (and all),
The site is coming along nicely. I’m having tons of fun making the theme go “circles all the way down.” I got to the point where I could get my circles in pages that pull posts by categories. You can see how I did that in an earlier post.
Now I got stumped trying to get the navigation buttons « » in the nav-below class to show. These are useful when you exceed the number of posts allowed in Settings/Reading. You can see them in the home page just fine. I thought the solution would be as easy as adding the spun_content_nav function to my Template page after the content template part. Here’s what I have so far:
<?php /* Template Name: Projects */ get_header(); ?> <div id="primary" class="content-area"> <div id="content" class="site-content" role="main"> <?php the_post(); $args = array( // Change these category SLUGS to suit your use. 'category_name' => 'projects', ); $list_of_posts = new WP_Query( $args ); while ( $list_of_posts->have_posts() ): $list_of_posts->the_post(); get_template_part( 'content', 'home' ); endwhile; ?> <?php spun_content_nav( 'nav-below' ); ?> </div><!-- #content .site-content --> </div><!-- #primary .content-area --> <?php get_sidebar(); ?> <?php get_footer();
The page using the template can be found here.
[scratches his head]
I just noticed that the HTML of the page has the nav-below id.
<nav role="navigation" id="nav-below" class="site-navigation paging-navigation"> <h1 class="assistive-text">Post navigation</h1> </nav><!-- #nav-below --> </div><!-- #content .site-content --> </div><!-- #primary .content-area -->
I’m guessing the function is failing to generate the rest of the content for the navigation, no? If that’s the case, any ideas why?
I found a tentative solution, which is to simply list all posts in the same page. This means no navigation, as in the home page, so it’s not optimal.
To have a page show all your circles add the following parameter to your $args variable within the array:
'posts_per_page' => -1
The end result should look like this:
$args = array( // Change these category SLUGS to suit your use. 'category_name' => 'projects', 'posts_per_page' => -1, );
Post navigation in Spun is hidden until you hover over it (appearing only for small screens/mobile devices). You’ll see this when you look at the opacity styles applied to #nav-below in the theme’s style.css.
Content navigation has to be included within The Loop or else its functions won’t work, which is what you’re seeing with the empty markup.
Hi Caroline, thanks for the answer.
I thought that’s what I was doing with the line
<?php spun_content_nav( ‘nav-below’ ); ?>
(see code above)
What am I doing wrong?
It’s not currently within The Loop — you need to include it before the
endwhile;portion of the above code.
I tried doing that, and it then adds it after every circle (rightly so). I borrowed my approach from your own code (below), where it is outside of the endwhile;
Am I missing something?
<?php /** * The main template file. * * This is the most generic template file in a WordPress theme * and one of the two required files for a theme (the other being style.css). * It is used to display a page when nothing more specific matches a query. * E.g., it puts together the home page when no home.php file exists. * Learn more: http://codex.wordpress.org/Template_Hierarchy * * @package Spun * @since Spun 1.0 */ get_header(); ?> <div id="primary" class="content-area"> <div id="content" class="site-content" role="main"> <?php if ( is_home() && ! is_paged() ) : ?> <h2 class="site-description"><?php bloginfo( 'description' ); ?></h2> <?php endif; ?> <?php if ( have_posts() ) : ?> <?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php /* Include the Post-Format-specific template for the content. * If you want to overload this in a child theme then include a file * called content-___.php (where ___ is the Post Format name) and that will be used instead. */ get_template_part( 'content', 'home' ); ?> <?php endwhile; ?> <?php spun_content_nav( 'nav-below' ); ?> <?php elseif ( current_user_can( 'edit_posts' ) ) : ?> <?php get_template_part( 'no-results', 'index' ); ?> <?php endif; ?> </div><!-- #content .site-content --> </div><!-- #primary .content-area --> <?php get_sidebar(); ?> <?php get_footer(); ?>
Hmm, you’re right, it doesn’t have to be in The Loop unless it’s single post view.
I would try looking at the navigation function itself in inc/template-tags.php. You probably need to take the paged query variable into account somehow, since you’re using a custom query.
This thread might have some useful info:
- The topic ‘Circles to Pages part 2 – navigation’ is closed to new replies.