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