WP-导航错误循环

问题描述 投票:0回答:1

我有这个用于自定义搜索的代码:

    <?php get_header(); ?>

<div id="content-wrap" class="clear" >
 <div id="content">
  <!--the loop-->
 <?php 
    function cut_string_using_last($character, $string, $side, $keep_character=true) {
    $offset = ($keep_character ? 1 : 0);
    $whole_length = strlen($string);
    $right_length = (strlen(strrchr($string, $character)) - 1);
    $left_length = ($whole_length - $right_length - 1);
    switch($side) {
        case 'left':
            $piece = substr($string, 0, ($left_length + $offset));
            break;
        case 'right':
            $start = (0 - ($right_length + $offset));
            $piece = substr($string, $start);
            break;
        default:
            $piece = false;
            break;
    }
    return($piece);
}
?>  
  <?php query_posts( array( 'category__and' => array( 8, 69 ) ) );?>
  <?php  if (have_posts()) : ?>
  <div id="categoria-archive" class="categoria-archive">Escorts en la procincia de Jaen</div>
  <!--loop article begin-->
  <div class="cajita">
  <?php while (have_posts()) : the_post(); ?>
   <?php 
   $precio = get_post_meta($post->ID, 'precio', $single = true);
   $mimg = get_post_meta($post->ID, 'post_images', $single = true);
   $mimg5 = '';
   $post_images_arr = explode(',',$mimg);
   $mimg = $post_images_arr[0];
   $mimg2 = substr (strrchr ($mimg, "/"), 1);
   $mimg3 = get_option( 'siteurl' ) ."/$upload_folder_path".'products_img/90/';
   $mimg4 = cut_string_using_last('/', $mimg, 'left', false);
   $mimg5= $mimg4.'/90/'.$mimg2;



  $catinfoarr = get_the_category();
        $feature_class = '';
        for($c=0;$c<count($catinfoarr);$c++)
        {
            if($catinfoarr[$c]->term_id == $General->get_feature_catid())
            {
                $feature_class = 'feature_post';
                break;
            }
        }
        if($_REQUEST['page']=='featured' || $_REQUEST['page']=='latest')
        {
            $guid = $post->guid;
        }else
        {
            $guid = get_option('siteurl')."/?page=ads&pid=".$post->ID;
        }

   ?>  
 <?php the_date('l j F Y', '<h6 id="background_date" class="background_date">', '</h6>' ); ?>

