在自定义post类型单个模板中使用快捷码进行WordPress分页
我有一个自定义的帖子类型设置,可以像页面一样运行。我正在使用一个shortcode函数列出这些页面中的一个自定义帖子类型 短代码可以工作,并使用WPNavi插件在帖子下方显示分页。下一页的链接显示:“/blog/page/2/”,但单击该链接时,它会将您带到同一页,而不是下一页的帖子。是否可以在自定义post类型子页面中使用分页在自定义post类型单个模板中使用快捷码进行WordPress分页,wordpress,pagination,Wordpress,Pagination,我有一个自定义的帖子类型设置,可以像页面一样运行。我正在使用一个shortcode函数列出这些页面中的一个自定义帖子类型 短代码可以工作,并使用WPNavi插件在帖子下方显示分页。下一页的链接显示:“/blog/page/2/”,但单击该链接时,它会将您带到同一页,而不是下一页的帖子。是否可以在自定义post类型子页面中使用分页 function rmcc_post_listing_shortcode1( $atts ) { ob_start(); global $post,
function rmcc_post_listing_shortcode1( $atts ) {
ob_start();
global $post,
$paged;
$authorID = $post->post_author;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$query = new WP_Query( array(
'posts_per_page' => '3',
'post_type' => 'custom_type',
'author' => $authorID,
'paged' => $paged
) );
$thumb = '';
$width = (int) apply_filters( 'et_pb_index_blog_image_width', 200 );
$height = (int) apply_filters( 'et_pb_index_blog_image_height', 130 );
$titletext = get_the_title();
$thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, true, 'Blogimage' );
$thumb = $thumbnail["thumb"];
?>
<div class="et_pb_posts portal-posts et_pb_bg_layout_light">
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'et_pb_post clearfix' ); ?>>
<?php if(has_post_thumbnail()) { ?>
<a href="<?php the_permalink(); ?>" class="post-thumbnail">
<?php print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
</a>
<?php } ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php
et_divi_post_meta();
if ( 'on' !== et_get_option( 'divi_blog_style', 'false' ) || ( is_search() && ( 'on' === get_post_meta( get_the_ID(), '_et_pb_use_builder', true ) ) ) )
truncate_post( 270 );
else
the_content();
?>
</article>
<?php endwhile;
wp_pagenavi( array( 'query' => $query ) );
endif;
wp_reset_query();
?>
</div>
<?php $myvariable = ob_get_clean();
return $myvariable;
}
add_shortcode( 'list-posts', 'rmcc_post_listing_shortcode1' );
函数rmcc\u post\u list\u shortcode1($atts){
ob_start();
全球美元邮政,
$paged;
$authorID=$post->post\u author;
$paged=(get_query_var('paged'))?get_query_var('paged'):1;
$query=新的WP\U查询(数组(
“每页帖子数”=>“3”,
“post_type”=>“custom_type”,
“author'=>$authord,
“paged”=>paged美元
) );
$thumb='';
$width=(int)应用过滤器('et_pb_index_blog_image_width',200);
$height=(int)应用过滤器('et_pb_index_blog_image_height',130);
$titletext=获取标题();
$thumbnail=get_缩略图($width,$height,$classtext,$titletext,$titletext,true,'Blogimage');
$thumb=$thumb[“thumb”];
?>
从wordpress codex上看:当多个循环(帖子列表)时主题模板文件中只使用了一个循环,即主循环,可以分页。
可能有一个插件用于此循环,或者使用get_pages/posts等创建自己的循环。谢谢,它似乎不起作用。也许我会使用jQuery插件添加分页。