Php Flow » Php

How To Create Featured Post/Product In WordPress

I want to add a featured product at the top of index wordpress page. Basically it will have an image and title of posts. There are a lot of plugin available for featured product but those are not fulfill my requirement.
So today I am trying to create custom featured product based on category name and number of product parameters.
I have done too much goggling but did not found satisfying answer, so below I am describing how to create featured product in simple steps.

featured_product_in_wordpress

Simple step to create featured product in wordpress.

Step 1: First We will create a category in wordpres name is ‘Featured Product’.
Step 2: Create CSS class for featured div.
Step 3: Now we will paste below code in index.php file Or where you want to display featured product:

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
28
29
30
31
32
33
34
35
36
37
38
39
<div class='featured-container'>
<div class='featured-item-title'>Featured Product</div>
<?php $postslist = get_posts('numberposts=10&order=DESC&category_name=Featured'); foreach ($postslist as $post) : setup_postdata($post);
?>
<div class="recent-posts-item">
<div class='img-thumbnail'><a href="<?php the_permalink(); ?>">
<?php
if(has_post_thumbnail()) {
the_post_thumbnail('thumbnail', array('class' => 'featured-thumb'));
} else {
echo '<img class="featured-thumb" src="http://phpflow/image_not_available.png"
alt="<?php the_title(); ?>" class="footer-thumb"  width="150px" height="150px"  />';

}
?>
</a></div>
<div class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
</div>
<?php endforeach; ?>

</div>

Step 4: Result:
featured product

Did you enjoy this article? Share it!

About the Author:

Hi, This is Parvez Alam from India. I am software developer with 4 years’ experience in web development. I have submitted articles on PHP, Mysql, Magento,CSS, HTML, jQuery, web designing and social API. You can subscribe to my blog via RSS/Twitter/Google plus and Facebook.

Random Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>