<div id="post-<?php the_ID(); ?>" class="listados <?php echo $feature_class; ?>">
<div class="caja-precio2">
        <?php if ($precio !== ''){?>
       <span class="tag-head2"><div class="precio-main2"><?php echo $precio;?> €</div></span>
       <?php } else
       {?>
       <?php } ?>
       </div>

      <a  href="<?php the_permalink() ?>">  <?php if($mimg5 !== '') { 

      ?>
     <img src="<?php bloginfo('template_directory'); ?>/thumb.php?src=<?php echo $mimg5; ?>&amp;h=100&amp;w=120&amp&a=t;zc=1<?php echo $thumb_url;?>" alt="<?php the_title(); ?>" class="imagenespostlistingg" /> </a>
      <?php } // end if statement
                // if there's not a thumbnail
                else { echo '<div class="imgnot_available" ><img src="http://localhost/anuncios/vacia.jpg"></div>'; } ?>

      <?php
      if($_REQUEST['page'] =='featured' || $_REQUEST['page']=='latest')
      {
      ?>
       <div id="titulo-post" class="titulo-post"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
      <div class="categorias"><?php the_categorys('>', 'single') ?></div>
      <p class="time"><span class="i_clock alignleft"> <?php the_time('j F, Y') ?> at <?php the_time('g:i a') ?> </span> 
      <span class="i_comments alignleft"> <?php comments_popup_link('(0) Comment', '(1) Comment', '(%) Comment'); ?> </span> 
      <strong class="alignright red"> <?php if(function_exists('the_views')) { the_views(); } ?> </strong></p>
       <div class="descripcion"><?php $short = stripslashes($post->post_content);       
         $short = substr($short, 0, 200);
         $short = strtoupper($short); 
         $caden=uploads;
         if (strstr ($short, "http")){
         echo "";
         }
         elseif (strstr ($short, "png")){
         echo "";
         }
         elseif (strstr ($short, "jpg")){
         echo "";
         }
         elseif (strstr ($short, "gif")){
         echo "";}
         else {  
         echo strip_tags($short);}
         ?></div>

      <?php
      }else{
      ?>
      <div class="caja1">
      <div id="titulo-post" class="titulo-post"><a  href="<?php the_permalink() ?>"><?php the_title(); ?></a></div>
      <div class="categorias"><?php the_categorys(' - ')?></div>
      <p class="time"><span class="i_clock alignleft"> <?php the_time('j F, Y') ?> at <?php the_time('g:i a') ?> </span></p>
       <strong class="alignright red"> <?php if(function_exists('the_views')) { the_views(); } ?> </strong>
       <div class="descripcion"><?php $short = stripslashes($post->post_content);
         $short = html_entity_decode($short);
         $short = utf8_encode($short);
         $short = strip_tags($short);    
         $short = substr($short, 0, 200);     
         $short = strtoupper($short); 
         echo "$short ...";
         ?></div>
      <?php }?>
  </div>
  </div>
  <?php endwhile; ?>
  <div class="googleads">
          <?php if ( function_exists('dynamic_sidebar') && (is_sidebar_active(7)) ) { // Show on the front page ?>
                <?php dynamic_sidebar(7); ?>  
         <?php } ?>
     </div>
  <!--page nav end -->
   <?php if(function_exists('wp_pagenavi')) { ?>
  <div class="wp-pagenavi">
    <?php wp_pagenavi();  ?>
   </div>
 <? } ?>

</div>
<div class="final4"></div>  
  <!-- do not delete-->
   <?php else : ?>
  <div class="error-caja">
  <div class="error-superior">Anuncio no encontrado</div>
  <div class="error-texto"><br> Lo sentimos.</br><br>No existe ningún anuncio con los</br><br>criterios de búsqueda indicados.</br><br>El equipo de</br><br><a href="<?php echo get_option('home'); ?>/"><img src="<?php if ( get_option('ptthemes_logo_url') <> "" ) { echo get_option('ptthemes_logo_url'); } else { echo get_bloginfo('template_directory').'/images/logo2.png'; } ?>" alt="<?php bloginfo('name'); ?>"/></a></br> </div>
  <meta http-equiv="Refresh" content="5;url=<?php echo home_url(); ?>">
  <div class="error-inferior"></div>
  </div>
  <?php endif; ?>
  <?php wp_reset_query();?>
  <!--search.php end-->
</div>


<?php get_sidebar(); ?> <!-- sidebar #end -->
<?php get_footer(); ?> <!-- footer #end -->

我添加此行以在 2 个(两个)类别中创建自定义搜索:

<?php query_posts( array( 'category__and' => array( 8, 69 ) ) );?>

查询工作正常,但我不能不使用 WP-Navigation 导航页面 2、3 等。当我点击转到第 2 页时,返回到第一页。

我该怎么办?

谢谢

php wordpress
1个回答
0
投票

首先,您可以在法典分页页面中阅读额外信息。
您将看到,为了让循环显示并使用分页,您需要将

$paged
变量传递给查询并从一页传递到另一页。

通常 $paged 变量是这样构建的:

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>

并传递给查询,如下例所示:

<?php query_posts('posts_per_page=3&paged=' . $paged); ?>

要使用您的代码实现此功能:

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php query_posts( array( 'category__and' => array( 8, 69 ), 'paged'=>$paged ) );?>

因此将第一行添加到

query_posts
函数上方,并添加
'paged'=>$paged
作为
query_posts
的参数。

© www.soinside.com 2019 - 2024. All rights reserved.