how to create custom popular post widget in WordPress

How to create custom popular post widget in WordPress? OR how to you create custom popular posts widget for my website? It is very easy to create a custom popular posts widget for your own website. It is some simple code that you just copy and paste your website. So, now we go to create custom widget for popular posts.

First open your theme folder and open your function.php / theme-function.php / custom-widget.php file. now copy below code and paste your function.php / theme-function.php / custom-widget.php file. Update your file and go to Widget option you can see here a new widget for custom popular posts widget “Br Theme – Popular Posts”. Now this widget use any where in your widget area.

php code for create custom popular post widget

///POPULAR POST WIDGET

class brtheme_popular_posts extends WP_Widget {
function __construct() {
$widgets_opt = array(‘description’=>’Display popular posts’);
parent::__construct(false,$name= “BR Theme – Popular Posts Widget”,$widgets_opt);
}
function form($instance) {
global $post;
$title = isset( $instance[‘title’] ) ? esc_attr( $instance[‘title’] ) : ”;
$count = isset( $instance[‘count’] ) ? esc_attr( $instance[‘count’] ) : ”;

?>
<p><label for=”<?php echo $this->get_field_id(‘title’); ?>”>Title:
<input id=”<?php echo $this->get_field_id(‘title’); ?>” name=”<?php echo $this->get_field_name(‘title’); ?>” type=”text” class=”widefat” value=”<?php echo $title;?>” /></label></p>

<div style=”float:left; width:99%;”>
<p><label for=”<?php echo $this->get_field_id(‘count’); ?>”>Show Item:
<input id=”<?php echo $this->get_field_id(‘count’); ?>” name=”<?php echo $this->get_field_name(‘count’); ?>” type=”text” class=”widefat” value=”<?php echo $count;?>” /></label></p>
</div>
<?php
}
function update($new_instance, $old_instance) {
return $new_instance;
}
function widget( $args, $instance ) {
global $post;
extract($args);
$title = apply_filters(‘widget_title’, $instance[‘title’]);
$count = apply_filters(‘count’, $instance[‘count’]);

echo $before_widget;
if ( $title )
echo ‘<h2>’. $title. ‘</h2>’;

$cID = get_the_ID();

function BRTheme_popular_posts($post_id) {
$count_key = ‘popular_posts’;
$count = get_post_meta($post_id, $count_key, true);
if ($count == ”) {
$count = 0;
delete_post_meta($post_id, $count_key);
add_post_meta($post_id, $count_key, ‘0’);
} else {
$count++;
update_post_meta($post_id, $count_key, $count);
}
}
function BRTheme_track_posts($post_id) {
if (!is_single()) return;
if (empty($post_id)) {
global $post;
$post_id = $post->ID;
}
BRTheme_popular_posts($post_id);
}
add_action(‘wp_head’, ‘BRTheme_track_posts’);

$popular = new WP_Query(array(‘posts_per_page’=>$count, ‘meta_key’=>’popular_posts’, ‘orderby’=>’meta_value_num’, ‘order’=>’DESC’));;
$i=1;
//query_posts($query);

if (have_posts()) :
echo ‘<div class=”popular-posts-items”>’;
//while (have_posts()) : the_post(); $i++;
while ($popular->have_posts()) : $popular->the_post();;

echo ‘<div class=”popular-post-item”>’;

echo ‘<h5><a href=”‘. get_the_permalink() .'” >’.$i++.’. ‘ .get_the_title().'</a></h5>’;
echo ‘<p>’ .wp_trim_words( get_the_content(”), ’12’, ” ).'</p>’;
echo ‘</div>’;
endwhile;
echo ‘<div class=”clr”></div>’; endif; wp_reset_query();

echo $after_widget;
}
}
add_action(‘widgets_init’, create_function(”, ‘return register_widget(“brtheme_popular_posts”);’));

