Skip to: Navigation | Footer

Pimping out WordPress

Not all plugins are created equal!

The way I see it, there are plugins and then there are real plugins. The first are only functions or function sets that either hook into or manipulate either the code or the database of WordPress. Real plugins are the same, but they offer fully configurable options as part of the admin area. However, this is not to say that the plain plugins are any less important to the flexibility that they offer the website owner.

The previous list of plugins aren't the full story, some functions I have borrowed, tweaked and/or rewritten and placed in the functions.php file inside of the template, and are loaded as part of that template. Here are those functions:

  1. function time_since($older_date, $newer_date = false){
  2. // array of time period chunks
  3. $chunks = array(
  4. array(60 * 60 * 24 * 365 , 'year'),
  5. array(60 * 60 * 24 * 30 , 'month'),
  6. array(60 * 60 * 24 * 7, 'week'),
  7. array(60 * 60 * 24 , 'day'),
  8. array(60 * 60 , 'hour'),
  9. array(60 , 'minute'),
  10. );
  11. // $newer_date will equal false if we want to know the time elapsed between a date and the current time
  12. // $newer_date will have a value if we want to work out time elapsed between two known dates
  13. $newer_date = ($newer_date == false) ? (time()+(60*60*get_settings("gmt_offset"))) : $newer_date;
  14. // difference in seconds
  15. $since = $newer_date - $older_date;
  16. // we only want to output two chunks of time here, eg:
  17. // x years, xx months
  18. // x days, xx hours
  19. // so there's only two bits of calculation below:
  20. // step one: the first chunk
  21. for ($i = 0, $j = count($chunks); $i < $j; $i++) {
  22. $seconds = $chunks[$i][0];
  23. $name = $chunks[$i][1];
  24. // finding the biggest chunk (if the chunk fits, break)
  25. if (($count = floor($since / $seconds)) != 0):
  26. break;
  27. endif;
  28. }
  29. // set output var
  30. $output = ($count == 1) ? '1 '.$name : "$count {$name}s";
  31. // step two: the second chunk
  32. if ($i + 1 < $j):
  33. $seconds2 = $chunks[$i + 1][0];
  34. $name2 = $chunks[$i + 1][1];
  35. if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0):
  36. // add to output var
  37. $output .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s";
  38. endif;
  39. endif;
  40. return $output;
  41. }
  42. function get_parent_category() {
  43. global $cat;
  44. foreach ((get_the_category()) as $cato):
  45. if($cat==$cato->cat_ID):
  46. if($cato->category_parent==0):
  47. return $cat;
  48. else:
  49. return $cato->category_parent;
  50. endif;
  51. endif;
  52. endforeach;
  53. return $cat;
  54. }
  55. function get_random_photos($before="
  56. <li>",$after="</li>
  57.  
  58. ",$numPosts="4") {
  59. global $post,$wpdb;
  60. $randposts = get_posts('numberposts='.$numPosts.'&category_name=photos&orderby=rand()');
  61. if ( $randposts ):
  62. foreach ( $randposts as $post ):
  63. setup_postdata($post);
  64. $start = $before.'<a href="'.get_permalink().'" title="Visit &lsquo;'.the_title('','',false).'&rsquo;">';
  65. $thethumb = yapb_get_thumbnail('','','', array('w=150', 'q=80'), 'thumbnail');
  66. $end = "</a>".$after."\n";
  67. echo $start.$thethumb.$end;
  68. endforeach;
  69. else:
  70. echo "Nothing found";
  71. endif;
  72. }
  73. function seriocomic_redirect() {
  74. $thiscat = get_parent_category();
  75. if ( ($thiscat == '27') && (!is_feed()) && (!is_category()) && (file_exists(TEMPLATEPATH . '/rhetoric.php')) ):
  76. load_template(TEMPLATEPATH.'/rhetoric.php');
  77. elseif ( $_GET['template'] && (file_exists(TEMPLATEPATH.'/'.$_GET['template'].'.php')) ):
  78. load_template(TEMPLATEPATH.'/'.$_GET['template'].'.php');
  79. endif;
  80. }
  81. add_action('template_redirect','seriocomic_redirect');
  82. remove_action('wp_head', 'rsd_link');
  83. remove_action('wp_head', 'wlwmanifest_link');
  84. if (function_exists('wp_generator')) {
  85. remove_action('wp_head', 'wp_generator');
  86. }
Page: « Prev | 1 | 2 | 3 | 4 | Next »

 | Read the 2 comments so far, and add yours .

2 comments and counting...

Jump to comment form | comments rss[?]
  1. gravatar Tyrun 2 years, 2 months ago

    Haha – I thought I was the only one that went nuts on plugins. Whether it’s Wordpress or Firefox, I somehow find the need to outfit whatever I’m using with the latest and coolest plugins. Lately I’ve been keeping it to the things I find most useful without going too overboard.

    Top notch post Mike, thanks for sharing – I’ve always enjoyed your work, as well as how you present it. Thanks for sharing some of your secrets :)

  2. gravatar seriocomic 2 years, 2 months ago

    Thank Tyrun.

    For those who hate the multiple page thing – I am working on a full-post option, and still working on fixing the feeds to show the full post…

Have your say!

Comment moderation is currently enabled.
There will most likely be a delay with your comment appearing if this is your first time.

DoFollow is in place.
I reward quality commenters with some of my google-juice.



No trackbacks/pingbacks so far...

Jump to comment form