{"id":706,"date":"2012-09-29T19:15:02","date_gmt":"2012-09-29T19:15:02","guid":{"rendered":"http:\/\/faq.pctrickers.com\/?p=706"},"modified":"2023-03-27T15:16:42","modified_gmt":"2023-03-27T15:16:42","slug":"wordpress-get-popular-posts-without-any-plugins","status":"publish","type":"post","link":"https:\/\/webexplorar.com\/wordpress-get-popular-posts-without-any-plugins\/","title":{"rendered":"WordPress get popular posts without any plugins"},"content":{"rendered":"<p>How can I get most <strong>popular posts<\/strong> without using any plugins in <strong>WordPress<\/strong>.I this post will describes how to <strong>get most popular posts without any plugins<\/strong>.<br \/>\n<!--more--><\/p>\n<h2>Method-1<\/h2>\n<h3><strong>Create a custom WordPress Query to get popular posts by limiting 10.<\/strong><\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;ul class=\"popular-posts\"&gt;\r\n    &lt;?php\r\n        $popular_posts_list = new WP_Query('orderby=comment_count&amp;posts_per_page=10');\r\n        while ($popular_posts_list-&gt;have_posts()) {\r\n        $popular_posts_list-&gt;the_post();\r\n    ?&gt;\r\n    &lt;li&gt;\r\n    &lt;?php\r\n    \t  if ( has_post_thumbnail() ) { \/\/ check if the post has a post thumbnail.\r\n    ?&gt;\r\n            &lt;a href=\"&lt;?php the_permalink(); ?&gt;\" title=\"&lt;?php the_title(); ?&gt;\"&gt;\r\n                &lt;?php the_post_thumbnail('thumb', array('alt' =&gt; ''.get_the_title().'', 'title' =&gt; ''.get_the_title().'')); ?&gt;\r\n            &lt;\/a&gt;\r\n            &lt;a class=\"popular-post-title\" href=\"&lt;?php the_permalink(); ?&gt;\" title=\"&lt;?php the_title(); ?&gt;\"&gt;&lt;?php the_title(); ?&gt;&lt;\/a&gt;\r\n    &lt;?php\r\n          } \/\/ end if\r\n           else {\r\n    ?&gt; \t\t&lt;a class=\"popular-post-title\" href=\"&lt;?php the_permalink(); ?&gt;\" title=\"&lt;?php the_title(); ?&gt;\"&gt;&lt;?php the_title(); ?&gt;&lt;\/a&gt;\r\n    &lt;?php\r\n     \t  } \/\/ end else\r\n    ?&gt;\r\n     &lt;\/li&gt;\r\n     &lt;?php\r\n        } \/\/ end while\r\n     ?&gt;\r\n&lt;\/ul&gt;\r\n\r\n$popular_posts_list = new WP_Query('orderby=comment_count&amp;posts_per_page=10'); \r\nwhile ($popular_posts_list-&gt;have_posts()) { \r\n  $popular_posts_list-&gt;the_post(); \r\n}\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Note<\/strong><br \/>\nMay be you have to displayed an error as following.<\/p>\n<p><strong>Fatal error: Call to undefined function: has_post_thumbnail() in &#8230;yourpage.php on line 32<\/strong><\/p>\n<p>So your theme has to call <code>add_theme_support('post-thumbnails');<\/code> in an <code>after_setup_theme action<\/code>.<br \/>\nOtherwise the post-thumbnail functions aren&#8217;t included.<br \/>\n1-Go to <strong>\/wp-content\/themes\/yourTheme<\/strong> folder.<br \/>\n2-Open the <strong>functions.php<\/strong> file.<br \/>\n3-Add <code>add_theme_support('post-thumbnails');<\/code> at the end of the page or anywhere and save the file.<br \/>\n4-Reload your site.<\/p>\n<h2>Method-2<\/h2>\n<p><strong>Simply executes the mysql query and get results.<\/strong><br \/>\nThat&#8217;s only!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How can I get most popular posts without using any plugins in WordPress.I this post will describes how to get most popular posts without any plugins.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,120],"tags":[],"class_list":["post-706","post","type-post","status-publish","format-standard","hentry","category-recent-posts","category-wordpress","post--single"],"aioseo_notices":[],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/webexplorar.com\/wp-json\/wp\/v2\/posts\/706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webexplorar.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webexplorar.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webexplorar.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webexplorar.com\/wp-json\/wp\/v2\/comments?post=706"}],"version-history":[{"count":1,"href":"https:\/\/webexplorar.com\/wp-json\/wp\/v2\/posts\/706\/revisions"}],"predecessor-version":[{"id":3730,"href":"https:\/\/webexplorar.com\/wp-json\/wp\/v2\/posts\/706\/revisions\/3730"}],"wp:attachment":[{"href":"https:\/\/webexplorar.com\/wp-json\/wp\/v2\/media?parent=706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webexplorar.com\/wp-json\/wp\/v2\/categories?post=706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webexplorar.com\/wp-json\/wp\/v2\/tags?post=706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}