• I’m building a custom theme for our website (Namespacestudio.com) and building the theme itself locally with the intent of moving it over. Ideally, I would like to have 5-10 posts/page with the ability to view previous posts by clicking the “Previous Posts” button. “Previous posts” works fine, but “Newer Posts” does not. Is this something that would be resolved on the live site (and this is just a localhost thing) or is there really an issue with the theme itself? If so, how might I resolve it?

    Here’s the code for the blog section of our homepage.

    <!--Blog section-->
    
    	<article class="homepage-blogposts">
    		<br>
    		<?php // Display blog posts on any page @ https://m0n.co/l
    		$temp = $wp_query; $wp_query= null;
    		$wp_query = new WP_Query(); $wp_query->query('posts_per_page=5' . '&paged='.$paged);
    		while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    
    		<!--Post title-->
    		<h2><a href="<?php the_permalink(); ?>" title="Read more"><?php the_title(); ?></a></h2>
    		
    		<!--Date published-->
    		<h4><?php the_time( get_option( 'date_format' ) ); ?></h4>
    		
    		<!-- Twitter button -->
    		<script src="https://platform.twitter.com/widgets.js" type="text/javascript"></script>
    			<a href="https://twitter.com/share" class="twitter-share-button"
    			data-url="<?php the_permalink(); ?>"
    			data-via="wpbeginner"
    			data-text="<?php the_title(); ?>"
    			data-related="syedbalkhi:Founder of WPBeginner"
    			data-count="vertical">Tweet</a>
    
    		<br>
    		<!-- Facebook button -->
    		<div class="fb-like" data-href="https://namespacestudio.com" data-width="75" data-layout="button" data-action="like" data-size="small" data-show-faces="true" data-share="true"></div>
    		
    		<!--Featured image-->
    		<div class="homeblog-featured-image"><center><?php the_post_thumbnail(); ?></center></div>
    		
    		<!--Post teaser and read more button-->
    		<div class="namespace-pager">
    			<?php the_content( $more_link_text , $strip_teaser ); ?>
    
    			<?php endwhile; ?>
    
    			<?php if ($paged > 1) { ?>
    
    			<nav id="nav-posts">
    				<div class="prev"><?php next_posts_link('<i class="fa fa-arrow-circle-left" aria-hidden="true"></i> Previous Posts'); ?></div>
    				<div class="next"><?php previous_posts_link('Newer Posts &raquo;'); ?></div>
    			</nav>
    
    			<?php } else { ?>
    
    			<nav id="nav-posts">
    				<div class="prev"><?php next_posts_link('<i class="fa fa-arrow-circle-left" aria-hidden="true"></i> Previous Posts'); ?></div>
    			</nav>
    
    			<?php } ?>
    
    			<?php wp_reset_postdata(); ?>
    		</div>
    
    	</article>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    Did you fix in a dashboard, setting-> reading-> display 10 posts per page as like https://www.screencast.com/t/g4qVHmP1nIm9

    Thread Starter namespacestudio

    (@namespacestudio)

    It was set to 10, so I tried setting both the posts per page (dashboard, setting-> reading-> Blog pages show at most) and this line:

    $wp_query = new WP_Query(); $wp_query->query('posts_per_page=5' . '&paged='.$paged);

    to 5.

    Still no luck. “Previous posts” works just fine, but newer posts does not.

    Hello @namespacestudio,

    Maybe a stupid question, but I want to ask it anyway: Did you navigate to the second page in order to check if the link “Newer Posts” is visible? On the first page only the link “Previous posts” is visible, as this page already starts with the latest posts.

    Thread Starter namespacestudio

    (@namespacestudio)

    Haha, yep. We absolutely did. It’s not working on any previous pages.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘“Previous Posts” is working on my blog page, but not “Newer Posts”’ is closed to new replies.