如何在一页上显示所有WordPress帖子

Do you want to display all your WordPress posts on one page? Recently one of our readers wanted to create an archives page and show all WordPress posts on a single page. In this article, we will show you how to display all your WordPress posts on one page without pagination.

您要在一页上显示所有WordPress帖子吗? 最近,我们的一位读者希望创建一个存档页面,并在单个页面上显示所有WordPress帖子。 在本文中,我们将向您展示如何在一个页面上不分页显示所有WordPress帖子。

Show all WordPress posts on one page
为什么以及何时在一页上显示所有帖子? (Why and When to Display All Posts on One Page?)

WordPress comes with built in archive pages for each category, tags, author, and date.

WordPress带有针对每个类别,标签,作者和日期的内置存档页面。

Many site owners however prefer to create custom archives page for their site. The archives page usually highlight their popular posts, display a date based compact archive, list categories, or display tag clouds, and more. Take a look at WPBeginner’s archives page as an example.

但是,许多网站所有者更喜欢为其网站创建自定义存档页面 。 存档页面通常会突出显示其热门帖子 ,显示基于日期的紧凑型存档 ,列表类别或显示标签云等。 以WPBeginner的存档页面为例。

Some blogs prefer to simply display a list of all their WordPress post titles on one page.

一些博客更愿意在一页上显示所有WordPress帖子标题的列表。

影片教学 (Video Tutorial)

演示地址

If you don’t like video tutorials or want to move at your own pace, then continue reading the instructions below.

如果您不喜欢视频教程或想按照自己的节奏前进,请继续阅读以下说明。

在一页上显示所有WordPress帖子 (Showing All WordPress Posts on One Page)

There are many different ways to display all your WordPress posts on a single page. You can display posts on a page with a shortcode, you can display posts on a page using a plugin, and lastly you can display all posts on a page using a custom template and loop.

有许多种方法可以在单个页面上显示所有WordPress帖子。 您可以使用短代码在页面上显示帖子,可以使用插件在页面上显示帖子,最后可以使用自定义模板和循环在页面上显示所有帖子。

We will cover all three methods starting with the most beginner friendly one.

我们将以最适合初学者的方法开始介绍所有三种方法。

方法1:使用显示帖子简码插件 (Method 1: Using Display Posts Shortcode Plugin)

First thing you need to do is install and activate the Display Posts Shortcode plugin. For more details, see our step by step guide on how to install a WordPress plugin.

您需要做的第一件事是安装并激活Display Posts Shortcode插件。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。

This plugin works out of the box, and there are not settings for you to configure.

该插件可以直接使用,没有可供您配置的设置。

Go ahead and create a new page and call it Archives or any other title. After that, you need to paste the following shortcode in your page.

继续创建一个新页面,并将其称为“存档”或任何其他标题。 之后,您需要在页面中粘贴以下短代码


[display-posts posts_per_page="1000" order="DESC"]

This shortcode will simply display a list of all your post titles in a chronological order. It is set to display maximum 1000 posts per page.

该短代码将仅按时间顺序显示所有帖子标题的列表。 设置为每页最多显示1000个帖子。

If you have more than a thousand posts, then you can change that. You can also change the post order to ASC which will display posts in a reverse chronological order (older posts first).

如果您有一千多个帖子,则可以更改。 您也可以将发布顺序更改为ASC,这将按相反的时间顺序显示发布(先显示旧发布)。

List all posts in WordPress

While you could use the display posts shortcode to show excerpts, thumbnails, and other related information, we don’t recommend doing that. When you are listing all your posts on a single page, this page will be long, and you want to make sure it’s simple and fast. Just displaying post titles is sufficient for archives page of this style.

虽然您可以使用显示帖子短代码来显示摘录,缩略图和其他相关信息,但我们不建议您这样做。 当您在一个页面上列出所有帖子时,此页面会很长,并且您想确保它既简单又快速。 仅显示帖子标题就足够了此样式的存档页面。

