840 VIEWS

WordPress Tricks #1: display custom featured posts on your blog

October 22, 2014

 wordpress logo 640x240

 
Featured Post or Featured Content has been widely used by many popular sites on the web. This is because featured post allows webmasters to highlight their unique contents and attract reader’s attention. Featured post is usually supposed to be displayed on the front page of a blog, as shown below.
 
featured post
 

There are various ways to display a featured post on your WordPress site. You can use a special WordPress theme that supports the featured post; you also can install plugins such as Jetpack.

However, using an existing design or theme can make you site look tacky. If you want your site look special, then creating a customized theme on your own can make your site stand out from the crowd by its unique design.

What I am recommending here is to show you how to create a featured post on your customized blog without any plugins.

Before we dive into it, you should understand WordPress loop. The Loop is simply a block of PHP code that handles each post to be displayed on the present page.

The default WordPress loop normally looks something like this:


<?php // The WordPress Loop
if (have_posts()) : while (have_posts()) : the_post();
//post content here
...
endwhile; else:
...
endif;
?>

To display a featured post in your WordPress customized theme, you need to have multiple loops or at least two loops. To achieve this, WP_Query is the way to go. For example:

// Loop 1

<?php $first_query = new WP_Query(); 
while($first_query->have_posts()) : $first_query->the_post(); ?>
        <?php the_excerpt() ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>//reset the query

<?php  // Loop 2

$second_query = new WP_Query(); ?>
    <?php while($second_query->have_posts()) : $second_query->the_post(); ?>
        <?php the_excerpt() ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>//reset the query
Yonge Chen

BY

Web Developer/Digital Marketer

As a Web Developer,  I plan, create and code web pages, applying both non-technical and technical skills to produce web applications that meet the customer's requirements.

As a digital marketing specialist, I am well versed in SEO, SEM, inbound marketing, content, social media, and heavily get involved with all sides of online marketing to help clients generate opportunities, drive sales, and build brand.

get our free ebook

free ebook download

conversion rate optimization

the way to increase your online sales!

download now

Download Free E-book

Conversion Rate Optimization – The Way to Increase Your Online Sales


Sign up to get instant access to my ultimate guide to successful Conversion Rate Optimization and keep updated on our actionable tips plus exclusive deals!