/theme/functions.php

https://github.com/crazybilly/magazine-blog-theme · PHP · 184 lines · 111 code · 40 blank · 33 comment · 15 complexity · 380fc86363d5011fb2db3c968332e750 MD5 · raw file

  1. <?php
  2. /*
  3. //default for one sidebar
  4. if ( function_exists('register_sidebar') )
  5. register_sidebar();*/
  6. //left sidebar for home
  7. if ( function_exists('register_sidebar') )
  8. register_sidebar(array(
  9. 'name' => 'sidebarleft_home',
  10. 'before_widget' => '',
  11. 'after_widget' => '',
  12. 'before_title' => '<h2>',
  13. 'after_title' => '</h2>',
  14. ));
  15. //left sidebar for !home
  16. if ( function_exists('register_sidebar') )
  17. register_sidebar(array(
  18. 'name' => 'sidebarleft_default',
  19. 'before_widget' => '',
  20. 'after_widget' => '',
  21. 'before_title' => '<h2>',
  22. 'after_title' => '</h2>',
  23. ));
  24. //right sidebar for home
  25. if ( function_exists('register_sidebar') )
  26. register_sidebar(array(
  27. 'name' => 'sidebarright_home',
  28. 'before_widget' => '',
  29. 'after_widget' => '',
  30. 'before_title' => '<h2>',
  31. 'after_title' => '</h2>',
  32. ));
  33. //right sidebar for default
  34. if ( function_exists('register_sidebar') )
  35. register_sidebar(array(
  36. 'name' => 'sidebarright_default',
  37. 'before_widget' => '',
  38. 'after_widget' => '',
  39. 'before_title' => '<h2>',
  40. 'after_title' => '</h2>',
  41. ));
  42. //for tiny excerpts
  43. function string_limit_words($string, $word_limit)
  44. {
  45. $words = explode(' ', $string, ($word_limit + 1));
  46. if(count($words) > $word_limit)
  47. array_pop($words);
  48. return implode(' ', $words);
  49. }
  50. function location () {
  51. if (is_archive() && !is_category() && !is_tag()) {
  52. return "Archives";
  53. }
  54. if (is_search()) {
  55. return "Search Results";
  56. }
  57. if (is_404 ()) {
  58. return "404 - nothing found";
  59. }
  60. if (is_tag ()) {
  61. return single_tag_title();
  62. }
  63. if (is_category()) {
  64. //think about replacing this with just the cat names?
  65. $locations = Array (
  66. "Linux" => Array (3,"linux","Linux"),
  67. "Religion &amp; Philosophy" => Array (4,"religion","Religion"),
  68. "Interesting Links" => Array (5,"links","Links"),
  69. "Art &amp; Faith" => Array (6,"art","Art"),
  70. "Life &amp; Family" => Array (7,"life","Life"),
  71. "Computers, Web &amp; Other Technology" => Array (8,"tech","Tech")
  72. );
  73. foreach ($locations as $key => $options) {
  74. if (is_category($options)) {
  75. return $key;
  76. }
  77. }
  78. }
  79. }
  80. /*
  81. * Create the Archives pulldown
  82. * relies on permalinks like /YYYY/MM
  83. *
  84. */
  85. function archivemenu ($title) {
  86. //set title if it's not already
  87. if (!$title) {
  88. $title = "Archives";
  89. }
  90. //write the intro
  91. $intro = '<a href="#">'.$title.'</a>';
  92. //get the arrays ready
  93. //figure out the first post
  94. //function from http://www.thisismyurl.com/tutorials/wordpress-help/generating-a-dynamic-copyright-notice-in-wordpress/
  95. global $wpdb;
  96. $posts = $wpdb->get_results("SELECT YEAR(post_date_gmt) AS year FROM $wpdb->posts WHERE post_date_gmt > 1970 ORDER BY post_date_gmt ASC");
  97. $last = $posts[count($posts)-1]->year;
  98. $first = $posts[0]->year;
  99. $months = Array (
  100. '01' => 'January',
  101. '02' => 'February',
  102. '03' => 'March',
  103. '04' => 'April',
  104. '05' => 'May',
  105. '06' => 'June',
  106. '07' => 'July',
  107. '08' => 'August',
  108. '09' => 'September',
  109. '10' => 'October',
  110. '11' => 'November',
  111. '12' => 'December',
  112. );
  113. $years = Array ();
  114. while ($first <= $last) {
  115. $years[] = $first;
  116. $first++;
  117. }
  118. //write the list, sans the outer ul tags
  119. foreach ($years as $val) {
  120. //add the li for the year
  121. $list = $list.'
  122. <li><a href="'.$val.'">'.$val.'</a>
  123. <ul>';
  124. //add the lis for each month
  125. foreach ($months as $key => $mon_val) {
  126. $list = $list.'
  127. <li><a href="'.$val.'/'.$key.'">'.$mon_val.'</a></li>';
  128. }
  129. //close the monthly ul and the yearly lie
  130. $list = $list.'</ul></li>';
  131. }
  132. $all = $intro."<ul>".$list."</ul>";
  133. return $all;
  134. /*
  135. Just for Reference
  136. $intro = <a href="#">Archives
  137. $list = <li><a href="2008">2008</a>
  138. <ul>
  139. <li><a href="2008/01">January</a>
  140. <li><a href="2008/02">Feb</a>
  141. </ul></li>
  142. */
  143. }
  144. ?>