分页在自定义查询循环中有效,但在短码中不起作用

时间:2013-10-31 作者:elenakoroleva

是否可以使用短代码?分页在自定义模板页面上运行良好。但我想用短代码显示帖子。帖子显示良好。但是分页工作不正确。所有页面上的帖子都相同。页面模板中的自定义查询循环:

$page = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;  
        $args = array(
    \'posts_per_page\' =>\'1\', 
    \'orderby\' => \'post_date\',
    \'paged\' => $paged,
    \'post_type\' => \'accomodation\',
    \'tax_query\' => array(
        \'relation\' => \'AND\',
        array(
            \'taxonomy\' => \'accomodation_category\',
            \'field\' => \'slug\',
            \'terms\' => \'gostinnitsy-2\'
        ),
        array(
            \'taxonomy\' => \'location\',
            \'field\' => \'slug\',
            \'terms\' => \'litva\'
        )
    )
);
$custom_query = new WP_Query( $args );
// Pagination fix
$temp_query = $wp_query;
$wp_query   = NULL;
$wp_query   = $custom_query;

?>

  
 have_posts() ) :
    while ($custom_query-> have_posts() ) :
        $custom_query->the_post();?>
                






  

max_num_pages );


$wp_query = NULL;
$wp_query = $temp_query;?>

和我的功能短代码。php


function accomodation_catalog_shortcode( $atts )
{
extract(shortcode_atts(array(
     \'accomodation\' => \'\',
     \'location\'     => \'\',
     \'number\'       =>\'-1\',
     \'orderby\'      => \'post_date\'
   ), $atts));
    $page = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;  
     global $post;
        $args = array(
    \'posts_per_page\' =>$number, 
    \'orderby\' => $orderby,
    \'paged\' => $paged,
    \'post_type\' => \'accomodation\',
    \'tax_query\' => array(
        \'relation\' => \'AND\',
        array(
            \'taxonomy\' => \'accomodation_category\',
            \'field\' => \'slug\',
            \'terms\' => $accomodation
        ),
        array(
            \'taxonomy\' => \'location\',
            \'field\' => \'slug\',
            \'terms\' => $location
        )
    )
);
$custom_query = new WP_Query( $args );
// Pagination fix
$temp_query = $wp_query;
$wp_query   = NULL;
$wp_query   = $custom_query;

?>

  
 have_posts() ) :
    while ($custom_query-> have_posts() ) :
        $custom_query->the_post();?>
                






  

max_num_pages );


$wp_query = NULL;
$wp_query = $temp_query;?>

    

I corrected the error:\'paged\' => $page, and pagination work!

But why when I want to display shortcode content under page content, shortcode content are displayed above page content?

In admin:

<p>page content<p>
[ accomodation-catalog location=\'slug \' accomodation=\'slug\']

display

<div>shortcode content</div> <p>page content<p>
怎么了?

1 个回复
SO网友:Courtney Ivey

嗯。。。看起来您的shortcode函数定义了$页,但查询本身使用$paged....使用d 在最后。可能会删除d?换言之,尝试改变

\'paged\' => $paged
进入

\'paged\' => $page

结束

相关推荐

Pagination in category

Updated: I have 50 categories and i wants to show each 5 category on one page and next 5 on next page and next 5 on next page. and so on. with pagination.我在WordPress网站上有50个类别。我想在每一页上显示五个类别,用10篇文章分页。我已经尝试过了,但分页并没有产生效果。<?php // get all the categ