WordPress.org

Support

Support » How-To and Troubleshooting » If archives or search results < X, do not display navigation bar

If archives or search results < X, do not display navigation bar

  • Hi 🙂

    My WP install is configured to show 15 posts/results/archives per page. So, when you display a page with more than 15 posts/results/archives, the navigation bar displays to allow the visitor to browse the previous posts/results/archives.

    BUT when there are LESS THAN 15 posts (or whatever number you set up in your config), my navigation bar shows all the same, causing some CSS trouble (since there are no “Previous” nor “Next” links, my div is empty and screws everything up).

    So I would like to say in PHP: “if there are LESS – OR – AS MANY AS 15 posts/results/archives, do NOT display the div which contains the navigation links”.

    Can anybody help me with this please? Maybe it’s simple but I’m no PHP developper. I guess it has something to do with the php endif or something, but I can’t figure it out and do not want to break my site.

    Here is my search.php page:

    <?php get_header(); ?>
    
    <?php get_sidebar(); ?>
    
    	<div id="content" class="hasLayout">
    
    	<?php if (have_posts()) : ?>
    
    	<div id="titre_h2">
    		<h2 class="pagerech">RĂ©sultats de la recherche</h2>
    	</div>
    
    		<div class="navigation_fix">
    			<div class="alignleft"><?php next_posts_link('&laquo; Résultats précédents') ?></div>
    			<div class="alignright"><?php previous_posts_link('RĂ©sultats suivants &raquo;') ?></div>
    		</div>
    
    		<?php while (have_posts()) : the_post(); ?>
    
    			<div class="post hasLayout">
    				<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permalink vers <?php the_title(); ?>"><?php the_title(); ?></a></h3>
    
    				<p class="postmeta">Ecrit le <?php the_time('j F Y') ?> <?php _e('Ă '); ?> <?php the_time() ?>, mis Ă  jour le <?php mdv_last_modified(); ?> · <?php _e('PostĂ© dans'); ?> <?php the_category(', ') ?>
    
    				<p class="postmetatag">Tags: <?php STP_PostTags(); ?>
    
    				<p class="postmetadata"><?php comments_popup_link('Aucun commentaire »', '1 commentaire »', '% commentaires »'); ?>
    
    			</div>
    
    	<?php endwhile; ?>
    
    		<div class="navigation_fix">
    			<div class="alignleft"><?php next_posts_link('&laquo; Résultats précédents') ?></div>
    			<div class="alignright"><?php previous_posts_link('RĂ©sultats suivants &raquo;') ?></div>
    		</div>
    
    	<?php else : ?>
    
    		<h2>Aucun billet trouvé. Lancez une autre recherche.</h2>
    		<form id="searchform" method="get" action="<?php echo get_settings('siteurl'); ?>/index.php">
    		Rechercher: <input type="text" name="s" size="30" /> <input type="submit" value="<?php _e('Ok'); ?>" />
    
    		</form>
    
    	<?php endif; ?>
    
    	</div>
    
    <?php get_footer(); ?>

    I do not post my archives.php page, I think it might be the same kind of solution – but tell me whenever I need to post it.

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘If archives or search results < X, do not display navigation bar’ is closed to new replies.
Skip to toolbar