{"id":74,"date":"2005-09-22T11:21:23","date_gmt":"2005-09-22T01:21:23","guid":{"rendered":"http:\/\/www.thunderguy.com\/semicolon\/?p=74"},"modified":"2005-09-22T11:22:18","modified_gmt":"2005-09-22T01:22:18","slug":"popularity-contest-for-pages","status":"publish","type":"post","link":"https:\/\/thunderguy.com\/semicolon\/2005\/09\/22\/popularity-contest-for-pages\/","title":{"rendered":"Popularity Contest for Pages"},"content":{"rendered":"<p>I&#8217;ve been enjoying Alex King&#8217;s excellent <a href=\"http:\/\/www.alexking.org\/blog\/2005\/07\/27\/popularity-contest-11\/\">Popularity Contest<\/a> plugin for several weeks now. It&#8217;s fascinating to see which posts are being viewed, commented, tracked and pinged, all through the one interface. After using it for a while, I thought of a useful way to extend it and also found and fixed a wee problem. Perhaps these changes will make their way into the next version of Alex&#8217;s plugin, but till then you can always download my version from here.<\/p>\n<h2>Count Pages<\/h2>\n<p>The first extension was to include WordPress Pages as well as Posts in the statistics. Some people don&#8217;t use Pages at all, but I use them a lot on Semicolon; in particular, I use them for my WordPress plugin homepages, which are some of the most popular pages on the site. I wanted them to be included in the popularity contest, so I made the following changes to Popularity Contest:<\/p>\n<p>To make sure Page views are tracked, I changed <code> if (is_single()) <\/code> to <code> if (is_single() || is_page()) <\/code> in the tracking code. Nice and easy.<\/p>\n<p>To make Pages appear in the reports, I changed the SQL code in various places from <code> post_status = 'publish' <\/code> to <code> post_status IN ('publish','static')<\/code>. This includes Pages, which always have status set to &#8216;static&#8217;. I didn&#8217;t change this everywhere, because some reports should not have Pages included &#8212; Pages do not fall within the normal chronology of Posts, so should not appear in date-based reports.<\/p>\n<h2>Conflict with other plugins<\/h2>\n<p>A couple of weeks after I installed Popularity Contest, it suddenly stopped working &#8212; the statistics were no longer being updated. I eventually figured out that Popularity Contest is incompatible with the <a href=\"http:\/\/www.arnebrachhold.de\/2005\/06\/05\/google-sitemaps-generator-v2-final\">Google Sitemaps<\/a> plugin, which I installed at that time. The Google Sitemaps code includes a WordPress admin include file for some of its function. Unfortunately, Popularity Contest checks for the existence of an admin function to decide whether a view is coming from an admin page. Therefore, with Google Sitemaps enabled, Popularity Contest always thinks it&#8217;s on an admin page and therefore never updates its stats.<\/p>\n<p>The fix is simple; delete Popularity Contest&#8217;s <code> is_admin_page() <\/code> function and use WordPress&#8217;s built-in <code> is_admin() <\/code> function instead. This function effectively checks whether the URL contains &#8220;wp-admin\/&#8221;, which as Alex <a href=\"http:\/\/www.alexking.org\/blog\/2005\/05\/25\/is_admin_page-for-wordpress\/\">says<\/a> is not the best idea:<\/p>\n<blockquote cite=\"http:\/\/www.alexking.org\/blog\/2005\/05\/25\/is_admin_page-for-wordpress\/\"><p>Initially, I just did a check in the URL for wp-admin, but that\u00e2\u20ac\u2122s really not a good solution. I had an IM chat with Dougal and he first suggested checking for get_bloginfo(&#8216;wp_uri&#8217;).&#8217;\/wp-admin\/&#8217;, but we decided that sub-domains could be problematic there. Then he suggested checking of the existence of a function from admin-functions.php. This seems like the best idea to date and it will be in the next release of the plugin.<\/p><\/blockquote>\n<p>The problem with this approach is shown up by the Google Sitemaps conflict &#8212; there&#8217;s nothing to stop another plugin from including admin-functions.php, which will break the admin page detection. I feel it&#8217;s best to use the built-in WordPress function &#8212; it&#8217;s less likely to cause obscure incompatibilities, simply because it&#8217;s in the WordPress core.<\/p>\n<h2>Download<\/h2>\n<p>Finally, my version of Popularity contest switches off the default popularity display per post. I like it like that.<\/p>\n<p>Download the tweaked version of <a href=\"\/semicolon\/wp\/wp-content\/plaintext\/popularity-contest.php\">popularity-contest.php<\/a>. To install, just copy it over your existing version. My modifications to popularity-contest.php are in the public domain. Share and enjoy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been enjoying Alex King&#8217;s excellent Popularity Contest plugin for several weeks now. It&#8217;s fascinating to see which posts are being viewed, commented, tracked and pinged, all through the one interface. After using it for a while, I thought of a useful way to extend it and also found and fixed a wee problem. Perhaps [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[83],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/comments?post=74"}],"version-history":[{"count":0,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/posts\/74\/revisions"}],"wp:attachment":[{"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/media?parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/categories?post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thunderguy.com\/semicolon\/wp-json\/wp\/v2\/tags?post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}