
wordpress相册检查
Did you know that WordPress allows you to feature your posts by 使用置顶帖 feature. However, sticky posts are one of the least known features of WordPress. In this article, we will show you 6 cool things you can do with sticky posts in WordPress.
您是否知道WordPress允许您使用置顶帖功能来展示您的帖子。 但是,粘性帖子是WordPress鲜为人知的功能之一。 在本文中,我们将向您展示WordPress中的粘帖可以做的6件事。

影片教学 (Video Tutorial)
如果您不喜欢该视频或需要更多说明,请继续阅读。
如果您不喜欢该视频或需要更多说明,请继续阅读。
1.自动过期即时贴 (1. Automatically Expire Sticky Posts)
如果您使用置顶帖子来突出显示特殊活动或优惠券,那么您需要在该活动结束后取消置顶帖子。
如果您使用置顶帖来突出显示特殊活动或优惠券,则需要在活动结束后取消置顶贴。
这听起来像是不必要的工作,您应该将其自动化。
这听起来像是不必要的工作,您应该将其自动化。
Simply install and activate the 使置顶帖子过期 plugin. Upon activation, you can set expiry date for sticky posts.
只需安装并激活使置顶帖子过期插件即可。 激活后,您可以为即时贴设置过期日期。

After the expiry date, your sticky post will automatically become a normal post. For detailed instructions take a look at our tutorial (with video) on how to set 置顶帖的过期日期 in WordPress.
有效期过后,您的粘性帖子将自动变为普通帖子。 有关详细说明,请看一下我们的教程(带视频),该教程如何设置WordPress中置顶帖子过期日期 。
2.类别的便利贴 (2. Sticky Posts for Categories)
默认情况下,置顶帖子仅出现在您网站的首页上。但是,如果您想在类别存档页面上显示特色内容怎么办?
默认情况下,置顶帖子仅出现在网站的主页上。但是,如果您想在类别存档页面上显示特色内容怎么办?
You can do that by installing and activating the 类别置顶帖 plugin. Upon activation, edit a post that you want to feature and select the sticky post category.
您可以通过安装并激活类别置顶帖插件来做到这一点。 激活后,编辑要突出显示的帖子,然后选择即时贴类别。

For more detailed instructions, see our tutorial on how to add 类别置顶帖 in WordPress.
有关更多详细说明,请参阅有关如何在WordPress中对于类别添加置顶帖教程。
3.显示最新的即时贴 (3. Display Latest Sticky Posts)
通常,粘性帖子用于特色帖子,以显示您最突出的内容。但过了一段时间,您的旧精选帖子就会消失在档案中。您可以通过在自定义存档页面或网站上的其他任何位置显示旧的特色内容,使它们恢复生机。
通常,粘性帖子用于特色帖子以显示您最突出的内容。但过了一段时间,你的旧精选帖子就从档案中消失了。您可以将旧的特色内容显示在自定义存档页面或网站上的任何其他位置,从而使其恢复生机。
Simply paste this code in your theme’s 函数.php file or a 特定于站点的 WordPress 插件.
只需将此代码粘贴到主题的函数.php文件或具体的于在网站的 WordPress 插件中 。
function wpb_latest_sticky() {
/* Get all sticky posts */
$sticky = get_option( 'sticky_posts' );
/* Sort the stickies with the newest ones at the top */
rsort( $sticky );
/* Get the 5 newest stickies (change 5 for a different number) */
$sticky = array_slice( $sticky, 0, 5 );
/* Query sticky posts */
$the_query = new WP_Query( array( 'post__in' => $sticky, 'ignore_sticky_posts' => 1 ) );
// The Loop
if ( $the_query->have_posts() ) {
$return .= '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
$return .= '<li><a href="' .get_permalink(). '" title="' . get_the_title() . '">' . get_the_title() . '</a><br />' . get_the_excerpt(). '</li>';
}
$return .= '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
return $return;
}
add_shortcode('latest_stickies', 'wpb_latest_sticky');
After adding this code, simply create add the shortcode [latest_stickies]
wherever you want to display your latest sticky posts.
添加此代码后,只需在要显示最新即时贴的位置创建简码[latest_stickies]
。
For detailed instructions, visit our article: 如何在 WordPress 中显示最新的置顶帖子.
有关详细说明,请访问我们的文章: 如何在WordPress中显示最新的便笺 。
4.自定义帖子类型的粘性帖子 (4. Sticky Posts for Custom Post Types)
Sticky post feature is only available for WordPress posts, but this does not mean that you cannot add this feature for other 帖子类型.
粘性帖子功能仅适用于WordPress帖子,但这并不意味着您不能为其他岗位类型添加此功能。
Simply install and activate the 粘性自定义帖子类型 plugin. Once you have activated the plugin, visit 设置 » 阅读 and enable sticky posts for any post type you want.
只需安装并激活粘性自定义帖子类型插件即可。 激活插件后,请访问“设置”»“阅读”,并为所需的任何帖子类型启用即时贴。

For more detailed instructions check out our tutorial on how to add WordPress 自定义帖子类型中的粘性帖子.
有关更详细的说明,请查看我们的教程,了解如何在 WordPress 自定义帖子类型中添加置顶帖 。
5.如何从WordPress Loop中隐藏即时贴 (5. How to Hide Sticky Posts From WordPress Loop)
使用置顶帖子时,您会注意到默认情况下 WordPress 将置顶帖子显示在所有 WordPress 帖子的顶部。例如,如果您有一个循环来显示最近的帖子,那么无论何时添加置顶帖子,它们都会显示在顶部。
使用置顶帖子时,您会注意到 WordPress 默认将您的置顶帖子显示在所有 WordPress 帖子的顶部。例如,如果您有一个显示最近帖子的循环,则每当您添加卡片时,它都会显示在顶部。
To avoid this simply use ignore_sticky_posts
argument in your WordPress query, like this:
为了避免这种情况,只需在WordPress查询中使用ignore_sticky_posts
参数,如下所示:
<?php
$args = array(
'posts_per_page' => 10,
'ignore_sticky_posts' => 1
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
?>
See our tutorial on how to 从 WordPress 循环中排除置顶帖子 for more detailed instructions.
请参阅我们的教程,了解如何从 WordPress 循环中排除置顶帖子,以获取更多详细说明。
6.设置粘性帖子的样式 (6. Styling Sticky Posts)
想要为您的置顶帖子添加自定义样式吗?
想要为您的便签添加自定义样式吗?
Many WordPress themes use post_class()
function to automatically add post classes for each post. If your theme is already using post_class() function, then you will see sticky class added to your sticky posts.
许多WordPress主题使用post_class()
函数自动为每个帖子添加帖子类别。 如果您的主题已经在使用post_class()函数,那么您会看到粘性类已添加到您的粘性帖子中。

如果您的主题没有向帖子容器 div 添加粘性类,那么您可以通过将 post_class() 函数添加到帖子 div 或文章容器中来自行添加。
如果您的主题未将粘性类添加到帖子容器 div,您可以通过将 post_class() 函数添加到帖子 div 或文章容器来自行添加粘性类。
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
Now you can use the .sticky
CSS class in your 儿童主题‘s stylesheet. Here is some basic CSS to get you started:
现在您可以使用了。 副主题的样式表中的sticky
CSS类。 以下是一些基本CSS入门指南:
.sticky {
background-color:#ededed;
border:1 px solid #f5f5f5;
color:#272727;
padding:5px;
}
.sticky:before {
content: "Featured";
color: #FFF;
background: #f20000;
padding: 10px;
display: inline-block;
text-align: right;
float: right;
font-weight: bold;
text-transform: uppercase;
}
这就是我们使用“二十一十二”主题的演示网站上的外观。
这就是我们使用“十二十二”主题的演示网站上的样子。

That’s all, we hope this article helped you learn some cool things to do with sticky posts on your WordPress site. You may also want to check out our guide on 10 most wanted WordPress 的类别黑客和插件.
仅此而已,我们希望本文能帮助您学习一些有趣的事情,这些事情与WordPress网站上的粘帖有关。 您可能还需要查看关于 WordPress 10种最需要黑客和插件的类别指南。
If you liked this article, then please subscribe to our YouTube 频道 for WordPress video tutorials. You can also find us on 推特 and 谷歌+.
如果您喜欢这篇文章,请订阅我们的YouTube 频道 WordPress视频教程。 您也可以在推特和谷歌+上找到我们。
翻译自: https://www.wpbeginner.com/beginners-guide/6-cool-things-you-can-do-with-sticky-posts-in-wordpress/
wordpress相册检查