Thord Daniel Hedengren - Smashing WordPress_ Beyond the Blog-Wiley (2014)

(avery) #1

140 PART II • Designing and Developing WordPress Themes


Another obvious usage is for announcements. If you’re selling e-books, for example, you can
stick a “Hey you! You should buy my spanking new book; I have to pay the rent after all!” post
up on top, or you could just pin a typical Lorem Ipsum post as shown in Figure 6-1 — whatever
you find works for you. More traditional announcements such as new site launches or a call to
action for an important cause would also work well, as would breaking news.

Figure 6-1: This sticky post really isn't helping, but at least it stands out, right?

Finally, you can go a step further by using the is_sticky() conditional tag. You can query
WordPress (using a loop and pre_get_posts to get the desired effect) for your sticky posts
and manage them separately. One idea is to have a headline area outside the normal loop and
just include a set number of sticky posts in it, excluding everything else. In fact, you can use
sticky posts to manage a full headline, but the same effect can be achieved with either custom
fields or a specific tag, for example, and because the sticky post check box is more or less
hidden away, the former may be a better call.

USING CUSTOM FIELDS


Custom fields are database fields with content defined entirely by the user and are often used
within the loop. You’ll find the Custom Fields box on the Add New Post screen within the
WordPress admin; however, you might have to enable it using the Screen Options feature on
the top right and then checking the box for Custom Fields. The Custom Fields box lets you
add one or several custom fields and a value for each (see Figure 6-2).
Free download pdf