【发布时间】:2018-02-18 17:21:58
【问题描述】:
我有一个 wordpress 博客,页面选择首页(主页),
当我选择页面作为主页(从外观 -> 阅读)时,分页不起作用并重定向到主页。
这意味着当输入这个地址时:example.com/page/2 它被重定向到example.com
我正在使用在 function.php 中调用的短代码显示我最近的帖子 这是我的简码:
function last_posts() {
$my_query = new WP_Query( 'cat=-1&posts_per_page=5' );
while ( $my_query->have_posts() ) : $my_query->the_post();
echo '<div style="margin: 20px 5px;" class="row post-inner-content">';
echo '<div class="col-md-8 col-sm-8 col-xs-6" style="padding-right: 15px;">';
echo '<a class="recent-posts-title" href="'.get_the_permalink().'">'.get_the_title().'</a>';
echo '<p class="recent-posts-date">'.get_the_date().'</p>';
echo '<p class="hidden-xs recent-posts-excerpt">';
echo kc_excerpt();
echo '</p>';
echo '<p class="recent-posts-cat">';
$cat = get_the_category($recent["ID"]); //get the category array
if ($cat[0]->name != "Featured") { //check if the category is "featured"
$catname = $cat[2]->name; //set $catname variable to "featured"
} else {
$catname = $cat[0]->name; //or set $catname variable to "other category name"
}
echo $catname; //output $catname variable
echo '</p>';
echo '</div>';
echo '<div class="col-md-4 col-sm-4 col-xs-6"><a href="'.get_the_permalink().'">'.get_the_post_thumbnail( $post_id, array( 350, 220) ).'</a></div>';
echo '</div>';
endwhile;
}
add_shortcode( 'lastposts', 'last_posts' );
我在主页(首页)中使用 [lastposts] 短代码来显示 5 个最近的帖子。
我如何在我的简码中添加分页号并且它的工作。 为什么分页不起作用? 对不起,我的英语不好 谢谢
【问题讨论】:
标签: php wordpress wordpress-theming