Nov
26

Most Popular Pages By Category - Dynamic Wordpress Hack

Posted by Rob in BLOGGER, BLOGROLL, INTERNET

A couple days ago I twittered that I’d be share a Dynamic Most Popular Pages By Category Wordpress hack. Its been in place on this blog for that time and I’ve noticed a decent improvement in the time people are spending on the site and the number of pages they visit.

Keep in mind, my increase is also a consequence of my categories being listed at the top of the page. People click through it often. I use it as a method to filter traffic and get visitors exactly where they want to be. Arguably, I need to go through some of my first posts and categorize them better, however, I’m sure many of you find yourself in the same position.

Adding a categorical most popular pages on category pages will provide you some relief until you can do that yourself. Either way, its still nice to have a another sorting method. And anything that helps the majority of your visitors improves the bottom line of most website’s goals.

Example

Web Design Category Page: http://robmalon.com/category/web-design/

Plugin & Version Requirements

Wordpress.Com Stats - Wordpress.Com Stats is one of the best, and the least load intensive statistics tracker you can get for Wordpress. Why? Because Wordpress themselves hosts it! See the graph to the right for an example of how it appears in your dashboard. This is where the data is pulled from to create the popular posts list.

Wordpress Popular Post - This “hack” is actually a modification to the Wordpress Popular Post Plugin. Perhaps they will update it with this functionality in a future release.

Wordpress 2.6 - I’m using this on a Wordpress 2.6.x install. I’ve heard that the popular post plugin does not work on Wordpress 2.5, but that may be an isolated issue. Give it a try and comment your results below.

WPPP - Wordpress Popular Posts Modifications

You can see the code changes below, but here is a link to my wppp.php modifications. I modified the 1.3.4 version of Wordpress Popular Posts. I’ll try and keep this updated, but you may be able to make changes to future versions of the plugin (with my additions) by using something like winmerge to migrate new/old code

