最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Highlight a Featured Post?

programmeradmin2浏览0评论

I would like to "highlight" a featured post above all other posts with a special indicator.

Is there a feature in WordPress that will do this or do I need to install a third party plug-in?

I am using a custom WordPress install (not WP hosted).

I would like to "highlight" a featured post above all other posts with a special indicator.

Is there a feature in WordPress that will do this or do I need to install a third party plug-in?

I am using a custom WordPress install (not WP hosted).

Share Improve this question edited May 4, 2011 at 19:46 EAMann 32.2k9 gold badges88 silver badges147 bronze badges asked Nov 3, 2010 at 22:46 user1462user1462 1,3043 gold badges17 silver badges23 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 8

Use the "sticky" feature.

In the "Page Attributes" metabox (labelled as Publish), if you click the "edit" link next to the Visibility option, there is a checkbox which allows you to "Stick this post to the front page".

Unless a theme overrides the default query, that post will show up above all the others. In addition, it adds the class name "sticky" to the attributes returned by post_class(), so you can style it however you want.

To add some text to your featured posts and highlight them, add a function like this inside the loop in your index.php (or loop.php, etc., depending on your theme):

if (is_sticky($post->ID)) echo '<span class="featured">Featured!</span>';

You can do the same thing with the css :before property, like this:

div.sticky h2:before {
     content: "Featured! ";
}

(assuming you're using h2's to display the titles of your posts, and you want to add the text before the title)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论