Guest User

WP Theme Andreas09 functions.php

a guest
Jun 21st, 2011
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.45 KB | None | 0 0
  1. <?php
  2.  
  3. $themecolors = array(
  4.     'bg' => 'fafcff',
  5.     'text' => '2a2a2a',
  6.     'link' => '303030'
  7. );
  8.  
  9. add_filter( 'body_class', '__return_empty_array', 1 );
  10.  
  11. add_theme_support( 'automatic-feed-links' );
  12.  
  13. // Custom background
  14. add_custom_background();
  15.  
  16. function andreas09_custom_background() {
  17.     if ( '' != get_background_color() || '' != get_background_image() ) { ?>
  18.         <style type="text/css">
  19.             #container { background: none; }
  20.         </style>
  21.     <?php }
  22. }
  23. add_action( 'wp_head', 'andreas09_custom_background' );
  24.  
  25. register_sidebar(array('name' => 'Main Sidebar', 'id' => 'main-sidebar'));
  26. register_sidebar(array('name' => 'Right Sidebar', 'id' => 'right-sidebar'));
  27.  
  28. // WP-Andreas09 Search Box  
  29. function widget_andreas09_search() {
  30. ?>
  31.    <li><?php include (TEMPLATEPATH . '/searchform.php'); ?></li>
  32. <?php
  33. }
  34. wp_register_sidebar_widget('search', __('Search'), 'widget_andreas09_search');
  35.  
  36. // WP-Andreas09 Subscribe  
  37. function widget_andreas09_subscribe() {
  38. ?>
  39. <li><h2><?php _e('Subscribe','andreas09'); ?></h2>
  40. <ul>
  41. <li class="feed"><a href="<?php bloginfo('rss2_url'); ?>"><?php _e('Entries (RSS)','andreas09'); ?></a></li>
  42. <li class="feed"><a href="<?php bloginfo('comments_rss2_url'); ?>"><?php _e('Comments (RSS)','andreas09'); ?></a></li>
  43. </ul>
  44. </li>
  45. <?php
  46. }
  47. wp_register_sidebar_widget('rss-subscribe', __('RSS Subscribe'), 'widget_andreas09_subscribe');  
  48.  
  49. // WP-Andreas09 Recent Posts    
  50. function widget_andreas09_recent_entries() {
  51.     $options = get_option('widget_recent_entries');
  52.     if ( !$number = (int) $options['number'] )
  53.         $number = 10;
  54.         $title = empty($options['title']) ? __('Recent Posts') : apply_filters('widget_title', $options['title']);
  55. ?>
  56. <li id="recent-posts"><h2><?php echo $title; ?></h2>
  57. <ul>
  58. <?php wp_get_archives('type=postbypost&limit=' . $number); ?>
  59. </ul>
  60. </li>
  61. <?php
  62. }
  63. wp_register_sidebar_widget('andreas-recent-posts', __('Andreas09 Recent Posts'), 'widget_andreas09_recent_entries');
  64.      
  65. // WP-Andreas09 Colour Options 
  66. load_theme_textdomain('andreas09');
  67.  
  68. function wp_andreas09_add_theme_page() {
  69.  
  70.     if ( $_GET['page'] == basename(__FILE__) ) {
  71.         if ( 'save' == $_REQUEST['action'] ) {
  72.             update_option( 'wp_andreas09_ImageColour', $_REQUEST[ 'set_ImageColour' ] );
  73.             header("Location: themes.php?page=functions.php&saved=true");
  74.             die;
  75.         } else if( 'reset' == $_REQUEST['action'] ) {
  76.             delete_option( 'wp_andreas09_ImageColour' );
  77.             header("Location: themes.php?page=functions.php&reset=true");
  78.             die;
  79.         }
  80.     }
  81.  
  82.     add_theme_page(__('Theme Options','andreas09'), __('Theme Options','andreas09'), 'edit_theme_options', basename(__FILE__), 'wp_andreas09_theme_page');
  83. }
  84.  
  85. function wp_andreas09_theme_page() {
  86.     if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.__('Settings saved.','andreas09').'</strong></p></div>';
  87.     if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.__('Settings reset.','andreas09').'</strong></p></div>';
  88.  
  89. ?>
  90.  
  91. <div class="wrap">
  92. <h1>WP-Andreas09</h1>
  93. <p>WP-Andreas09 <?php _e('was designed by','andreas09'); ?> <a href="http://andreasviklund.com">Andreas Viklund</a> <?php _e('and Ported to WordPress by','andreas09'); ?> <a href="http://webgazette.co.uk">Ainslie Johnson</a>.</p>
  94.  
  95. <h3><?php _e('Available Image Colours:','andreas09'); ?></h3>
  96. <style>
  97. ul.horizontal {padding-top: 5px; padding-bottom: 5px; width: 90%;}
  98. .horizontal li {list-style: none; padding: 5px 0 5px 10px; margin: 10px; border: 1px solid #000000; font-weight: bold;}
  99. li.blue { background: url(<?php bloginfo('template_url'); ?>/images/bodybg-blue.jpg);}
  100. li.green { background: url(<?php bloginfo('template_url'); ?>/images/bodybg-green.jpg);}
  101. li.red { background: url(<?php bloginfo('template_url'); ?>/images/bodybg-red.jpg);}
  102. li.orange { background: url(<?php bloginfo('template_url'); ?>/images/bodybg-orange.jpg);}
  103. li.purple { background: url(<?php bloginfo('template_url'); ?>/images/bodybg-purple.jpg);}
  104. li.black { background: url(<?php bloginfo('template_url'); ?>/images/bodybg-black.jpg);}
  105. li.isecore { background: url(<?php bloginfo('template_url'); ?>/images/bodybg-isecore.jpg);}
  106. li.pink { background: url(<?php bloginfo('template_url'); ?>/images/bodybg-pink.jpg);}
  107. li.blue2 { background: url(<?php bloginfo('template_url'); ?>/images/bodybg-blue2.jpg);}
  108. li.green2 { background: url(<?php bloginfo('template_url'); ?>/images/bodybg-green2.jpg);}
  109. li.red2 { background: url(<?php bloginfo('template_url'); ?>/images/bodybg-red2.jpg);}
  110. li.orange2 { background: url(<?php bloginfo('template_url'); ?>/images/bodybg-orange2.jpg);}
  111. li.purple2 { background: url(<?php bloginfo('template_url'); ?>/images/bodybg-purple2.jpg);}
  112. li.black2 { background: url(<?php bloginfo('template_url'); ?>/images/bodybg-black2.jpg);}
  113. .center {text-align: center;}
  114. </style>
  115.  
  116. <ul class="horizontal">
  117. <li class="blue"><?php _e('Original Blue','andreas09') ?></li>
  118. <li class="green"><?php _e('Original Green','andreas09') ?></li>
  119. <li class="red"><?php _e('Original  Red','andreas09') ?></li>
  120. <li class="orange"><?php _e('Original Orange','andreas09') ?></li>
  121. <li class="purple"><?php _e('Original Purple','andreas09') ?></li>
  122. <li class="black"><?php _e('Original Black','andreas09') ?></li>
  123. <li class="isecore">Isecore <?php _e('Blue - Courtesy of','andreas09') ?> <a href="http://blog.isecore.net/">Isecore</a></li>
  124. <li class="pink"><?php _e('Pretty Pink','andreas09') ?></li>
  125. <li class="blue2"><?php _e('Striped Blue','andreas09') ?></li>
  126. <li class="green2"><?php _e('Striped Green','andreas09') ?></li>
  127. <li class="red2"><?php _e('Striped Red','andreas09') ?></li>
  128. <li class="orange2"><?php _e('Striped Orange','andreas09') ?></li>
  129. <li class="purple2"><?php _e('Striped Purple','andreas09') ?></li>
  130. <li class="black2"><?php _e('Striped Black','andreas09') ?></li>
  131. </ul>
  132. <h3><?php _e('Image Colour Settings','andreas09') ?></h3>
  133. <form method="post">
  134. <p><?php _e('Select colour from list:','andreas09') ?>
  135. <?php
  136.     $value = get_settings( 'wp_andreas09_ImageColour' );
  137.         echo "<select name=\"set_ImageColour\" style=\"width:200px;\" onchange=\"updateColour( this )\">";
  138.         wp_andreas09_input( "set_ImageColour", "option", __('Original Blue','andreas09'), "blue", $value );
  139.         wp_andreas09_input( "set_ImageColour", "option", __('Original Green','andreas09'), "green", $value );
  140.         wp_andreas09_input( "set_ImageColour", "option", __('Original Red','andreas09'), "red", $value );
  141.         wp_andreas09_input( "set_ImageColour", "option", __('Original Orange','andreas09'), "orange", $value );
  142.         wp_andreas09_input( "set_ImageColour", "option", __('Original Purple','andreas09'), "purple", $value );
  143.         wp_andreas09_input( "set_ImageColour", "option", __('Original Black','andreas09'), "black", $value );
  144.         wp_andreas09_input( "set_ImageColour", "option", __('Isecore Blue','andreas09'), "isecore", $value );
  145.         wp_andreas09_input( "set_ImageColour", "option", __('Pretty Pink','andreas09'), "pink", $value );
  146.         wp_andreas09_input( "set_ImageColour", "option", __('Striped Blue','andreas09'), "blue2", $value );
  147.         wp_andreas09_input( "set_ImageColour", "option", __('Striped Green','andreas09'), "green2", $value );
  148.         wp_andreas09_input( "set_ImageColour", "option", __('Striped Red','andreas09'), "red2", $value );
  149.         wp_andreas09_input( "set_ImageColour", "option", __('Striped Orange','andreas09'), "orange2", $value );
  150.         wp_andreas09_input( "set_ImageColour", "option", __('Striped Purple','andreas09'), "purple2", $value );
  151.         wp_andreas09_input( "set_ImageColour", "option", __('Striped Black','andreas09'), "black2", $value );
  152.         echo "</select>";
  153. ?>
  154. </p>
  155.  
  156. <!-- Save Settings Button -->
  157. <?php wp_andreas09_input( "save", "submit", "", __('Save Settings','andreas09') ); ?>
  158. <input type="hidden" name="action" value="save" />
  159. </form>
  160. <p class="center"><?php _e('With credit to','andreas09'); ?> <a href="http://www.binarymoon.co.uk/" title="Binary Moon - games, web design, and other random nonsense">Ben Gillbanks</a>. <?php _e('I could not have implemented the <strong>Current Theme Options</strong> without his excellent example in the','andreas09'); ?> <a href="http://www.binarymoon.co.uk/regulus/" title="Regulus theme for WordPress">Regulus</a></p>
  161.  
  162. </div>
  163.  
  164. <?php
  165. }
  166.  
  167. add_action('admin_menu', 'wp_andreas09_add_theme_page');
  168.  
  169. function wp_andreas09_input( $var, $type, $description = "", $value = "", $selected="" ) {
  170.     echo "\n";
  171.     switch( $type ){
  172.         case "submit":
  173.             echo "<p class=\"submit\"><input name=\"$var\" type=\"$type\" value=\"$value\" /></p>";
  174.             break;
  175.  
  176.         case "option":
  177.             if( $selected == $value ) { $extra = "selected=\"true\""; }
  178.             echo "<option value=\"$value\" $extra >$description</option>";
  179.             break;
  180.     }
  181. }
  182.  
  183. /*
  184. Plugin Name: PageNav
  185. Plugin URI: http://www.adsworth.info/wp-pagesnav
  186. Description: Header Navigation.
  187. Author: Adi Sieker
  188. Version: 0.0.1
  189. Author URI: http://www.adsworth.info/
  190. */
  191. /*  Copyright 2004  Adi J. Sieker  (email : [email protected])
  192.  
  193.     This program is free software; you can redistribute it and/or modify
  194.     it under the terms of the GNU General Public License as published by
  195.     the Free Software Foundation; either version 2 of the License, or
  196.     (at your option) any later version.
  197.  
  198.     This program is distributed in the hope that it will be useful,
  199.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  200.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  201.     GNU General Public License for more details.
  202.  
  203.     You should have received a copy of the GNU General Public License
  204.     along with this program; if not, write to the Free Software
  205.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  206. */
  207.  
  208. function wp_andreas09_nav($args = '') {
  209.     global $wp_query;
  210.     parse_str($args, $r);
  211.     if (!isset($r['current']))          $r['current'] = -1;
  212.     if (!isset($r['show_all_parents'])) $r['show_all_parents'] = 0;
  213.     if (!isset($r['show_root']))        $r['show_root'] = 0;
  214.     if (!isset($r['list_tag']))        $r['show_root'] = 1;
  215.  
  216.     if($r['current'] == "")
  217.         return;
  218.  
  219.     if($r['current'] == -1 && $wp_query->is_page == true) {
  220.         $r['current'] = $wp_query->post->ID;
  221.     }
  222.  
  223.     if($r['current'] == -1 && $r['show_root'] != 0) {
  224.         $r['current'] = 0;
  225.     }
  226.    
  227.     // Query pages.
  228.     $pages = get_pages($args);
  229.     if ( $pages ) {
  230.         // Now loop over all pages that were selected
  231.         $page_tree = Array();
  232.         $parent_page_id = null;
  233.         $parents= Array();
  234.         foreach($pages as $page) {
  235.             // set the title for the current page
  236.             $page_tree[$page->ID]['title'] = $page->post_title;
  237.             $page_tree[$page->ID]['parent'] = $page->post_parent;
  238.    
  239.             // set the selected date for the current page
  240.             // depending on the query arguments this is either
  241.             // the createtion date or the modification date
  242.             // as a unix timestamp. It will also always be in the
  243.             // ts field.
  244.             if (! empty($r['show_date'])) {
  245.                 if ('modified' == $r['show_date'])
  246.                     $page_tree[$page->ID]['ts'] = $page->time_modified;
  247.                 else
  248.                     $page_tree[$page->ID]['ts'] = $page->time_created;
  249.             }
  250.    
  251.             // The tricky bit!!
  252.             // Using the parent ID of the current page as the
  253.             // array index we set the curent page as a child of that page.
  254.             // We can now start looping over the $page_tree array
  255.             // with any ID which will output the page links from that ID downwards.
  256.             $page_tree[$page->post_parent]['children'][] = $page->ID;  
  257.             if( $r['current'] == $page->ID) {
  258.                 if($page->post_parent != 0 || $r['show_root'] == true)
  259.                     $parents[] = $page->post_parent;
  260.             }
  261.  
  262.         }
  263.  
  264.         $len = count($parents);
  265.         for($i = 0; $i < $len ; $i++) {
  266.             $parent_page_id = $parents[$i];
  267.             $parent_page = $page_tree[$parent_page_id];
  268.  
  269.             if(isset($parent_page['parent']) && !in_array($parent_page['parent'], $parents)) {
  270.                 if($parent_page['parent'] != 0 || $r['show_root'] == true) {
  271.                     $parents[] = $parent_page['parent'];
  272.                     $len += 1;
  273.                     if( $len >= 2 && $r['show_all_parents'] == 0) {
  274.                         break;
  275.                     }
  276.  
  277.                 }
  278.             }
  279.         }
  280.  
  281.         $parents = array_reverse($parents);
  282.  
  283.         $level = 0;
  284.         $parent_out == false;
  285.         foreach( $parents as $parent_page_id ) {
  286.             $level += 1;
  287.             $css_class = 'level' . $level;
  288.             if( $r['list_tag'] == true || $parent_out == true)
  289.                 echo "<ul class='". $css_class . "'>";
  290.             foreach( $page_tree[$parent_page_id]['children'] as $page_id) {
  291.                 $cur_page = $page_tree[$page_id];
  292.                 $title = $cur_page['title'];
  293.  
  294.                 $css_class = '';
  295.                 if( $page_id == $r['current']) {
  296.                     $css_class .= ' current';
  297.                 }
  298.                 if( $page_id == $page_tree[$r['current']]['parent']){
  299.                     $css_class .= 'currentparent';
  300.                 }
  301.                 echo "<li class='" . $css_class . "' ><a href='" . get_page_link($page_id) . "' title='" . esc_attr($title) . "'>" . $title . "</a></li>\n";
  302.             }
  303.  
  304.                 echo "</ul>";
  305.  
  306.             $parent_out = true;
  307.  
  308.         }
  309.  
  310.         if( is_array($page_tree[$r['current']]['children']) === true ) {
  311.             $level += 1;
  312.             $css_class = 'level' . $level;
  313.             if( $r['list_tag'] == true || $parent_out == true)
  314.                 echo "<ul class='". $css_class . " children'>";
  315.             foreach( $page_tree[$r['current']]['children'] as $page_id) {
  316.                 $cur_page = $page_tree[$page_id];
  317.                 $title = $cur_page['title'];
  318.        
  319.                 echo "<li class='" . $css_class . "'><a href='" . get_page_link($page_id) . "' title='" . esc_attr($title) . "'>" . $title . "</a></li>\n";
  320.             }
  321.  
  322.                 echo "</ul>";
  323.  
  324.         }
  325.      }
  326. }
  327.  
  328. // Header navigation menu
  329. register_nav_menus( array(
  330.     'primary' => __( 'Primary Navigation', 'andreas09' )
  331. ) );
  332.  
  333. // Fallback for primary navigation
  334. function andreas09_page_menu() { ?>
  335.     <ul class="level1">
  336.         <li<?php if ( is_front_page() ) echo ' class="current_page_item"'; ?>><a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Home', 'andreas09' ); ?></a></li>
  337.         <?php wp_list_pages( 'depth=1&title_li=' ); ?>
  338.     </ul>
  339. <?php }
  340.  
  341. function andreas09_callback($comment, $args, $depth) {
  342.     $GLOBALS['comment'] = $comment;
  343.     extract($args, EXTR_SKIP);
  344. ?>
  345.     <li <?php comment_class(empty( $args['has_children'] ) ? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">
  346.     <div class="comment-author vcard">
  347.     <?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?>
  348.     <h3 class="commenttitle"><cite class="fn"><?php comment_author_link(); ?></cite> <span class="says"><?php _e('said','almost-spring'); ?></span></h3>
  349.     </div>
  350. <?php if ($comment->comment_approved == '0') : ?>
  351.     <em><?php _e('Your comment is awaiting moderation.','andreas09'); ?></em>
  352.     <br />
  353. <?php endif; ?>
  354.    
  355.     <small class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
  356.     <?php comment_date() ?> <?php _e('at','andreas09'); ?> <?php comment_time() ?></a> <?php edit_comment_link('e','',''); ?></small>
  357.    
  358.     <?php comment_text(); ?>
  359.  
  360.     <div class="reply">
  361.     <?php comment_reply_link(array_merge( $args, array('add_below' => 'comment', 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  362.     </div>
  363. <?php
  364. }
  365.  
  366. function andreas09_comment_form_defaults( $args ) {
  367.     $args['title_reply'] = __( 'Leave a Comment', 'andreas09' );
  368.     return $args;
  369. }
  370.  
  371. add_filter( 'comment_form_defaults', 'andreas09_comment_form_defaults' );
Advertisement
Add Comment
Please, Sign In to add comment