Support » Fixing WordPress » display certain number of posts on index.php

  • Resolved vince23

    (@vince23)


    Hey,

    I have an index.php based on the twenty eleven-theme.

    How can I edit this code, so that I only 15 posts

    are shown and older ones are hidden. I need 5 per page (as it is right now).

    Thanks !

    Code:

    <?php
    /*Template Name:My Template */
    
    get_header(); ?>
    
    		<div id="primary_index">
    
    			<div id="content" role="main">
    
    			<?php if ( have_posts() ) : ?>
    
    				<?php twentyeleven_content_nav( 'nav-above' ); ?>
    
    				<?php /* Start the Loop */ ?>
    				<?php while ( have_posts() ) : the_post(); ?>
    
    					<?php get_template_part( 'content', get_post_format() ); ?>
    
    				<?php endwhile; ?>
    
    				<?php twentyeleven_content_nav( 'nav-below' ); ?>
    
    			<?php else : ?>
    
    				<article id="post-0" class="post no-results not-found">
    
    <?php if ( has_post_thumbnail() ) {
    										the_post_thumbnail();} ?>
    <header class="entry-header">
    						<h1 class="entry-title"><?php _e( 'Nothing Found', 'twentyeleven' ); ?></h1>
    					</header><!-- .entry-header -->
    
    					<div class="entry-content">
    
    <p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyeleven' ); ?></p>
    						<?php get_search_form(); ?>
    					</div><!-- .entry-content -->
    				</article><!-- #post-0 -->
    
    			<?php endif; ?>
    
    			</div><!-- #content -->
    		</div><!-- #primary -->
    
    <?php get_footer(); ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • [Admin panel] >> [Options] >> [Reading]

    but I can only set the amount of posts per page.

    I d like to know whether its possible to hide

    posts after the last 15 posts.

    You may look for a plugin similar to http://wordpress.org/plugins/hide-old-posts/.

    ok, thats an option. thank you

    any code solutions ?

    Have a look at your loop.php and hide Navigation “Older Entries” if there are more pages than a sertain number.

    Your posts/page = 5
    Your max post you want to show = 15
    Your max pages would be 3

    So try this (depending on your template, find <nav> tag and change it)

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        if($paged < 3) : ?>
            <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'justcss' ) ); ?></div>
        <?php endif; ?>

    Example:

    <?php /* Display navigation to next/previous pages when applicable */ ?>
    <?php if (  $wp_query->max_num_pages > 1 ) :?>
    	<nav id="nav-below">
    		<h1 class="section-heading"><?php _e( 'Post navigation', 'justcss' ); ?></h1>
    		<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    		if($paged < 3) : ?>
    		<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'justcss' ) ); ?></div>
    		<?php endif; ?>
    		<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'justcss' ) ); ?></div>
    	</nav><!-- #nav-below -->
    <?php endif; ?>

    Thank you !

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘display certain number of posts on index.php’ is closed to new replies.