wordpress查询\u归档发布中的帖子
我想让我的所有文章在每个类别下降根据其得分(使用GD星级插件)。 我在插件网站上发现,我需要添加wordpress查询\u归档发布中的帖子,wordpress,archive,posts,Wordpress,Archive,Posts,我想让我的所有文章在每个类别下降根据其得分(使用GD星级插件)。 我在插件网站上发现,我需要添加query_帖子(“gdsr_sort=rating”)在my archive.php文件中 下面是my archive.php在添加了query_帖子后的外观: <?php query_posts("gdsr_sort=rating"); ?> <?php while (have_posts()) : the_post(); ?> <div <?p
query_帖子(“gdsr_sort=rating”)代码>在my archive.php文件中
下面是my archive.php在添加了query_帖子后的外观:
<?php query_posts("gdsr_sort=rating"); ?>
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class() ?>><li>
<h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a>
<?php endif; ?>
<?php the_content('Read more...'); ?>
</li>
</div>
<?php endwhile; ?>
<div class="clear"></div>
<?php wp_reset_query(); ?>
它把事情搞砸了,所以我尝试使用query_posts('posts_per_page=5')代码>
好的是它每页显示5篇文章。
糟糕的是,它显示了错误的文章。准确地说,无论我属于哪一类。。正在显示不应属于该子类别的相同文章。当你进入下一页时。。正在显示相同的文章。这些随处可见的物品只属于一个子类。
我还应该提到,我有10个分类,每个分类都有2-3个子分类
我在这里不知所措,希望您理解我的解释。您可以修改wordpress查询,而不是进行新的查询。我不知道您使用的插件,但我认为应该可以:
function change_archive_query( $query ) {
if ( $query->is_main_query() && $query->is_archive()) {
$query->set( 'gdsr_sort', 'rating' );
}
}
add_action( 'pre_get_posts', 'change_archive_query' );
您可以将其放在functions.php中。在archive.php中,您可以删除查询帖子您希望您的文章来自哪个类别?效果非常好。谢谢:)