Easy Featured Post for WordPress

Creating a featured post section for your most recent post has quickly become one of the most widely used features for many templates.

The ScatterBrain WordPress Theme uses a featured post section in which the latest post is displayed with a large image which is attached to the post using the “Custom Fields” found when publishing a post. So let’s do a quick run through of the code so we can all understand the process.

Here is the full code for reference that is used in the ScatterBrain WordPress Theme which we will be dissecting:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<div id="latest_post">   
<?php $the_query = new WP_Query('showposts=1');
while ($the_query->have_posts()) : $the_query->the_post();?>
<h3 class="sections">Latest Story</h3>
<div class="postMeta"><span class="date"><?php the_time('m.d.y') ?></span></div>
<?php if ( get_post_meta($post->ID, 'home_image', true) ) { ?>
<div id="latest_post_image">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/latest/<?php echo get_post_meta($post->ID, "home_image", $single = true); ?>" alt="<?php bloginfo('name'); ?>: Latest post" width="470" /></a>
</div>
<?php } ?>
<h3 class="latest_post_title" id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?></a></h3>
<p><?php echo strip_tags(get_the_excerpt(), '<a><strong>'); ?></p>
<div class="latest_post_meta">
<span class="latest_read_on">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/read.gif">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">Continue Reading</a></span>
<span class="latest_comments">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/comment.gif">
<?php comments_popup_link('Post a comment', 'One comment', '% comments', '', 'Comments off');?></span>
<?php $cat = get_the_category(); $cat = $cat[0]; ?>
<span class="latest_category">Category: <a href="<?php echo get_category_link($cat->cat_ID);?>"><?php echo $cat->cat_name; ?></a></span>
</div>
</div>   
<?php endwhile; ?>

Query Your WordPress Posts:

2
3
<?php $the_query = new WP_Query('showposts=1');
while ($the_query->have_posts()) : $the_query->the_post();?>

What the above means:
Hey WordPress, for this section I want to call upon and use 1 post. Luckily for use the “1 post” will always be the latest post across all categories. If you want to show 1 post from a specific category, use (‘showposts=1&cat=11′) where cat= is the category ID of the category you wish to pull from. You can also use category_name= to name a specific category or exclude categories from this query. See the Query Posts Templates Tag WordPress Codex for a full rundown of parameters.

Section Label and Date:

4
5
<h3 class="sections">Latest Story</h3>
<div class="postMeta"><span class="date"><?php the_time('m.d.y') ?></span></div>

What the above means:
Line 4 is labeling the section. Line 5 is pulling the date of the post entry. There are several options for the format of the date and time, review the Formatting Date and Time WordPress Codex for more info.

Looking for the Image:

