我有一些我正在使用的短代码。短代码本身正在工作。短代码具有分页功能,因为它正在图片库中循环。
分页本身可以工作,但当它前进时,也会前进其他使用相同短代码的图片库的分页。
我的问题是,我如何拥有相同的短代码,但在使用分页时只推进特定的库,而不是使用该短代码推进所有库?例如,如果我单击gallery 2017的第2页,gallery 2016将停留在第1页。
我在页面上使用的快捷码如下所示:[halloffame rml_folder="16"]
和[halloffame rml_folder="14"]
函数文件中的实际短代码如下所示:
function picture_gallery($atts){
extract(shortcode_atts(array(
\'rml_folder\' => 1
), $atts));
$paged = ( get_query_var( \'paged\' ) ) ? get_query_var( \'paged\' ) : 1;
query_posts("post_status=inherit&post_type=attachment&rml_folder=".$rml_folder."&orderby=title&order=asc&posts_per_page=12&paged=".$paged);
if ( have_posts() ) :
$return_string .= \'<div id="album">\';
while ( have_posts() ) : the_post();
$return_string .= \'<div class="gallery">\';
$image = wp_get_attachment_image(get_post_thumbnail_id($post->ID), \'medium\');
$return_string .= \'<a href="\'.wp_get_attachment_url($post->ID).\'" class="simplelightbox">\'.$image.\'</a>\';
$return_string .= \'</div>\';
endwhile;
$return_string .= \'</div>\';
endif;
$return_string .= \'<div id="pagi">\';
$return_string .= \'<div class="wrap">\';
$args = array(
\'prev_text\' => __(\'<span class="left"></span><span class="ion-android-arrow-dropleft"></span>\'),
\'next_text\' => __(\'<span class="ion-android-arrow-dropright"></span><span class="right"></span>\')
);
$return_string .= paginate_links($args);
$return_string .= \'</div>\';
$return_string .= \'</div>\';
global $wp_query;
$current_page = get_query_var( \'paged\' );
$pages = $wp_query->max_num_pages;
$return_string .= \'<p align="center">(Page: \'.$current_page.\' of \'.$pages.\')</p>\';
wp_reset_query();
return $return_string;
}
function register_shortcodes(){
add_shortcode(\'halloffame\', \'picture_gallery\');
}
add_action( \'init\', \'register_shortcodes\');
我绝对不受此代码的约束,如果有更好的方法,请不要犹豫!
有什么想法吗?
**更新**我已更新要使用的快捷码WP_Query
而不是query_posts
, 我的代码类似,但现在看起来像:
function picture_gallery($atts){
extract(shortcode_atts(array(
\'rml_folder\' => 1
), $atts));
$paged = ( get_query_var( \'paged\' ) ) ? get_query_var( \'paged\' ) : 1;
$picture_gallery = new WP_Query(array(
\'post_status\' => \'inherit\',
\'post_type\' => \'attachment\',
\'rml_folder\' => $rml_folder,
\'orderby\' => \'title\',
\'order\' => \'asc\',
\'posts_per_page\' => 12,
\'paged\' => $paged
));
if ( $picture_gallery->have_posts() ) :
$return_string .= \'<div id="album">\';
while ( $picture_gallery->have_posts() ) : $picture_gallery->the_post();
$return_string .= \'<div class="gallery">\';
$image = wp_get_attachment_image(get_post_thumbnail_id($post->ID), \'medium\');
$return_string .= \'<a href="\'.wp_get_attachment_url($post->ID).\'" class="simplelightbox">\'.$image.\'</a>\';
$return_string .= \'</div>\';
endwhile;
$return_string .= \'</div>\';
endif;
$return_string .= \'<div id="pagi">\';
$return_string .= \'<div class="wrap">\';
$return_string .= paginate_links(array(
\'prev_text\' => __(\'<span class="left"></span><span class="ion-android-arrow-dropleft"></span>\'),
\'next_text\' => __(\'<span class="ion-android-arrow-dropright"></span><span class="right"></span>\'),
\'total\' => $picture_gallery->max_num_pages
));
$return_string .= \'</div>\';
$return_string .= \'</div>\';
$current = get_query_var( \'paged\' );
$total = $picture_gallery->max_num_pages;
$return_string .= \'<p align="center">(Page: \'.$current.\' of \'.$total.\')</p>\';
return $return_string;
wp_reset_query();
}
function register_shortcodes(){
add_shortcode(\'halloffame\', \'picture_gallery\');
}
add_action( \'init\', \'register_shortcodes\');
现在,我又回到了我原来的问题,那就是对我的短代码进行分页可以在同一页上推进所有多个查询。。。仍在调查此事。
谢谢,乔希