wordpress上传限制_如何限制WordPress中显示的存档月数

wordpress上传限制

Do you want to display the number of archive months displayed in WordPress? If you have been blogging for years, you will notice that your archives list will become too long. In this article, we will show you how to limit the number of archive months displayed in WordPress.

您是否要显示WordPress中显示的存档月数? 如果您已经写博客多年,您会发现存档列表将变得太长。 在本文中,我们将向您展示如何限制WordPress中显示的存档月份数。

How to limit number of archive months in WordPress
影片教学 (Video Tutorial)

演示地址

If you don’t like the video or need more instructions, then continue reading.

如果您不喜欢该视频或需要更多说明,请继续阅读。

方法1:使用插件限制存档月数 (Method 1. Limit Number of Archive Months with Plugin)

This method is easier and it is recommended for all users.

此方法更简单,建议所有用户使用。

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

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

Upon activation, you need to visit Appearance » Widgets page and add the Collapsing Archives widget to your sidebar.

激活后,您需要访问Appearance»Widgets页面,并将Collapsing Archives Widget添加到侧边栏。

Collapse archives

The widget menu will expand to show its settings.

小部件菜单将展开以显示其设置。

The Collapsing Archives widget uses JavaScript to collapse your archive links into collapsible yearly links. Your users can click on years to expand them to view monthly archives. You can even make monthly archives collapsible and allow users to see post titles underneath.

“折叠式存档”小部件使用JavaScript将您的存档链接折叠成可折叠的年度链接。 您的用户可以单击年份将其扩展以查看每月存档。 您甚至可以折叠每月的存档,并允许用户在下面查看帖子标题。

Review the widget settings to suit your needs and then click on the Save button to store your settings.

查看适合您需要的小部件设置,然后单击“保存”按钮以存储您的设置。

You can now visit your website to see the widget in action.

现在,您可以访问您的网站以查看正在运行的小部件。

Collapsing archives
方法2。用压缩存档替换默认存档 (Method 2. Replace Default Archives with Compact Archives)

This method provides a cleaner alternative to the default archives widget by beautifully displaying them in a compact more presentable way.

该方法通过以紧凑​​,更易于表现的方式精美地显示默认存档窗口小部件,从而提供了一种更干净的替代方法。

First, you need to install and activate the Compact Archives plugin. For more details, see our step by step guide on how to install a WordPress plugin.

首先,您需要安装并激活Compact Archives插件。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。

Upon activation, you need to visit Appearance » Widgets page and add the ‘Compact Archives’ widget to your sidebar.

激活后,您需要访问Appearance»Widgets页面,并将“ Compact Archives” Widget添加到边栏中。

Compact Archives settings

Compact Archives plugin comes in three styles. You can choose from block, initials, or numeric.

Compact Archives插件有三种样式。 您可以选择块,缩写或数字。

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

不要忘记单击“保存”按钮来存储您的小部件设置。

You can now visit your website to see the compact archives in action.

现在,您可以访问您的网站以查看实际的压缩归档。

Compact Archives preview

You can also use Compact Archives plugin to create a custom archives page on your site. For more details see our guide on how to create compact archives in WordPress

您还可以使用Compact Archives插件在您的站点上创建自定义档案页面 。 有关更多详细信息,请参见有关如何在WordPress中创建紧凑型归档文件的指南

方法3。手动限制WordPress中的存档月数 (Method 3. Manually Limit Number of Archive Months in WordPress)

This method requires you to add code to your WordPress theme files. If you haven’t done this before, then take a look at our guide on how to copy and paste code in WordPress.

此方法要求您将代码添加到WordPress主题文件中。 如果您以前没有做过,请查看我们的指南, 了解如何在WordPress中复制和粘贴代码

You will need to add the following code to your theme’s functions.php file or a site-specific plugin.

您将需要在主题的functions.php文件或特定站点的插件中添加以下代码。



// Function to get archives list with limited months
function wpb_limit_archives() { 

$my_archives = wp_get_archives(array(
	'type'=>'monthly', 
	'limit'=>6,
	'echo'=>0
));
	
return $my_archives; 

} 

// Create a shortcode
add_shortcode('wpb_custom_archives', 'wpb_limit_archives'); 

// Enable shortcode execution in text widget
add_filter('widget_text', 'do_shortcode'); 


This code fetches the archives list and limits it to past 6 months only. It then creates a shortcode and enables shortcode in text widgets.

此代码获取存档列表,并将其限制为仅过去6个月。 然后,它会创建一个简码并在文本小部件中启用简码。

You can now go to Appearance » Widgets page and add a ‘Text’ widget to your sidebar. Switch to the text mode and add your shortcode like this:

现在,您可以转到外观»小部件页面,并将“文本”小部件添加到侧边栏中。 切换到文本模式并添加您的短代码,如下所示:


<ul>
[wpb_custom_archives]
</ul>

Don’t forget to save your widget settings.

不要忘记保存小部件设置。

You can now visit your website to see your custom archives list in action.

现在,您可以访问您的网站以查看您的自定义存档列表。

That’s all, we hope this article helped you learn how to limit the number of archive months displayed in WordPress. You may also want to see our list of these most useful tricks for the WordPress functions file.

仅此而已,我们希望本文能帮助您学习如何限制WordPress中显示的存档月数。 您可能还需要查看WordPress函数文件的这些最有用技巧的列表。

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-limit-the-number-of-archive-months-displayed-in-wordpress/

wordpress上传限制

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值