The wppp.php file we’re modifying here can be found in: /wp-content/plugins/wordpresscom-popular-posts/wppp.php (if the plugin is installed)

  1. //Make changes to wppp.php version 1.3.4 and in this order for line numbers to be accurate
  2.  
  3. //LINE 20 - ADD AFTER: ,’title_length’ => ‘0′
  4. ,‘by_category’ => ‘0′
  5.  
  6. //LINE 61 - REPLACE: $howmany *= 2;
  7. $howmany *= 5;
  8.  
  9. //LINE 87 STARTS WITH: $results = $wpdb->get_results("
  10. //CONTINUES TILL 94 WHICH ENDS WITH: }
  11. REPLACE WITH:
  12. //RobMalon.com category hack
  13. $currentcat = $WPPP_defaults[‘by_category’];
  14. //Checks and toggle default query usage
  15. if (is_numeric($opzioni[‘by_category’]) && $opzioni[‘by_category’] > 0) {
  16. $results = $wpdb->get_results("
  17. SELECT * FROM {$wpdb->posts} p LEFT OUTER JOIN wp_term_relationships r ON r.object_id = p.ID LEFT OUTER JOIN wp_terms t ON t.term_id = r.term_taxonomy_id WHERE p.id IN (" . implode(’,', $id_list) . ") AND p.post_type = ‘" .
  18. ( $opzioni[’show’] == ‘pages’ ? ‘page’ : ‘post’ ) . "’ AND t.term_id = ‘" . $opzioni[‘by_category’] . "’
  19. ");
  20. } else {
  21. //note ID changed to upper case
  22. $results = $wpdb->get_results("
  23. SELECT ID FROM {$wpdb->posts} WHERE id IN (" . implode(’,', $id_list) . ") AND post_type = ‘" .
  24. ( $opzioni[’show’] == ‘pages’ ? ‘page’ : ‘post’ ) . "’
  25. ");
  26. }
  27.  
  28. $valid_list = array();
  29. foreach ( $results as $valid ) {
  30. $valid_list[] = $valid->ID; //note ID changed to upper case
  31. }
  32.  
  33. //LINE 209 - ADD AFTER: $opzioni['title_length'] = $opzioni['title_length'] !== NULL ? $opzioni['title_length'] : $WPPP_defaults['title_length'];
  34. $opzioni[‘by_category’] = $opzioni[‘by_category’] !== NULL ? $opzioni[‘by_category’] : $WPPP_defaults[‘by_category’];

Category Template Additions

Now you need to add a function call to WPPP_show_popular_posts in your /wp-content/themes/[themename]/category.php file. I’ve customized it in such a way that if there are less than 5 posts in a category, that it wont display a the popular category widget. You can see it and easily change that functionality in the code you see below.

  1. <?php if (have_posts()) :?>
  2. <h1 id="cat_h1">Category: <?php single_cat_title() ?></h1>
  3.  
  4. <?php
  5. $numposts = $wp_query->post_count;
  6. if (function_exists(‘WPPP_show_popular_posts’) && $numposts >= 5) { ?>
  7. <div id="popularbycategory">
  8. <h2 style="padding:0;">TOP 5 <?php single_cat_title() ?> Articles</h2>
  9. <div class="alreadyread">
  10. <?php
  11. $category = get_the_category();
  12. WPPP_show_popular_posts("show=posts&by_category={$category[0]->term_id}&title=&number=5&days=360&format=- <a href=’%post_permalink%’ title=’%post_title_attribute%’>%post_title%</a>");
  13. ?>
  14. </div></div>
  15. <?php } ?>

General Popular Posts

As a quick bonus, I thought I’d also give you the parameters of the general WPPP_show_popular_posts call that I’m using in the top left of all the pages on this site.

  1. <?php if (function_exists(‘WPPP_show_popular_posts’)) WPPP_show_popular_posts("show=posts&title_length=45&title=&number=6&days=360&format=- <a href=’%post_permalink%’ title=’%post_title_attribute%’>%post_title%</a>"); ?>

Extending The Idea

Note that the Popular By Categories hack I created was a rather quick fix. There’s more than one way to do it, and ways to make it more efficient/extendable. For example, pulling the popular categories for multiple delimited categories at once. That would come in handy for a those that assign multiple categories to a post and want to display a “Most Popular Posts Within This Posts Categories”. That’s a mouthful, and something I might do if its requested enough.

Leave a comment below with your results, examples, or questions.


Related posts:


Copyright © 2008 Rob Malon [DOT] Com.
This feed is for personal, non-commercial use only. The use of this feed on other websites breaches copyright.
If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright.
(Digital Fingerprint: 5c394827a5b7ee93916fdb889290a04c)


Tags: , , , ,





Nov
21

HowTo Recover Lost Website Content

Posted by Rob in BLOGGER, BLOGROLL, DESIGN, INTERNET

Ever loose all your site content? If you’ve maintained a website for any number of years you know that “things happen”. Servers crash, hard drives go bad, and security holes are exploited. Before you realize it, your once simple startup might have overlook backups in its growth and all your hard work is lost. More importantly, all your unique content is lost that you’ve put hours into. It doesn’t have to be that way if you act fast however!

Search Engine Cached Data

The top search engines cache the text on each page of your site so that they can search on it from queries. They also provide this to be viewed by anyone VIA a “cache” link. Google, Yahoo, and MSN have these features. If you act quickly you may be able to obtain all your site data by using the queries below. Make sure you substitute my site with your domain.

Google

Syntax: keywords site:robmalon.com
Example: Search For Wordpress on RobMalon.Com

MSN

Syntax: search term (site:robmalon.com)
Example: Search For Wordpress on RobMalon.Com

Yahoo

Syntax: keyword (Then use “Preferences” to add a site restriction on searches”)

Revision Systems Recover Accidental Mishaps.

  • Search Engine Cache (again) - The process mentioned above can also be useful if you accidently reverted content to an old version and somehow lost a large chunk of content on a page in the process. Simply enter the current URL into google and click on the “cache” link it provides you for that link.
  • Wordpress Revisions - Wordpress also has a revision system complete with auto save. Check out the Revision Control plugin which gives you some extra control over it.
  • Drupal Revisions - Another great CMS, Drupal, also has a built in revision system. Just make sure you’re using it. It doesn’t auto save by itself. You have to consciously put a tick mark in the revision box when saving a page.

Archives

Archive.Org is another resource you could try using. The only problem with this one is it typically wont index as much content. In fact, you’ll only see the front page of your site in most cases, but you will be able to see how its changed over time. Useful in rare cases, but more for fun to see how far you’ve come.

Embarrassment for your enjoyment…

Way back when I ran my current game sites on free servers. One of the first places I had them hosted at was at a url that looks like this:

  • members.spree.com/funNgames/matrix223

That hosting service isn’t around anymore (as you can see from the cache, I didn’t like them very much and was happy about my new domain/servers). However you can see pieces of my early web years from viewing it on archive.org. I had just learned tables and didn’t know PHP at all yet. Thank god it didn’t cache the site in 1997. The 2002 version, sadly, was a redesign and had all the hallmarks of a 90’s website (too much color, gifs etc. everywhere).

Were you able to find your long lost site on there? Let us know the story in the comments below.


Related posts:


Copyright © 2008 Rob Malon [DOT] Com.
This feed is for personal, non-commercial use only. The use of this feed on other websites breaches copyright.
If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright.
(Digital Fingerprint: 5c394827a5b7ee93916fdb889290a04c)


Tags: , , ,





Nov
13

Hidden Form Fields To Prevent Bot Spam

Posted by Rob in BLOGGER, BLOGROLL, INTERNET

Augie (from intellectualcapitalreport.com) presented a spam prevention method idea which we’ve been talking about under a previous post this past week: HowTo Eliminate Wordpress Trackback Comment And Pingback Spam. The basic idea is to provide an extra input field which is hidden to a user when viewed normally from the browser. This means if you check your form data when a submission is being processed, you can determine if the field is still empty. If it is filled out, then a bot must have auto filled the field.

Spam Field Details

The naming convention used on a hidden field should be named “email” or “url” to trick the bot. Your real email field will then of course need to be named something else. A small price to pay for less house cleaning.

Another key to all of this is to wrap your trap (haha) in a DIV so that the a bot cant tell that the field is hidden. Marking it with type=”hidden” on the input tag itself is a bit of a giveaway. Assigning an id or class to the div and specifying display:none; would cause the bot a lot of extra work which most probably aren’t programmed for. You could also use a built in id or class directly on the div to specify it as a hidden field.

Hidden Input Field Code

Here is an example of what your code would look like:

  1. CSS code would look like this:
  2. #email {
  3. display: none
  4. }
  5.  
  6. OR if you're doing it by the div:
  7.  
  8. .specialfield {
  9. display: none
  10. }
  11.  
  12. Your form would look something like this:
  13. <form method="post" action="yourformprocessor.php">
  14. <div class="specialfield"><input id="email" type="text"></div>
  15. <input id="realemail" type="text">
  16. </form>

Using Hidden Fields

It isn’t too much of a stretch to add this to a custom solution or implement it into a Wordpress comments or form plugins because id’s and classes are assigned to input fields by default. If you’re not already using a form plugin check out:

cforms II or Contact Form 7 (my preference).

If I get enough requests I’ll write a post which explains how to implement this into Wordpress comments in a similar manner in which I setup the Enhanced Numbered Equation CAPTCHA.

The More Spam Defense The Better

I don’t have a lot of experience in using spam bots, but this is a promising way to enhance our line of defense against spam. More importantly, its not intrusive on a users browsing experience. Unlike a CPATCHA, it requires a valid visitor to do nothing!

If you have any thoughts or comments, about this spam technique, leave them below.


Related posts:


Copyright © 2008 Rob Malon [DOT] Com.
This feed is for personal, non-commercial use only. The use of this feed on other websites breaches copyright.
If this content is not in your news reader, it makes the page you are viewing an infringement of the copyright.
(Digital Fingerprint: 5c394827a5b7ee93916fdb889290a04c)


Tags: , , ,