If you want to display posts on page based on category or other parameters, you can do so by following the detailed usage instructions on their documentation page.

如果要基于类别或其他参数在页面上显示帖子,可以按照其文档页面上的详细使用说明进行操作。

方法2:使用简单的年度存档插件 (Method 2: Using Simple Yearly Archive Plugin)

Showing all your WordPress posts on a single page can make it too long to scroll. You can fix that by showing a list of each year. Users can then click on a year to expand it and see the posts published that year.

在单个页面上显示所有WordPress帖子可能会使滚动时间太长。 您可以通过显示每年的列表来解决此问题。 然后,用户可以单击年份以展开它并查看该年发布的帖子。

First thing you need to do is install and activate the Simple Yearly Archive plugin.

您需要做的第一件事是安装并激活Simple Yearly Archive插件。

Upon activation, you need to go to Settings » Simple Yearly Archive page to configure plugin settings.

激活后,您需要转到设置»简单年度存档页面以配置插件设置。

Simple yearly archive settings

The plugin allows you to display list of posts in a variety of ways. You can show them all under links to yearly archives, or you can show them under collapsible years.

该插件可让您以多种方式显示帖子列表。 您可以在指向年度存档的链接下显示所有内容,也可以在可折叠的年份下显示它们。

If you want to display them under collapsible years, then you need to add <div> and </div> next to the option ‘Before / After (Year headline)’.

如果要在可折叠年份下显示它们,则需要在“之前/之后(年份标题)”选项旁边添加<div>和</ div>。

Rest of the plugin options are quite self-explanatory. You can set them up according to your needs.

其余的插件选项很不言自明。 您可以根据需要进行设置。

Don’t forget to click on the save changes button to store your settings.

不要忘记单击“保存更改”按钮来存储您的设置。

Now to display all your posts on a page, you just need to add [SimpleYearlyArchive] shortcode to the page of your choice.

现在,要在页面上显示所有帖子,只需将[SimpleYearlyArchive]简码添加到所选页面。

Collapsible yearly archives showing all posts in WordPress

The plugin provides a range of parameters that can be used with the shortcode. You can look at the parameters on plugin’s documentation page.

该插件提供了可以与短代码一起使用的一系列参数。 您可以在插件的文档页面上查看参数。

方法3:使用模板代码在一页中显示所有WordPress帖子 (Method 3: Display All WordPress Posts in One Page with Template Code)

While using a plugin to display all posts in one page is the easiest way, some of you may want to learn how to do it with page templates code.

虽然使用插件在一个页面中显示所有帖子是最简单的方法,但有些人可能想学习如何使用页面模板代码来实现。

First you will need to create a custom page template and copy the styling from your page.php file.

首先,您将需要创建一个自定义页面模板,并从page.php文件中复制样式。

After that, you will use a loop below to display all posts in one page.

之后,您将使用下面的循环在一页中显示所有帖子。


<?php 
// the query
$wpb_all_query = new WP_Query(array('post_type'=>'post', 'post_status'=>'publish', 'posts_per_page'=>-1)); ?>

<?php if ( $wpb_all_query->have_posts() ) : ?>

<ul>

	<!-- the loop -->
	<?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
		<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
	<?php endwhile; ?>
	<!-- end of the loop -->

</ul>

	<?php wp_reset_postdata(); ?>

<?php else : ?>
	<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

If the above code instructions does not make sense, the we recommend that you use method 1.

如果上述代码说明没有意义,我们建议您使用方法1。

We hope this article helped you display all your WordPress posts on one page. You may also want to see our guide on 8 proven methods to promote old posts in WordPress.

我们希望本文能帮助您在一页上显示所有WordPress帖子。 您可能还希望查看有关在WordPress中推广旧帖子的8种成熟方法的指南。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-display-all-your-wordpress-posts-on-one-page/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值