WordPress.org

Ready to get started?Download WordPress

Forums

PageNavi don't work in Search or archive (3 posts)

  1. PureRushh
    Member
    Posted 1 year ago #

    Hello.

    I have some problems with using the PageNavi plugin in my WordPress Theme. I've added the plugin in all my pages, posts and archvies. But in archives and search-results the PageNavi don't work. It just returns an URL like /page/2?s=example and then I return to the frontpage of my theme.

    The theme is own build by me. I've have googled the problem and find the error using query_posts(); wrong. So I changed all the querys to how it should be, but still I've got the error.

    Here is my code:

    search.php

    <?php get_header(); ?>
    <div id="content-search">
    <?php if (have_posts()) : ?>
    <?php query_posts( array( 'posts_per_page' => 1, 'paged' => get_query_var('paged') ) );
    				<?php while (have_posts()) : the_post(); ?>
                    <div class="search-news">
                    	<div class="search_therms">
            				<h2 class="search_h2"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e( 'link til') ?> <?php the_title_attribute(); ?>" ><b><?php the_title(); ?></b></a></h2>
            				<div class="search-content"><?php the_excerpt(); ?></div>
            			</div>
                       <div class="read-more"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e( 'link til') ?> <?php the_title_attribute(); ?>" ><b>Les mer</b></a></div>
                     <center><img src="<?php bloginfo('stylesheet_directory'); ?>/images/news-line.png" /></center>
    
                     </div><!-- end of search -->
                    <?php endwhile; ?>
                   <?php wp_pagenavi( array( 'type' => 'multipart' ) ); ?>
                    <?php else: ?>
                      <div class="error-search"><p>Beklager, ingen artikler eller sider<br /> stemte med dine søkekriterier, kanskje et nytt søk vil hjelpe?</p><br /> <div class="search-bar"><?php include 'searchform.php'; ?></div></div>
                    <?php endif; ?>
    </div>
    <?php get_footer(); ?>

    and my index.php

    <?php get_header(); ?>
    <div id="content-holder">
    <?php if (have_posts()): ?>
        <?php query_posts( array( 'showposts' => 2, 'paged' => get_query_var('paged') ) ); ?>
        <?php while (have_posts()) : the_post(); ?>
            <div id="box-news">
           		<div class="box-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e( 'link til') ?> <?php the_title_attribute(); ?>" ><h2><?php the_title(); ?></h2></a><p class="p-box"><?php the_date(); ?> skrevet av <?php the_author(); ?></p>
    
            	</div>
                <div class="box-content"><?php the_excerpt(); ?><br /> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e( 'link til') ?> <?php the_title_attribute(); ?>" >Les mer</a></div>
                <br /><center><img src="<?php bloginfo('stylesheet_directory'); ?>/images/news-line.png" /></center>
            </div>
    
          <?php endwhile; ?>
    
    	  <div id="other-posts">
          <center><h2>Flere nyheter</h2></center>
    	 <?php query_posts( array( 'showposts' => 18, '&offset' => 2, 'paged' => get_query_var('paged') ) ); ?>
         <?php while (have_posts()) : the_post(); ?>
         <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e( 'link til') ?> <?php the_title_attribute(); ?>" ><p><?php the_title(); ?></p></a>
         <?php endwhile; ?>
         </div>
    	 <?php else: ?>
          <p class="could_not404">Beklager, ingen artikler eller<br /> sider ble funnet, kanskje et søk vil hjelpe?</p>
         <?php endif; ?>
    
    </div>
    <div id="sidebar">
    <div class="countdown"><?php echo do_shortcode('[CountDown id=1 width=250 custom_widget=1 containerx=0 containerxy=0 imagebackground=false reflection=false year=2012 month=10 day=5 hours=22 minute=00 textunder=true color=dark]'); ?></center></div>
    <div id="ord-holder">
    <center><img src="<?php bloginfo('stylesheet_directory'); ?>/images/slag-ord.png" style="margin-top: 30px;"/></center>
    </div>
    </div>
    <?php get_footer(); ?>

    So could someone please be nice and help me!

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    Hi PureRushh try paginating this way.
    Control the posts per page from your theme's functions.php:

    function my_post_queries( $query ) {
          // not an admin page and it is the main query
          if (!is_admin() && $query->is_main_query()){
    
            // home page
            if(is_home()){
              $query->set('posts_per_page', 20);
            }
    
            // search archive pages
            if(is_search()) {
              $query->set('posts_per_page', 1);
            }
    
          }
        }
        add_action( 'pre_get_posts', 'my_post_queries' );

    make index.php only with one loop and no query_posts so you can paginate it more easily: http://pastebin.com/EXGJ4FNZ

    Remove the query and array( 'type' => 'multipart' ) on your search template: http://pastebin.com/Nxwnn4LA

  3. PureRushh
    Member
    Posted 1 year ago #

    Hmm, no it wont paginate. On archive i see all posts in the archive and not just 1 posts. What is wroong?

Topic Closed

This topic has been closed to new replies.

About this Topic