114 Responses to “how to create custom popular post widget in WordPress”

  1. minecraft says:

    I enjoy what you guys are up too. This sort of clever work and exposure!
    Keep up the very good works guys I’ve added you guys to
    my blogroll.

  2. minecraft says:

    There is definately a great deal to find out about this subject.
    I really like all the points you have made.

  3. minecraft says:

    Hello, I enjoy reading through your article. I like to write a little comment to support you.

  4. minecraft says:

    Hi, I think your site might be having browser compatibility issues.
    When I look at your website in Opera, it looks fine but when opening in Internet Explorer, it
    has some overlapping. I just wanted to give you a quick heads up!
    Other then that, fantastic blog!

  5. minecraft says:

    I am curious to find out what blog platform you have been using?
    I’m having some small security issues with my latest blog and
    I would like to find something more risk-free. Do you have any solutions?

  6. minecraft says:

    Hey! I could have sworn I’ve been to this blog before but after
    checking through some of the post I realized it’s new to me.
    Nonetheless, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

  7. minecraft says:

    This is my first time visit at here and i am in fact
    pleassant to read everthing at single place.

  8. minecraft says:

    I pay a quick visit daily a few blogs and blogs to read articles, but this blog presents
    quality based writing.

  9. minecraft says:

    I have read so many articles or reviews about the blogger lovers but
    this article is in fact a pleasant piece of writing,
    keep it up.

  10. minecraft says:

    Wow, that’s what I was exploring for, what a information! present here
    at this website, thanks admin of this web page.

  11. Hey there are using WordPress for your site platform? I’m new
    to the blog world but I’m trying to get started and set up
    my own. Do you need any html coding expertise to make your own blog?
    Any help would be greatly appreciated!

  12. It’s a shame you don’t have a donate button! I’d most certainly donate to this superb
    blog! I guess for now i’ll settle for book-marking and adding your RSS feed to my Google account.
    I look forward to fresh updates and will talk about
    this blog with my Facebook group. Talk soon!

  13. Terrific work! This is the type of info that are supposed to
    be shared around the internet. Disgrace on Google for not positioning
    this post higher! Come on over and seek advice from my site .
    Thanks =)

  14. Its like you read my mind! You seem to know so much about this, like you
    wrote the book in it or something. I think that you can do with some pics to
    drive the message home a little bit, but instead of that,
    this is magnificent blog. A fantastic read.
    I will certainly be back.

  15. If you want to grow your experience only keep visiting this website and be
    updated with the most recent gossip posted
    here.

  16. Heya i am for the first time here. I came across
    this board and I to find It truly useful & it helped me out a lot.
    I am hoping to give one thing back and aid others such
    as you helped me.

  17. Hey there! I simply wish to offer you a huge thumbs up for
    the excellent info you have got here on this post. I’ll be coming back to your
    blog for more soon.

  18. I was suggested this blog by my cousin. I’m not sure whether this post is written by him
    as no one else know such detailed about my trouble.
    You are amazing! Thanks!

  19. Hello, I enjoy reading all of your article. I wanted to write a little comment to support you.

  20. Everything is very open with a very clear explanation of the challenges.
    It was definitely informative. Your site is useful.
    Thank you for sharing!

  21. Write more, thats all I have to say. Literally, it seems as though
    you relied on the video to make your point.
    You definitely know what youre talking about, why waste your
    intelligence on just posting videos to your weblog when you could be giving us
    something informative to read?

  22. I’ve read several good stuff here. Definitely worth bookmarking for revisiting.
    I wonder how so much effort you put to create such a excellent informative web
    site.

  23. Hi! Quick question that’s entirely off topic. Do you know how to make your site mobile friendly?
    My web site looks weird when viewing from my iphone 4.
    I’m trying to find a theme or plugin that might be able
    to fix this problem. If you have any suggestions,
    please share. Thanks!

  24. I was recommended this blog by my cousin. I’m not sure whether this post is written by
    him as nobody else know such detailed about my difficulty.
    You are incredible! Thanks!

  25. Hey! Do you use Twitter? I’d like to follow you if that
    would be ok. I’m undoubtedly enjoying your blog and look forward to new posts.

  26. I always emailed this web site post page to all my associates, for the reason that if
    like to read it after that my links will too.

  27. Thanks for sharing your info. I really appreciate your efforts
    and I will be waiting for your next post thanks once again.

  28. Excellent post. I used to be checking constantly this weblog and I’m inspired!
    Extremely helpful info specifically the remaining section 🙂
    I handle such information much. I used to be seeking
    this particular information for a long time. Thank you and good luck.

  29. Coconut Oil says:

    I all the time used to study paragraph in news papers but now
    as I am a user of net so from now I am using net for articles, thanks to web.

  30. I do believe all of the concepts you’ve offered
    on your post. They are very convincing and can definitely work.
    Still, the posts are too brief for starters. May you please extend them a little from
    subsequent time? Thanks for the post.

  31. you’re truly a just right webmaster. The web site loading
    speed is incredible. It kind of feels that you are doing any distinctive trick.
    Also, The contents are masterpiece. you’ve performed a wonderful task
    in this subject!

  32. The other day, while I was at work, my cousin stole my iphone and tested to
    see if it can survive a 40 foot drop, just so she can be a youtube sensation.
    My iPad is now broken and she has 83 views. I know this is entirely off topic but I had to share it with someone!

  33. Quest bars cheap fitnesstipsnew1 quest bars cheap 516999410492780544 quest bars cheap
    Somebody necessarily help to make critically articles
    I might state. This is the very first time I
    frequented your website page and so far? I surprised with
    the research you made to create this particular post extraordinary.

    Great task! Quest bars cheap fitnesstipsnew1 quest bars cheap 516999410492780544 quest bars cheap

  34. I and also my pals have already been taking note of the nice helpful hints from your web page then suddenly got an awful feeling I never thanked you for those secrets. All of the guys became so glad to learn all of them and already have in fact been making the most of those things. I appreciate you for being really accommodating and also for finding this form of quality useful guides millions of individuals are really desirous to learn about. My personal honest apologies for not expressing appreciation to sooner.

  35. My developer is trying to persuade me to move to .net from PHP.
    I have always disliked the idea because of the costs. But
    he’s tryiong none the less. I’ve been using WordPress on various websites for about a year
    and am worried about switching to another platform.
    I have heard very good things about blogengine.net.
    Is there a way I can import all my wordpress content into it?
    Any kind of help would be greatly appreciated!

  36. I really wanted to write down a quick message to be able to thank you for these great advice you are sharing on this site. My time intensive internet research has at the end been recognized with useful facts and techniques to go over with my co-workers. I ‘d assume that we readers actually are definitely blessed to be in a very good site with many awesome people with good techniques. I feel truly privileged to have discovered the webpages and look forward to plenty of more exciting times reading here. Thanks a lot once more for all the details.

  37. adidas nmd says:

    I truly wanted to write a small word so as to say thanks to you for the precious techniques you are placing at this site. My long internet investigation has now been rewarded with excellent strategies to go over with my friends and family. I ‘d express that many of us readers are quite fortunate to dwell in a very good community with many awesome individuals with helpful techniques. I feel really fortunate to have discovered your website page and look forward to tons of more cool times reading here. Thanks again for all the details.

  38. I precisely needed to say thanks again. I am not sure what I could possibly have tried in the absence of the creative ideas revealed by you over such situation. Certainly was an absolute terrifying scenario in my circumstances, nevertheless finding out your skilled way you managed the issue forced me to jump with fulfillment. I am grateful for your service and thus sincerely hope you are aware of a powerful job you’re providing teaching the rest all through your blog. More than likely you’ve never got to know any of us.

  39. When someone writes an post he/she keeps the image
    of a user in his/her mind that how a user can be aware of it.
    Therefore that’s why this piece of writing is outstdanding.
    Thanks!

  40. I have to point out my gratitude for your kind-heartedness in support of individuals who require help with in this field. Your real commitment to passing the message across appears to be extremely powerful and have really allowed employees just like me to get to their desired goals. Your own interesting guide means a great deal a person like me and somewhat more to my fellow workers. Thanks a ton; from each one of us.

  41. Sling TV says:

    I simply couldn’t leave your website prior to suggesting that I extremely enjoyed the standard info an individual supply on your guests?
    Is gonna be again regularly in order to check up on new posts

  42. Sling TV says:

    First off I want to say wonderful blog! I had a quick question in which I’d like to ask if you do not
    mind. I was interested to know how you center yourself and clear
    your head prior to writing. I have had a difficult time
    clearing my mind in getting my ideas out there.
    I truly do enjoy writing but it just seems like the first 10 to 15 minutes tend to be wasted just trying to figure out how to begin. Any suggestions
    or tips? Thank you!

  43. I wanted to compose a quick comment so as to thank you for some of the unique tips you are giving on this website. My time intensive internet lookup has finally been recognized with useful points to go over with my visitors. I ‘d tell you that many of us visitors actually are truly lucky to exist in a fantastic network with very many marvellous individuals with beneficial suggestions. I feel pretty privileged to have come across your webpages and look forward to really more brilliant minutes reading here. Thanks once more for a lot of things.

  44. Admiring the hard work you put into your website and detailed information you offer.

    It’s awesome to come across a blog every once
    in a while that isn’t the same out of date rehashed material.
    Great read! I’ve saved your site and I’m adding your RSS feeds to my Google account.

  45. Hello, Neat post. There is an issue with your web site in web
    explorer, could test this? IE still is the market leader and a large portion of other
    folks will pass over your wonderful writing due to this problem.

  46. My wife and i felt so delighted that Albert could deal with his investigation using the precious recommendations he got from your web pages. It is now and again perplexing just to continually be handing out strategies others might have been trying to sell. We fully understand we have got the website owner to appreciate for that. All the explanations you made, the easy site menu, the relationships you can aid to engender – it’s got all fantastic, and it is aiding our son and our family recognize that this concept is fun, and that is particularly pressing. Thank you for the whole thing!

  47. Ahaa, its pleasant conversation on the topic of this
    article at this place at this weblog, I have read all that, so at this time me also commenting here.

  48. I happen to be writing to let you be aware of of the excellent discovery my princess enjoyed studying your blog. She noticed numerous pieces, most notably what it’s like to possess a great helping spirit to get the others clearly fully understand specific extremely tough subject matter. You actually did more than my desires. Many thanks for supplying the beneficial, trusted, edifying and unique tips on the topic to Sandra.

  49. It’s awesome in favor of me to have a website, which is helpful for my know-how.
    thanks admin

  50. I am also commenting to make you be aware of what a useful experience my friend’s daughter found going through yuor web blog. She discovered such a lot of issues, including what it is like to possess a marvelous giving spirit to make a number of people very easily fully grasp chosen specialized matters. You really surpassed my expectations. Many thanks for supplying the productive, trustworthy, edifying not to mention fun tips about that topic to Lizeth.

  51. I constantly spent my half an hour to read this blog’s articles or
    reviews daily along with a cup of coffee.

  52. Hi, Neat post. There’s an issue along with your site in internet explorer, might test this?

    IE still is the marketplace leader and a large part of folks will omit
    your magnificent writing due to this problem.

  53. My husband and i ended up being really relieved Ervin managed to complete his homework through the entire ideas he discovered from your very own web site. It’s not at all simplistic to just choose to be handing out concepts a number of people may have been making money from. And now we fully grasp we now have the writer to thank for that. All of the explanations you’ve made, the easy website menu, the relationships your site give support to promote – it’s got everything unbelievable, and it’s really letting our son and the family reckon that the matter is thrilling, which is certainly exceptionally important. Thank you for the whole thing!

  54. you are in point of fact a excellent webmaster. The site loading velocity
    is incredible. It sort of feels that you are doing any unique
    trick. Moreover, The contents are masterpiece. you have performed
    a fantastic process in this topic!

  55. reebok shoes says:

    I and also my buddies were found to be following the great techniques on your website and then then came up with a horrible feeling I had not expressed respect to the website owner for them. All of the young boys are already absolutely very interested to learn them and have in effect in truth been tapping into these things. Appreciation for truly being considerably accommodating and then for deciding on these kinds of quality themes most people are really eager to understand about. Our honest regret for not saying thanks to sooner.

  56. I precisely had to say thanks once again. I’m not certain the things I would’ve used in the absence of these smart ideas shared by you about my problem. It had been a very alarming concern for me personally, but finding out the skilled manner you handled it made me to cry over happiness. I am grateful for this help as well as hope you find out what a great job that you are carrying out educating people today all through a site. Probably you’ve never encountered any of us.

  57. Thank you a lot for providing individuals with an extraordinarily nice chance to read critical reviews from this web site. It’s usually very fantastic and as well , packed with a lot of fun for me personally and my office acquaintances to search your website nearly three times weekly to see the newest things you have. Not to mention, I am just actually fascinated concerning the fabulous suggestions served by you. Certain 3 facts on this page are undoubtedly the most beneficial we’ve ever had.

  58. I simply wanted to post a quick note to thank you for some of the magnificent facts you are writing on this website. My rather long internet look up has now been recognized with reliable facts and strategies to exchange with my colleagues. I would declare that many of us site visitors are very blessed to live in a magnificent network with very many perfect people with insightful tricks. I feel pretty fortunate to have seen the web site and look forward to tons of more brilliant moments reading here. Thanks a lot once more for everything.

  59. I actually wanted to type a comment to appreciate you for some of the pleasant techniques you are showing on this website. My extensive internet investigation has at the end of the day been compensated with reputable facts and techniques to talk about with my close friends. I ‘d point out that we readers actually are really endowed to be in a superb community with so many brilliant individuals with useful advice. I feel somewhat lucky to have come across your entire site and look forward to so many more awesome moments reading here. Thanks a lot again for all the details.

  60. nike flyknit says:

    Thanks so much for giving everyone remarkably marvellous opportunity to check tips from here. It is usually very pleasurable and also full of fun for me personally and my office acquaintances to visit your web site more than three times in 7 days to study the latest guides you will have. And lastly, I am also usually fascinated for the spectacular ideas you give. Some 1 facts in this article are absolutely the simplest I have ever had.

  61. yeezy boost says:

    I would like to express some thanks to you just for rescuing me from this incident. Just after searching throughout the the web and getting recommendations that were not powerful, I believed my entire life was gone. Being alive devoid of the approaches to the problems you have sorted out as a result of this post is a crucial case, and those that could have in a wrong way affected my entire career if I had not encountered your web page. Your training and kindness in maneuvering a lot of stuff was very helpful. I don’t know what I would’ve done if I hadn’t come across such a step like this. I can also at this time relish my future. Thanks a lot so much for this professional and sensible guide. I won’t hesitate to endorse the website to anybody who needs and wants recommendations on this topic.

  62. I simply desired to appreciate you all over again. I’m not certain what I would’ve implemented without the creative ideas revealed by you relating to my area. It had become an absolute traumatic condition in my view, however , finding out this expert way you handled the issue forced me to leap for joy. Now i’m thankful for this work and as well , hope you know what an amazing job you were doing teaching men and women by way of your websites. Most probably you haven’t met any of us.

  63. foamposites says:

    I wanted to write down a brief note so as to say thanks to you for all of the wonderful tips and tricks you are writing at this website. My considerable internet lookup has at the end of the day been compensated with extremely good tips to write about with my two friends. I ‘d say that we readers are rather endowed to be in a notable network with many marvellous people with great tips. I feel truly happy to have seen your web site and look forward to many more awesome minutes reading here. Thanks a lot once again for everything.

  64. I just wanted to compose a note in order to thank you for the awesome secrets you are giving on this site. My long internet investigation has at the end been compensated with beneficial knowledge to exchange with my family. I would declare that most of us website visitors actually are really endowed to be in a really good network with so many special individuals with very helpful tips and hints. I feel truly happy to have seen the site and look forward to many more fun minutes reading here. Thanks a lot once more for a lot of things.

  65. I must convey my admiration for your kind-heartedness in support of men and women who need help with this one content. Your real commitment to passing the message all over appeared to be exceptionally powerful and has frequently helped regular people much like me to reach their pursuits. This warm and helpful key points can mean this much to me and even more to my colleagues. Best wishes; from each one of us.

  66. yeezy boost says:

    I precisely wanted to say thanks all over again. I am not sure the things that I would have done in the absence of the entire tips shared by you concerning my problem. It was actually a very difficult circumstance for me personally, nevertheless observing the very skilled approach you handled it made me to weep with delight. I’m just grateful for your guidance and as well , expect you realize what a powerful job you are always undertaking training some other people through the use of your web page. Most probably you haven’t come across all of us.

  67. nike shoes says:

    I would like to convey my passion for your kindness in support of persons who require help on this concept. Your special dedication to getting the message all over turned out to be unbelievably beneficial and has continually helped people much like me to reach their ambitions. Your new helpful help entails a great deal a person like me and far more to my mates. With thanks; from each one of us.

  68. I precisely needed to thank you so much all over again. I do not know the things I could possibly have undertaken without these ideas shared by you on this subject. It truly was a horrifying situation for me personally, nevertheless seeing a new skilled strategy you solved that made me to weep for happiness. I’m just happier for the help and then trust you realize what a powerful job that you are doing training many people via your webblog. Most likely you haven’t encountered any of us.

  69. I happen to be writing to make you know what a fine experience my cousin’s princess undergone going through the blog. She learned plenty of details, which include how it is like to have an incredible giving spirit to let other folks very easily gain knowledge of specific advanced subject areas. You actually surpassed visitors’ expected results. Many thanks for imparting the important, healthy, informative and even fun guidance on this topic to Jane.

​Leave a Comment

Comment authors age:




how to create custom category widget in wordpress?

Some of Home Based Business Idea