我有自定义搜索的代码:
<?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; ?>&h=100&w=120&&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页时,返回第一个。
我该怎么办?
由于
答案 0 :(得分:0)
首先,您可以在codex Pagination page中阅读额外信息
在那里你会看到,为了让你的循环显示和使用分页,你需要将$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
的参数。