如何在wordpress中删除单个网站的分页?

dwthyt8l  于 2023-05-06  发布在  WordPress
关注(0)|答案(1)|浏览(131)

我喜欢保留分页的标准设置,但在单个网站上删除分页。我该怎么做?
我使用以下网站,分页应删除此网站:https://github.com/Alpenverein/DAV-Theme/blob/master/archive-personas.php
或者换句话说:我需要该页面的while循环遍历所有条目,而不是在达到第1页的金额时停止:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
fwzugrvs

fwzugrvs1#

你必须创建一个自定义的WP_Query并获取所有帖子。
另外,如果您根本不希望在存档视图中使用pagination函数,那么最好删除对该函数的调用。
有一个posts_per_page查询参数,您必须将其设置为-1。(ref)
对于这个存档页面,您还必须将post_type参数设置为personas。(ref)
假设post类型为personas。但是你可以从文件名中推导出来。因为自定义文章类型归档模板的命名方案是archive-{post-type}.php。(ref)

$query = new WP_Query([
  'posts_per_page' => -1,
  'post_type' => 'personas',
]);

那么你就不用

if ( have_posts() ) : while ( have_posts() ) : the_post();

你用

if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();

如docs中所示。(ref)

相关问题