6
<?php if ( get_post_meta($post->ID, 'home_image', true) ) { ?>

What the above means:
Here we start our “If” statement to look for a custom field named ‘home_image’ which you set when you are writing your post. Custom fields consist of a Key and a Value, in this case our Key is ‘home_image’ and our value is our image name. For every post that is to appear in the featured area you would add a value or image name to the Key of ‘home_image’.

Setting the Image:

7
8
9
10
<div id="latest_post_image">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/latest/<?php echo get_post_meta($post->ID, "home_image", $single = true); ?>" alt="<?php bloginfo('name'); ?>: Latest post" width="470" /></a>
</div>

What the above means:
First we need to make sure to link the image to it’s post, line 8 starts the link wrap for the image as the href= will be linking to the post permalink.

Line 9 may be long but all we are doing is pulling in an image.

The first part of our image source aka img src= is pointing to a directory located within the theme called images/latest. I use this so I can just dump images to the folder via ftp but you can change this to point to your uploads folder and add images via the WordPress built in media gallery.

The second part of the img src= is naming the file in the images/latest folder. So get_post_meta($post->ID, “home_image”, $single = true); is pulling in the value you set in your Custom Field for the key of “home_image”. If your image was called home.jpg the img src from above would essentially be “Your Theme Stylesheet Directory/images/latest/’home_image’” or “Your Theme Stylesheet Directory/images/latest/home.jpg”

Post Title:

12
13
14
<h3 class="latest_post_title" id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?></a></h3>

What the above means:
Again we use the_permalink() to link the title to it’s permalink while the_title() pulls in the title.

Post Title:

15
<p><?php echo strip_tags(get_the_excerpt(), '<a><strong>'); ?></p>

What the above means:
Pull in the excerpt!

Post Title:

16
17
18
19
20
21
22
23
24
25
<div class="latest_post_meta">
<span class="latest_read_on">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/read.gif">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">Continue Reading</a></span>
<span class="latest_comments">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/comment.gif">
<?php comments_popup_link('Post a comment', 'One comment', '% comments', '', 'Comments off');?></span>
<?php $cat = get_the_category(); $cat = $cat[0]; ?>
<span class="latest_category">Category: <a href="<?php echo get_category_link($cat->cat_ID);?>"><?php echo $cat->cat_name; ?></a></span>
</div>

What the above means:
This is the code for the bottom area which contains the Continue Reading Link, Number of Comments and displays what Category the post came from. The first two sections have an image followed by a text link. Each section is wrapped with a span class such as latest_read_on, latest_comments and latest_category.

If all goes well, and with some CSS you will end up with an image, title, excerpt and read more, comment and category:

I tried to keep it short on the areas which were a little more self explanatory but if there’s any questions feel free to ask. Overall line 2 is where the magic happens in which you’re telling WordPress where to look at how many posts to pull for your section. Line 6 is where you tell WordPress to look for your custom Key while line 9 is where you swap your Key for a Value.

100 Beautiful Blog Designs

Looking for some inspiration? The folks over at Hongkiat.com have compiled a list of 100 Beautiful Blog Designs.

The list has all types of designs, from simplistic and clean to colorful vibrant designs.  A great compilation to look over to see what others are doing out there with their Blogs!  So if you have 10-15 minutes(because you will end up clicking through some sites) then make sure you check it out.

First Impressions: Veritocracy

Veritocracy.com

Veritocracy.com

Veritocracy.com – Veritocracy learns to find the best perspectives, on the topics that interest you. To get started, just read and vote on the articles you see.
What is Veritocracy?
”The ultimate objective,” says CEO Lee Hoffman, “is to create a truly meritocratic content distribution system where each article a writer publishes finds its way to the individual readers that will actually want to see it.”

I was able to snag an invite to the closed Beta of Veritocracy through a write up on TechCrunch. The title of the article, Veritocracy = Digg + Techmeme, was interesting enough for me to try to sign up through my phone while walking into a restaurant to get some lunch. Unfortunately due to the AJAX sign up form(along with validation) that appears after you enter the invite code, it renders off screen on a iPhone 3G. With some guessing and hitting the “Done” button I was still able to sign up even though only half the sign up form was able to be seen. No worries, it’s in Beta…besides who registers for a Beta site from a phone…

Once you get your confirmation email and log into the site you are presented with your personal page, in which you see a brief overview of the Top 2 articles for numerous categories.

Veritocracy.com

Veritocracy.com

What’s appealing is that once you begin to start reading articles and rating them, the system will adjust to your preferences and show you articles according to your ranking of articles. Not sure how long it would take for the algorithm to start sending articles tailored to your interests but it will probably take some dedication from the user. Think of the Digg Recommendation engine as a site of it’s own and you’ll have the quick idea of Veritocracy.

In order for the system to send you specific articles you need to rate a number of articles. Luckily if the articles are submitted via the feed feature and show the full story vs the excerpt you are able to view the articles in a lightbox like feature, which is truly convenient as it allows for quick reading and rating.

Veritocracy.com

Veritocracy.com

The appeal of publishers getting their stories to those readers who would be most interested in the topic is promising, but will take a lot of user contribution. The articles you see when you log in are not to be the most popular articles on the site but the most appealing based on your history of rating articles, submitting and commenting.

7AD26797C8A0A66E12273E38A6A33960

ScatterBrain WordPress Theme

The ScatterBrain WordPress Theme is available for download!

ScatterBrain WordPress Theme: Demo
ScatterBrain WordPress Theme: Download

Theme Features:
-Widget Ready Sidebar (with 3 specific areas)
-2 Column (Main/Sidebar)
-Main Page:
Featured Story
Recent Stories
Archive List
-Built In Plugins:
WP-PageNavi
Recent Posts
Recent Comments
-IE6 Friendly

Page 6 of 8« First...5678

Contact

Questions, inquiries or just feel like getting in touch, feel free to do so: