wordpress相册查件_您可以使用WordPress中的便利贴做的6件事

wordpress相册查件

Did you know that WordPress allows you to feature your posts by using sticky posts 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件事。

Sticky Post Tricks
影片教学 (Video Tutorial)

演示地址

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

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

1.自动过期即时贴 (1. Automatically Expire Sticky Posts)

If you are using sticky posts to highlight a special event or coupon, then you will need to unstick the post once that event is over.

如果您使用粘性帖子突出显示特殊事件或优惠券,则该事件结束后,您将需要取消粘贴该帖子。

This sounds like unnecessary work that you should automate.

这听起来像您应该自动化的不必要的工作。

Simply install and activate the Expire Sticky Posts plugin. Upon activation, you can set expiry date for sticky posts.

只需安装并激活Expire Sticky Posts插件即可。 激活后,您可以为即时贴设置过期日期。

Setting expiration date for sticky post

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 expiration date for sticky posts in WordPress.

有效期过后,您的粘性帖子将自动变为普通帖子。 有关详细说明,请看一下我们的教程(带视频),该教程如何设置WordPress中粘性帖子的过期日期

2.类别的便利贴 (2. Sticky Posts for Categories)

By default, sticky posts only appear on the front-page of your site. But what if you wanted to display featured content on your category archive pages?

默认情况下,粘性帖子仅显示在网站的首页上。 但是,如果您想在类别存档页面上显示特色内容怎么办?

You can do that by installing and activating the Category Sticky Post plugin. Upon activation, edit a post that you want to feature and select the sticky post category.

您可以通过安装并激活Category Sticky Post插件来做到这一点。 激活后,编辑要突出显示的帖子,然后选择即时贴类别。

Adding a sticky post to specific category

For more detailed instructions, see our tutorial on how to add sticky posts for categories in WordPress.

有关更多详细说明,请参阅有关如何在WordPress中为类别添加粘性帖子的教程。

3.显示最新的即时贴 (3. Display Latest Sticky Posts)

Typically sticky posts are used for featured posts to display your most prominent content. But after a while your old featured posts disappear under the archives. You can bring back your old featured content to life by showing them on custom archives page or anywhere else on your site.

通常,粘性帖子用于特色帖子,以显示您最突出的内容。 但是过了一会儿,您以前的精选帖子在档案库中消失了。 您可以通过在自定义档案页或网站上的其他任何地方显示旧的特色内容,使它们恢复生气。

Simply paste this code in your theme’s functions.php file or a site-specific WordPress plugin.

只需将此代码粘贴到主题的functions.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: How to display latest sticky posts in 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 post types.

粘性帖子功能仅适用于WordPress帖子,但这并不意味着您不能为其他帖子类型添加此功能。

Simply install and activate the Sticky Custom Post Types plugin. Once you have activated the plugin, visit Settings » Reading and enable sticky posts for any post type you want.

只需安装并激活Sticky Custom Post Types插件即可。 激活插件后,请访问“设置”»“阅读”,并为所需的任何帖子类型启用即时贴。

Sticky Post on a custom post type

For more detailed instructions check out our tutorial on how to add sticky posts in WordPress custom post types.


有关更详细的说明,请查看我们的教程,了解如何在WordPress自定义帖子类型中添加粘性帖子

5.如何从WordPress Loop中隐藏即时贴 (5. How to Hide Sticky Posts From WordPress Loop)

When using sticky posts, you will notice that by default WordPress displays your sticky post at the top of all your WordPress posts. For example, if you have a loop to show recent posts, then sticky posts will appear on the top no matter when they were added.

使用粘性帖子时,您会注意到默认情况下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 exclude sticky posts from WordPress loop for more detailed instructions.

请参阅我们的教程,了解如何从WordPress循环中排除粘性帖子,以获取更多详细说明。

6.设置粘性帖子的样式 (6. Styling Sticky Posts)

Want to add custom styling to your 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()函数,那么您会看到粘性类已添加到您的粘性帖子中。

Sticky class added to post container

If your theme is not adding sticky class to the post container div, then you can add that yourself by adding post_class() function into the post div or article container.

如果您的主题不是将粘性类添加到post容器div中,则可以通过将post_class()函数添加到post div或article容器中来自己添加粘性类。


<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

Now you can use the .sticky CSS class in your child theme‘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;
}

This is how it looked on our demo site using Twenty Twelve theme.

这就是使用“十二十二”主题在我们的演示站点上的外观。

Styling a sticky post in WordPress

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 category hacks and plugins for WordPress.

仅此而已,我们希望本文能帮助您学习一些有趣的事情,这些事情与WordPress网站上的粘帖有关。 您可能还需要查看有关WordPress的 10种最需要分类的黑客和插件的指南。

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

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

翻译自: https://www.wpbeginner.com/beginners-guide/6-cool-things-you-can-do-with-sticky-posts-in-wordpress/

wordpress相册查件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值