如何在一个类别中粘贴多个帖子以显示在该类别的顶部?
Tried Ideas:我尝试使用“分类贴子”插件,但它只允许我为每个类别固定一篇文章。
还尝试将帖子粘贴到主页,并从主页中删除特色帖子,但它们不会粘贴在类别顶部。
如何在一个类别中粘贴多个帖子以显示在该类别的顶部?
Tried Ideas:我尝试使用“分类贴子”插件,但它只允许我为每个类别固定一篇文章。
还尝试将帖子粘贴到主页,并从主页中删除特色帖子,但它们不会粘贴在类别顶部。
你的category.php
应该有两个环-一个用于粘滞,一个用于常规帖子:
<?php
// get sticky posts array
$sticky = get_option(\'sticky_posts\');
// First WP_Query arguments
$args = array(
// include stickies
\'post__in\' => $sticky
);
$query = new WP_Query( $args );
// First loop for stickies only
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post() );
echo get_the_title() . \'<br />\';
echo get_the_content() . \'<br />\';
endwhile; endif;
wp_reset_postdata(); // don\'t forget to reset before the next loop
/***************************************/
// Second WP_Query arguments
$args = array(
// exclude stickies
\'post__not_in\' => $sticky
);
$query = new WP_Query( $args );
// Second loop for posts excluding stickies
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post() );
echo get_the_title() . \'<br />\';
echo get_the_content() . \'<br />\';
endwhile; endif;
wp_reset_postdata(); // if necessary
更有可能的是,您将需要更多WP_Query
参数。参见WP_Query;Sticky Posts
我目前正在处理的网站中的帖子都有多个层次分类。例如:Source - Books -- Moby Dick -- Sherlock Holmes 永久链接设置为/%category%/%postname%/. 然而,一篇文章的URL并不包括所有的子类别——我得到的只是site.com/source/books/*postname*, 尽管这篇文章在来源上没有分类,但只在书籍+白鲸上。有人能帮我找出如何调整这种行为吗?非常感谢。