• 1.
    <?php
  • 2.
     
  • 3.
    add_theme_support( 'custom-background' );
  • 4.
    $defaults = array(
  • 5.
    	'default-image'          => '',
  • 6.
    	'wp-head-callback'       => '_custom_background_cb',
  • 7.
    	'admin-head-callback'    => '',
  • 8.
    	'admin-preview-callback' => ''
  • 9.
    );
  • 10.
    add_theme_support( 'custom-background', $defaults);
  • 11.
     
  • 12.
     
  • 13.
    // WP THEME CUSTOMIZER: START
  • 14.
    function wptuts_theme_customizer( $wp_customize ) {
  • 15.
     
  • 16.
     
  • 17.
    //// SECTION: LINKS
  • 18.
    $wp_customize->add_section( 'links', array(
  • 19.
    'title' => 'Links',
  • 20.
    'description' => 'Link settings',
  • 21.
    ) );
  • 22.
     
  • 23.
    	//// LINKS: Link Color
  • 24.
    	$wp_customize->add_setting( 'link_color', array(
  • 25.
    		'default' => 'Hello world',					// Default value
  • 26.
    	) );
  • 27.
     
  • 28.
    	$wp_customize->add_control( 'link_color', array(		// Unique name to grab the code via PHP
  • 29.
    	'label' => 'Link Color',					// Label
  • 30.
    	// 'type' =>,							// Default is "text", define the content type.
  • 31.
    	'section' => 'links',						// ID of the section that this function belongs to
  • 32.
    	) );
  • 33.
     
  • 34.
     
  • 35.
    // WP THEME CUSTOMIZER: LAST LINE
  • 36.
    }
  • 37.
    add_action( 'customize_register', 'wptuts_theme_customizer', 11 );
  • 38.
     
  • 39.
     
  • 40.
    // Enque: jQuery
  • 41.
    if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
  • 42.
    function my_jquery_enqueue() {
  • 43.
       wp_deregister_script('jquery');
  • 44.
       wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
  • 45.
       wp_enqueue_script('jquery');
  • 46.
    }
  • 47.
     
  • 48.
    // WP_LINK_PAGES: Add prev and next links to a numbered link list
  • 49.
    add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add'); 
  • 50.
     
  • 51.
    function wp_link_pages_args_prevnext_add($args) { 
  • 52.
        global $page, $numpages, $more, $pagenow; 
  • 53.
        $args['before'] = '<div id="link_wrap">'; 
  • 54.
        $args['after'] = '</div>'; 
  • 55.
        $args['link_before'] = '<span class="classlinks %s">';
  • 56.
        $args['link_after'] = '</span>'; 
  • 57.
        if($page-1) // there is a previous page 
  • 58.
        $args['before'] .= ' '. _wp_link_page($page-1) . sprintf($args['link_before'],'prev') . $args['previouspagelink'] . $args['link_after'] . '</a>' . ' ' ;
  • 59.
        if ($page<$numpages) // there is a next page 
  • 60.
        $args['after'] = ' '. _wp_link_page($page+1) . sprintf($args['link_before'],'next') . $args['nextpagelink'] . $args['link_after'] . '</a></div>' ; 
  • 61.
        return $args; 
  • 62.
    } 
  • 63.
     
  • 64.
    // Custom Post Type: Portfolio
  • 65.
    add_action( 'init', 'register_cpt_portfolio' );
  • 66.
     
  • 67.
    function register_cpt_portfolio() {
  • 68.
     
  • 69.
        $labels = array( 
  • 70.
            'name' => _x( 'Portfolio', 'portfolio' ),
  • 71.
            'singular_name' => _x( 'Portfolio', 'portfolio' ),
  • 72.
            'add_new' => _x( 'Add New', 'portfolio' ),
  • 73.
            'add_new_item' => _x( 'Add New', 'portfolio' ),
  • 74.
            'edit_item' => _x( 'Edit Portfolio', 'portfolio' ),
  • 75.
            'new_item' => _x( 'New Portfolio', 'portfolio' ),
  • 76.
            'view_item' => _x( 'View Portfolio', 'portfolio' ),
  • 77.
            'search_items' => _x( 'Search Portfolio Projects', 'portfolio' ),
  • 78.
            'not_found' => _x( 'No portfolio projects found', 'portfolio' ),
  • 79.
            'not_found_in_trash' => _x( 'No portfolio projects found in Trash', 'portfolio' ),
  • 80.
            'parent_item_colon' => _x( 'Parent Portfolio:', 'portfolio' ),
  • 81.
            'menu_name' => _x( 'Portfolio', 'portfolio' ),
  • 82.
        );
  • 83.
     
  • 84.
        $args = array( 
  • 85.
            'labels' => $labels,
  • 86.
            'hierarchical' => true,
  • 87.
            'description' => 'Portfolio',
  • 88.
            'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ),
  • 89.
            'taxonomies' => array( 'portfolio' ),
  • 90.
            'public' => true,
  • 91.
            'show_ui' => true,
  • 92.
            'show_in_menu' => true,
  • 93.
            'show_in_nav_menus' => true,
  • 94.
            'publicly_queryable' => true,
  • 95.
            'exclude_from_search' => false,
  • 96.
            'has_archive' => true,
  • 97.
            'query_var' => true,
  • 98.
            'can_export' => true,
  • 99.
            'rewrite' => true,
  • 100.
            'capability_type' => 'post'
  • 101.
        );
  • 102.
     
  • 103.
        register_post_type( 'portfolio', $args );
  • 104.
     
  • 105.
    // Portfolio meta box
  • 106.
    add_action( 'admin_print_styles-post-new.php', 'portfolio_admin_style', 11 );
  • 107.
    add_action( 'admin_print_styles-post.php', 'portfolio_admin_style', 11 );
  • 108.
     
  • 109.
    // Portfolio meta box styles
  • 110.
    function portfolio_admin_style() {
  • 111.
    	global $post_type;
  • 112.
    	if( 'portfolio' == $post_type )
  • 113.
    	wp_enqueue_style( 'portfolio-admin-style', get_stylesheet_directory_uri() . '/styles/portfolio-admin.css' );
  • 114.
    }
  • 115.
    }
  • 116.
     
  • 117.
    // Input fields
  • 118.
    add_action("admin_init", "add_portfolio");
  • 119.
    add_action('save_post', 'update_website_url');
  • 120.
     
  • 121.
    // Meta Box Title
  • 122.
    function add_portfolio(){
  • 123.
    	add_meta_box("portfolio_details", "Project Information", "portfolio_options", "portfolio", "normal", "low");
  • 124.
    }
  • 125.
     
  • 126.
    // Create Custom Meta
  • 127.
    function portfolio_options(){
  • 128.
    	global $post;
  • 129.
    	$custom = get_post_custom($post->ID);
  • 130.
    	$website_url = $custom["website_url"][0];
  • 131.
    	$port_excerpt = $custom["port_excerpt"][0];
  • 132.
    ?>
  • 133.
     
  • 134.
    // Meta Box HTML Markup
  • 135.
    <div id="portfolio-options">
  • 136.
    	<span><label>Website URL</label><input name="website_url" value="<?php echo $website_url; ?>" /></span>
  • 137.
    	<span><label>Excerpt</label><input name="port_excerpt" value="<?php echo $port_excerpt; ?>" /></span>		
  • 138.
    </div>
  • 139.
     
  • 140.
    <!--end portfolio-options-->   
  • 141.
    <?php
  • 142.
    	}
  • 143.
    	function update_website_url(){
  • 144.
    		global $post;
  • 145.
    		update_post_meta($post->ID, "website_url", $_POST["website_url"]);
  • 146.
    		update_post_meta($post->ID, "port_excerpt", $_POST["port_excerpt"]);
  • 147.
    	}
  • 148.
     
  • 149.
    add_filter("manage_edit-portfolio_columns", "portfolio_edit_columns");
  • 150.
    add_action("manage_posts_custom_column",  "portfolio_columns_display");
  • 151.
     
  • 152.
    function portfolio_edit_columns($portfolio_columns){
  • 153.
    	$portfolio_columns = array(
  • 154.
    		"cb" => "<input type=\"checkbox\" />",
  • 155.
    		"title" => "Project Title",
  • 156.
    		"description" => "Description",
  • 157.
    	);
  • 158.
    	return $portfolio_columns;
  • 159.
    }
  • 160.
     
  • 161.
    function portfolio_columns_display($portfolio_columns){
  • 162.
    	switch ($portfolio_columns)
  • 163.
    	{
  • 164.
    		case "description":
  • 165.
    			the_excerpt();
  • 166.
    			break;				
  • 167.
    	}
  • 168.
    }
  • 169.
     
  • 170.
    // Excerpt word count
  • 171.
    function excerpt_count_js(){
  • 172.
    	echo '<script>jQuery(document).ready(function(){
  • 173.
    jQuery("#postexcerpt .handlediv").after("<div style=\"position:absolute;top:0px;right:5px;color:#666;\"><small>Excerpt length: </small><input type=\"text\" value=\"0\" maxlength=\"3\" size=\"3\" id=\"excerpt_counter\" readonly=\"\" style=\"background:#fff;\"> <small>word(s).</small></div>");
  • 174.
    	jQuery("#excerpt_counter").val(jQuery("#excerpt").val().split(/\S+\b[\s,\.\'-:;]*/).length - 1);
  • 175.
    	jQuery("#excerpt").keyup( function() {
  • 176.
    	jQuery("#excerpt_counter").val(jQuery("#excerpt").val().split(/\S+\b[\s,\.\'-:;]*/).length - 1);
  • 177.
    	});
  • 178.
    });</script>';
  • 179.
    }
  • 180.
    add_action( 'admin_head-post.php', 'excerpt_count_js');
  • 181.
    add_action( 'admin_head-post-new.php', 'excerpt_count_js');
  • 182.
     
  • 183.
    // Quote format always a blockquote
  • 184.
    add_filter( 'the_content', 'my_quote_content' );
  • 185.
     
  • 186.
    function my_quote_content( $content ) {
  • 187.
     
  • 188.
    	/* Check if we're displaying a 'quote' post. */
  • 189.
    	if ( has_post_format( 'quote' ) ) {
  • 190.
     
  • 191.
    		/* Match any <blockquote> elements. */
  • 192.
    		preg_match( '/<blockquote.*?>/', $content, $matches );
  • 193.
     
  • 194.
    		/* If no <blockquote> elements were found, wrap the entire content in one. */
  • 195.
    		if ( empty( $matches ) )
  • 196.
    			$content = "<blockquote>{$content}</blockquote>";
  • 197.
    	}
  • 198.
    	return $content;
  • 199.
    }
  • 200.
     
  • 201.
    // Pagination
  • 202.
    function my_theme_navigation() 
  • 203.
    { 
  • 204.
        global $shortname;
  • 205.
     
  • 206.
        if( get_option( $shortname . '_next_prev_or_paginate' ) == 'Next/Previous Links' ) : 
  • 207.
            // the block for next-prev navigation
  • 208.
    		echo '<div class="left">';
  • 209.
            next_posts_link('Older');
  • 210.
    		echo '</div>';
  • 211.
    		echo '<div class="right">';
  • 212.
            previous_posts_link ('Newer');
  • 213.
    		echo '</div>';
  • 214.
        else : 
  • 215.
            // the block for pagination
  • 216.
            global $wp_query;
  • 217.
            $big = 999999999; // need an unlikely integer
  • 218.
            echo paginate_links(
  • 219.
                array(
  • 220.
                    'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
  • 221.
                    'format' => '?paged=%#%',
  • 222.
    		'end_size'     => 1,
  • 223.
    		'mid_size'     => 2,
  • 224.
                    'current' => max( 1, get_query_var('paged') ), 
  • 225.
                    'total' => $wp_query->max_num_pages
  • 226.
                )
  • 227.
            ); 
  • 228.
        endif; 
  • 229.
    }
  • 230.
     
  • 231.
     
  • 232.
    // Remove 10px caption margin
  • 233.
    add_filter( 'img_caption_shortcode', 'wap8_img_caption', 10, 3 );
  • 234.
    function wap8_img_caption($nowt, $attr, $content) {
  • 235.
    	extract( shortcode_atts( array(
  • 236.
    		'id' => '',
  • 237.
    		'align' => 'alignnone',
  • 238.
    		'width' => '',
  • 239.
    		'caption' => '',
  • 240.
    	), $attr ) );
  • 241.
     
  • 242.
    	if ( 1 > (int) $width || empty( $caption ) ) {
  • 243.
    		return $content;
  • 244.
    	} 
  • 245.
    	if ( $id )
  • 246.
    		$id = 'id="' . esc_attr( $id ) . '" ';
  • 247.
    	return '<div ' . $id . 'class="wp-caption ' . esc_attr( $align ) . '" style="width:' . ( (int) $width ) . 'px;">' . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
  • 248.
    }
  • 249.
     
  • 250.
    // Posts per page
  • 251.
    add_filter('parse_query', 'wpq_parse_query');
  • 252.
    function wpq_parse_query($query)
  • 253.
    {
  • 254.
    	if($query->is_archive())
  • 255.
    	{
  • 256.
    		$query->query_vars['posts_per_page'] = get_option('to_count_archives', 10);
  • 257.
    	}
  • 258.
    	if($query->is_home())
  • 259.
    	{
  • 260.
    		$query->query_vars['posts_per_page'] = get_option('to_count_home', 10);
  • 261.
    	}
  • 262.
    	if($query->is_search())
  • 263.
    	{
  • 264.
    		$query->query_vars['posts_per_page'] = get_option('to_count_search', 10);
  • 265.
    	}
  • 266.
    	return $query;
  • 267.
    }
  • 268.
     
  • 269.
     
  • 270.
    // Profile fields: Add Twitter and Location
  • 271.
    add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
  • 272.
    add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
  • 273.
    function my_show_extra_profile_fields( $user ) { ?>
  • 274.
    	<h3>Extra profile information</h3>
  • 275.
    	<table class="form-table">
  • 276.
    		<tr>
  • 277.
    			<th><label for="twitter">Twitter</label></th>
  • 278.
    			<td>
  • 279.
    				<input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br />
  • 280.
    				<span class="description">Where are you?</span>
  • 281.
    			</td>
  • 282.
    		</tr>
  • 283.
     
  • 284.
    		<tr>
  • 285.
    <th><label for="location">Location</label></th>
  • 286.
    			<td>
  • 287.
    				<input type="text" name="location" id="location" value="<?php echo esc_attr( get_the_author_meta( 'location', $user->ID ) ); ?>" class="regular-text" /><br />
  • 288.
    				<span class="description">Please enter your Twitter username.</span>
  • 289.
    			</td>
  • 290.
    		</tr>
  • 291.
    	</table>
  • 292.
    <?php }
  • 293.
     
  • 294.
    add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
  • 295.
    add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
  • 296.
     
  • 297.
    function my_save_extra_profile_fields( $user_id ) {
  • 298.
     
  • 299.
    	if ( !current_user_can( 'edit_user', $user_id ) )
  • 300.
    		return false;
  • 301.
     
  • 302.
    	/* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
  • 303.
    	update_usermeta( $user_id, 'twitter', $_POST['twitter'] );
  • 304.
    	update_usermeta( $user_id, 'location', $_POST['location'] );
  • 305.
    }
  • 306.
     
  • 307.
    // Breadcrumbs
  • 308.
    function dimox_breadcrumbs() {
  • 309.
      $delimiter = '<span class="crumbdivider">&raquo;</span>';
  • 310.
      $home = 'Home'; // text for the 'Home' link
  • 311.
      $before = '<span class="current">'; // tag before the current crumb
  • 312.
      $after = '</span>'; // tag after the current crumb
  • 313.
      if ( !is_home() && !is_front_page() || is_paged() ) {
  • 314.
         echo '<div id="crumbs">'; 
  • 315.
        global $post;
  • 316.
        $homeLink = get_bloginfo('url');
  • 317.
        echo '<a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' ';
  • 318.
        if ( is_category() ) {
  • 319.
          global $wp_query;
  • 320.
          $cat_obj = $wp_query->get_queried_object();
  • 321.
          $thisCat = $cat_obj->term_id;
  • 322.
          $thisCat = get_category($thisCat);
  • 323.
          $parentCat = get_category($thisCat->parent);
  • 324.
          if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
  • 325.
          echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after;
  • 326.
        } elseif ( is_day() ) {
  • 327.
          echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
  • 328.
          echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
  • 329.
          echo $before . get_the_time('d') . $after;
  • 330.
        } elseif ( is_month() ) {
  • 331.
          echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
  • 332.
          echo $before . get_the_time('F') . $after;
  • 333.
        } elseif ( is_year() ) {
  • 334.
          echo $before . get_the_time('Y') . $after;
  • 335.
        } elseif ( is_single() && !is_attachment() ) {
  • 336.
          if ( get_post_type() != 'post' ) {
  • 337.
            $post_type = get_post_type_object(get_post_type());
  • 338.
            $slug = $post_type->rewrite;
  • 339.
            echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' ';
  • 340.
            echo $before . get_the_title() . $after;
  • 341.
          } else {
  • 342.
            $cat = get_the_category(); $cat = $cat[0];
  • 343.
            echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
  • 344.
            echo $before . get_the_title() . $after;
  • 345.
          }
  • 346.
     
  • 347.
        } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
  • 348.
          $post_type = get_post_type_object(get_post_type());
  • 349.
          echo $before . $post_type->labels->singular_name . $after;
  • 350.
     
  • 351.
        } elseif ( is_attachment() ) {
  • 352.
          $parent = get_post($post->post_parent);
  • 353.
          $cat = get_the_category($parent->ID); $cat = $cat[0];
  • 354.
          echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
  • 355.
          echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
  • 356.
          echo $before . get_the_title() . $after;
  • 357.
     
  • 358.
        } elseif ( is_page() && !$post->post_parent ) {
  • 359.
          echo $before . get_the_title() . $after;
  • 360.
     
  • 361.
        } elseif ( is_page() && $post->post_parent ) {
  • 362.
          $parent_id  = $post->post_parent;
  • 363.
          $breadcrumbs = array();
  • 364.
          while ($parent_id) {
  • 365.
            $page = get_page($parent_id);
  • 366.
            $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
  • 367.
            $parent_id  = $page->post_parent;
  • 368.
          }
  • 369.
          $breadcrumbs = array_reverse($breadcrumbs);
  • 370.
          foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
  • 371.
          echo $before . get_the_title() . $after;
  • 372.
     
  • 373.
        } elseif ( is_search() ) {
  • 374.
          echo $before . 'Search results for "' . get_search_query() . '"' . $after;
  • 375.
     
  • 376.
        } elseif ( is_tag() ) {
  • 377.
          echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after;
  • 378.
     
  • 379.
        } elseif ( is_author() ) {
  • 380.
           global $author;
  • 381.
          $userdata = get_userdata($author);
  • 382.
          echo $before . 'Articles posted by ' . $userdata->display_name . $after;
  • 383.
     
  • 384.
        } elseif ( is_404() ) {
  • 385.
          echo $before . 'Error 404' . $after;
  • 386.
        }
  • 387.
     
  • 388.
        if ( get_query_var('paged') ) {
  • 389.
          if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
  • 390.
          echo __('Page') . ' ' . get_query_var('paged');
  • 391.
          if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
  • 392.
        }
  • 393.
     
  • 394.
        echo '</div>';
  • 395.
     
  • 396.
      }
  • 397.
    } // end dimox_breadcrumbs()
  • 398.
     
  • 399.
    // Shortcode: Obfuscate e-mail addresses
  • 400.
    function cwc_mail_shortcode( $atts , $content=null ) {
  • 401.
        for ($i = 0; $i < strlen($content); $i++) $encodedmail .= "&#" . ord($content[$i]) . ';';
  • 402.
        return '<a href="mailto:'.$encodedmail.'">'.$encodedmail.'</a>';
  • 403.
    }
  • 404.
    add_shortcode('mailto', 'cwc_mail_shortcode');
  • 405.
     
  • 406.
    // Shortcode: Drop cap
  • 407.
    add_shortcode('dropcap', 'dropcap');
  • 408.
    function dropcap($atts, $content = null) {
  • 409.
       extract(shortcode_atts(array('link' => '#'), $atts));
  • 410.
       return '<span class="dropcap">' . do_shortcode($content) . '</span>';
  • 411.
    }
  • 412.
     
  • 413.
    // Shortcode: Scroll to top
  • 414.
    function scrolltop() {
  • 415.
    return '<a class="btn" href="#wrap" title="Scroll to top">Scroll to top</a>';
  • 416.
    }
  • 417.
     
  • 418.
    add_shortcode('scrolltop', 'scrolltop');
  • 419.
     
  • 420.
    // Shortcode: PDF viewer
  • 421.
    function pdflink($attr, $content) {
  • 422.
    	return '<a class="btn" href="http://docs.google.com/viewer?url=' . $attr['href'] . '">'.$content.'</a>';
  • 423.
    }
  • 424.
    add_shortcode('pdf', 'pdflink');
  • 425.
     
  • 426.
    // Shortcode: Buttons
  • 427.
    function btn($atts, $content = null) {
  • 428.
       extract(shortcode_atts(array('link' => '#', 'color' => '' , 'size' => 'large'), $atts));
  • 429.
       return '<a class="btn '.$size.'" href="'.$link.'" style="background-color:'.$color.';"><span>' . do_shortcode($content) . '</span></a>';
  • 430.
    }
  • 431.
    add_shortcode('btn', 'btn');
  • 432.
     
  • 433.
    // Shortcode: total words
  • 434.
    function total_words() {
  • 435.
      global $wpdb;
  • 436.
      return $wpdb->get_var("SELECT SUM(LENGTH(post_content) - LENGTH(REPLACE(post_content, ' ', '')) + 1) 
  • 437.
                             FROM $wpdb->posts 
  • 438.
                             WHERE post_type = 'post' 
  • 439.
                             AND post_status = 'publish'");
  • 440.
    }
  • 441.
    add_shortcode('totalwords', 'total_words');
  • 442.
     
  • 443.
    // Shortcode: Two columns
  • 444.
    function two($atts, $content = null) {
  • 445.
    	return '
  • 446.
    <div class="two">'.$content.'</div>
  • 447.
    ';
  • 448.
    }
  • 449.
    function two_last($atts, $content = null) {
  • 450.
    	return '
  • 451.
    <div class="two-last">'.$content.'</div>
  • 452.
    <br class="clear" />';
  • 453.
    }
  • 454.
    add_shortcode('two', 'two');
  • 455.
    add_shortcode('two_last', 'two_last');
  • 456.
     
  • 457.
    // Shortcode: Three columns
  • 458.
    function three($atts, $content = null) {
  • 459.
    	return '
  • 460.
    <div class="three">'.$content.'</div>
  • 461.
    ';
  • 462.
    }
  • 463.
    function three_last($atts, $content = null) {
  • 464.
    	return '
  • 465.
    <div class="three-last">'.$content.'</div>
  • 466.
    <br class="clear" />';
  • 467.
    }
  • 468.
    add_shortcode('three', 'three');
  • 469.
    add_shortcode('three_last', 'three_last');
  • 470.
     
  • 471.
    // Shortcode: Four columns
  • 472.
    function four($atts, $content = null) {
  • 473.
    	return '
  • 474.
    <div class="four">'.$content.'</div>
  • 475.
    ';
  • 476.
    }
  • 477.
    function four_last($atts, $content = null) {
  • 478.
    	return '
  • 479.
    <div class="four-last">'.$content.'</div>
  • 480.
    <br class="clear" />';
  • 481.
    }
  • 482.
    add_shortcode('four', 'four');
  • 483.
    add_shortcode('four_last', 'four_last');
  • 484.
     
  • 485.
    // Shortcode: Five columns
  • 486.
    function five($atts, $content = null) {
  • 487.
    	return '
  • 488.
    <div class="five">'.$content.'</div>
  • 489.
    ';
  • 490.
    }
  • 491.
    function five_last($atts, $content = null) {
  • 492.
    	return '
  • 493.
    <div class="five-last">'.$content.'</div>
  • 494.
    <br class="clear" />';
  • 495.
    }
  • 496.
    add_shortcode('five', 'five');
  • 497.
    add_shortcode('five_last', 'five_last');
  • 498.
     
  • 499.
    // Shortcode: Six columns
  • 500.
    function six($atts, $content = null) {
  • 501.
    	return '
  • 502.
    <div class="six">'.$content.'</div>
  • 503.
    ';
  • 504.
    }
  • 505.
    function six_last($atts, $content = null) {
  • 506.
    	return '
  • 507.
    <div class="six-last">'.$content.'</div>
  • 508.
    <br class="clear" />';
  • 509.
    }
  • 510.
    add_shortcode('six', 'six');
  • 511.
    add_shortcode('six_last', 'six_last');
  • 512.
     
  • 513.
    // Custom templates: post templates
  • 514.
    if(!function_exists('get_post_templates')) {
  • 515.
    function get_post_templates() {
  • 516.
    	$themes = get_themes();
  • 517.
    	$theme = get_current_theme();
  • 518.
    	$templates = $themes[$theme]['Template Files'];
  • 519.
    	$post_templates = array();
  • 520.
     
  • 521.
    	$base = array(trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()));
  • 522.
     
  • 523.
    	foreach ((array)$templates as $template) {
  • 524.
    		$template = WP_CONTENT_DIR . str_replace(WP_CONTENT_DIR, '', $template); 
  • 525.
    		$basename = str_replace($base, '', $template);
  • 526.
     
  • 527.
    		// don't allow template files in subdirectories
  • 528.
    		if (false !== strpos($basename, '/'))
  • 529.
    			continue;
  • 530.
     
  • 531.
    		$template_data = implode('', file( $template ));
  • 532.
     
  • 533.
    		$name = '';
  • 534.
    		if (preg_match( '|Single Post Template:(.*)$|mi', $template_data, $name))
  • 535.
    			$name = _cleanup_header_comment($name[1]);
  • 536.
     
  • 537.
    		if (!empty($name)) {
  • 538.
    			if(basename($template) != basename(__FILE__))
  • 539.
    				$post_templates[trim($name)] = $basename;
  • 540.
    		}
  • 541.
    	}
  • 542.
     
  • 543.
    	return $post_templates;
  • 544.
     
  • 545.
    }}
  • 546.
     
  • 547.
    //	build the dropdown items
  • 548.
    if(!function_exists('post_templates_dropdown')) {
  • 549.
    function post_templates_dropdown() {
  • 550.
    	global $post;
  • 551.
    	$post_templates = get_post_templates();
  • 552.
    	
  • 553.
    	foreach ($post_templates as $template_name => $template_file) { //loop through templates, make them options
  • 554.
    		if ($template_file == get_post_meta($post->ID, '_wp_post_template', true)) { $selected = ' selected="selected"'; } else { $selected = ''; }
  • 555.
    		$opt = '<option value="' . $template_file . '"' . $selected . '>' . $template_name . '</option>';
  • 556.
    		echo $opt;
  • 557.
    	}
  • 558.
    }}
  • 559.
     
  • 560.
    //	Filter the single template value, and replace it with
  • 561.
    //	the template chosen by the user, if they chose one.
  • 562.
    add_filter('single_template', 'get_post_template');
  • 563.
    if(!function_exists('get_post_template')) {
  • 564.
    function get_post_template($template) {
  • 565.
    	global $post;
  • 566.
    	$custom_field = get_post_meta($post->ID, '_wp_post_template', true);
  • 567.
    	if(!empty($custom_field) && file_exists(TEMPLATEPATH . "/{$custom_field}")) { 
  • 568.
    		$template = TEMPLATEPATH . "/{$custom_field}"; }
  • 569.
    	return $template;
  • 570.
    }}
  • 571.
     
  • 572.
    //	Everything below this is for adding the extra box
  • 573.
    //	to the post edit screen so the user can choose a template
  • 574.
     
  • 575.
    //	Adds a custom section to the Post edit screen
  • 576.
    add_action('admin_menu', 'pt_add_custom_box');
  • 577.
    function pt_add_custom_box() {
  • 578.
    	if(get_post_templates() && function_exists( 'add_meta_box' )) {
  • 579.
    		add_meta_box( 'pt_post_templates', __( 'Single Post Template', 'pt' ), 
  • 580.
    			'pt_inner_custom_box', 'post', 'normal', 'high' ); //add the boxes under the post
  • 581.
    	}
  • 582.
    }
  • 583.
       
  • 584.
    //	Prints the inner fields for the custom post/page section
  • 585.
    function pt_inner_custom_box() {
  • 586.
    	global $post;
  • 587.
    	// Use nonce for verification
  • 588.
    	echo '<input type="hidden" name="pt_noncename" id="pt_noncename" value="' . wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
  • 589.
    	// The actual fields for data entry
  • 590.
    	echo '<label class="hidden" for="post_template">' . __("Post Template", 'pt' ) . '</label><br />';
  • 591.
    	echo '<select name="_wp_post_template" id="post_template" class="dropdown">';
  • 592.
    	echo '<option value="">Default</option>';
  • 593.
    	post_templates_dropdown(); //get the options
  • 594.
    	echo '</select><br /><br />';
  • 595.
    	echo '<p>' . __("Some themes have custom templates you can use for single posts that might have additional features or custom layouts. If so, you'll see them above.", 'pt' ) . '</p><br />';
  • 596.
    }
  • 597.
     
  • 598.
    //	When the post is saved, saves our custom data
  • 599.
    add_action('save_post', 'pt_save_postdata', 1, 2); // save the custom fields
  • 600.
    function pt_save_postdata($post_id, $post) {
  • 601.
    	
  • 602.
    	// verify this came from the our screen and with proper authorization,
  • 603.
    	// because save_post can be triggered at other times
  • 604.
    	if ( !wp_verify_nonce( $_POST['pt_noncename'], plugin_basename(__FILE__) )) {
  • 605.
    	return $post->ID;
  • 606.
    	}
  • 607.
     
  • 608.
    	// Is the user allowed to edit the post or page?
  • 609.
    	if ( 'page' == $_POST['post_type'] ) {
  • 610.
    		if ( !current_user_can( 'edit_page', $post->ID ))
  • 611.
    		return $post->ID;
  • 612.
    	} else {
  • 613.
    		if ( !current_user_can( 'edit_post', $post->ID ))
  • 614.
    		return $post->ID;
  • 615.
    	}
  • 616.
     
  • 617.
    	// OK, we're authenticated: we need to find and save the data
  • 618.
    	
  • 619.
    	// We'll put the data into an array to make it easier to loop though and save
  • 620.
    	$mydata['_wp_post_template'] = $_POST['_wp_post_template'];
  • 621.
    	// Add values of $mydata as custom fields
  • 622.
    	foreach ($mydata as $key => $value) { //Let's cycle through the $mydata array!
  • 623.
    		if( $post->post_type == 'revision' ) return; //don't store custom data twice
  • 624.
    		$value = implode(',', (array)$value); //if $value is an array, make it a CSV (unlikely)
  • 625.
    		if(get_post_meta($post->ID, $key, FALSE)) { //if the custom field already has a value...
  • 626.
    			update_post_meta($post->ID, $key, $value); //...then just update the data
  • 627.
    		} else { //if the custom field doesn't have a value...
  • 628.
    			add_post_meta($post->ID, $key, $value);//...then add the data
  • 629.
    		}
  • 630.
    		if(!$value) delete_post_meta($post->ID, $key); //and delete if blank
  • 631.
    	}
  • 632.
    }
  • 633.
     
  • 634.
    //// Post format: links
  • 635.
    function catch_that_link() {
  • 636.
      global $post, $posts;
  • 637.
      $first_link = '';
  • 638.
      ob_start();
  • 639.
      ob_end_clean();
  • 640.
      $output = preg_match_all('/<a[\s]+[^>]*?href[\s]?=[\s\"\']+(.*?)[\"\']+.*?>([^<]+|.*?)?<\/a>/is', $post->post_content, $matches);
  • 641.
      $first_link = $matches [1] [0];
  • 642.
      if(empty($first_link)){ //Defines a default link
  • 643.
        $first_link = "<a href='http://www.some_default_link.com'>link text</a>";
  • 644.
      }
  • 645.
      return $first_link;
  • 646.
    }
  • 647.
     
  • 648.
    //// Post formats
  • 649.
    add_theme_support( 'post-formats', array( 'aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quotes', 'status', 'video' ) );
  • 650.
    // add post-formats to post_type 'page'
  • 651.
    add_post_type_support( 'page', 'post-formats' );
  • 652.
     
  • 653.
    // add post-formats to post_type 'my_custom_post_type'
  • 654.
    add_post_type_support( 'my_custom_post_type', 'post-formats' );
  • 655.
     
  • 656.
    //// Post thumbnails
  • 657.
    	if (function_exists('add_theme_support')) {
  • 658.
    	add_theme_support('post-thumbnails');
  • 659.
    		set_post_thumbnail_size(120, 90, true);
  • 660.
    		add_image_size('thmb-index', 225, 165, true);
  • 661.
    		add_image_size('thmb-portfolio', 307, 210, true);
  • 662.
    		add_image_size('thmb-sdbr-lst', 125, 75, true);
  • 663.
    		add_image_size('thmb-archive', 72, 72, true);
  • 664.
    }
  • 665.
     
  • 666.
    // Post views
  • 667.
        function getPostViews($postID){
  • 668.
            $count_key = 'post_views_count';
  • 669.
            $count = get_post_meta($postID, $count_key, true);
  • 670.
            if($count==''){
  • 671.
                delete_post_meta($postID, $count_key);
  • 672.
                add_post_meta($postID, $count_key, '0');
  • 673.
                return "0 View";
  • 674.
            } 
  • 675.
            if ($count == '1') {
  • 676.
            return $count.' View';
  • 677.
            } else {
  • 678.
            $count = number_format((int)$count);
  • 679.
            return $count.' Views';
  • 680.
           }
  • 681.
        }
  • 682.
        function setPostViews($postID) {
  • 683.
            $count_key = 'post_views_count';
  • 684.
            $count = get_post_meta($postID, $count_key, true);
  • 685.
            if($count==''){
  • 686.
                $count = 0;
  • 687.
                delete_post_meta($postID, $count_key);
  • 688.
                add_post_meta($postID, $count_key, '0');
  • 689.
            }else{
  • 690.
                $count++;
  • 691.
                update_post_meta($postID, $count_key, $count);
  • 692.
            }
  • 693.
        }
  • 694.
     
  • 695.
    remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
  • 696.
     
  • 697.
    // Home page menu link option
  • 698.
    function home_page_menu_args( $args ) {
  • 699.
    $args['show_home'] = true;
  • 700.
    return $args;
  • 701.
    }
  • 702.
    add_filter( 'wp_page_menu_args', 'home_page_menu_args' );
  • 703.
     
  • 704.
    // Register sidebar
  • 705.
      // REGISTER THE SIDBARS
  • 706.
      if (!function_exists( 'ideatree_widgets_init' )) {
  • 707.
       function ideatree_widgets_init() {
  • 708.
        register_sidebar(array(
  • 709.
          'name' => __( 'Primary Widget Area', 'ideatree' ), 
  • 710.
          'id' => 'primary-widget-area', 
  • 711.
          'description' => 'The primary widget area', 'ideatree', 
  • 712.
          'before_widget' => '<ul><li id="%1$s" class="widget-container %2$s">', 
  • 713.
          'after_widget' => '</li></ul>', 
  • 714.
          'before_title' => '<h3 class="widgettitle">', 
  • 715.
          'after_title' => '</h3>',)
  • 716.
          );
  • 717.
        register_sidebar(array(
  • 718.
          'name' => 'Secondary Widget Area', 'ideatree', 
  • 719.
          'id' => 'secondary-widget-area', 
  • 720.
          'description' => 'The secondary widget area', 'ideatree', 
  • 721.
          'before_widget' => '<ul><li id="%1$s" class="widget-container %2$s">', 
  • 722.
          'after_widget' => '</li></ul>', 
  • 723.
          'before_title' => '<h3 class="widgettitle">', 
  • 724.
          'after_title' => '</h3>',)
  • 725.
          );
  • 726.
     
  • 727.
          }
  • 728.
        add_action('widgets_init', 'ideatree_widgets_init');
  • 729.
        }
  • 730.
     
  • 731.
    // Portfolio Excerpt Length
  • 732.
    class Excerpt {
  • 733.
     
  • 734.
      // Default length (by WordPress)
  • 735.
      public static $length = 25;
  • 736.
     
  • 737.
      // So you can call: my_excerpt('short');
  • 738.
      public static $types = array(
  • 739.
          'short' => 5,
  • 740.
          'regular' => 25,
  • 741.
          'long' => 100
  • 742.
        );
  • 743.
     
  • 744.
      public static function length($new_length = 25) {
  • 745.
        Excerpt::$length = $new_length;
  • 746.
        add_filter('excerpt_length', 'Excerpt::new_length');
  • 747.
        Excerpt::output();
  • 748.
      }
  • 749.
      public static function new_length() {
  • 750.
        if( isset(Excerpt::$types[Excerpt::$length]) )
  • 751.
          return Excerpt::$types[Excerpt::$length];
  • 752.
        else
  • 753.
          return Excerpt::$length;
  • 754.
      }
  • 755.
      public static function output() {
  • 756.
        the_excerpt();
  • 757.
      }
  • 758.
    }
  • 759.
     
  • 760.
    // An alias to the class
  • 761.
    function my_excerpt($length = 25) {
  • 762.
      Excerpt::length($length);
  • 763.
    }
  • 764.
     
  • 765.
    // Highlight category while viewing a single post
  • 766.
    function show_active_category($text) {
  • 767.
    	global $post;
  • 768.
    	if( is_single() || is_category() ) {
  • 769.
    		$categories = wp_get_post_categories($post->ID);
  • 770.
    		foreach( $categories as $catid ) {
  • 771.
    			$cat = get_category($catid);
  • 772.
    			if(preg_match('#>' . $cat->name . '</a>#', $text)) {
  • 773.
    				$text = str_replace('>' . $cat->name . '</a>', ' class="active_category">' . $cat->name . '</a>', $text);
  • 774.
    			}
  • 775.
    		}
  • 776.
    	}
  • 777.
    	return $text;
  • 778.
    }
  • 779.
    add_filter('wp_nav_menu', 'show_active_category');
  • 780.
     
  • 781.
    // Excerpt
  • 782.
    // Changing excerpt length
  • 783.
    function new_excerpt_length($length) {
  • 784.
    	return 15;
  • 785.
    }
  • 786.
    add_filter('excerpt_length', 'new_excerpt_length');
  • 787.
     
  • 788.
    // Changing excerpt more
  • 789.
    function new_excerpt_more($post) {
  • 790.
    	return ' <a class="read_more" href="'. get_permalink($post->ID) . '">' . 'read more' . '</a>';
  • 791.
    }
  • 792.
    add_filter('excerpt_more', 'new_excerpt_more'); 
  • 793.
     
  • 794.
    // Thumbnails
  • 795.
    // Enable post thumbnails
  • 796.
    add_theme_support( 'post-thumbnails' );
  • 797.
     
  • 798.
    // Post thumbnail width x height
  • 799.
    set_post_thumbnail_size( 200, 166, true );
  • 800.
     
  • 801.
    // Help block hack attempts
  • 802.
    global $user_ID; if($user_ID) {  
  • 803.
        if(!current_user_can('level_10')) {  
  • 804.
            if (strlen($_SERVER['REQUEST_URI']) > 255 ||  
  • 805.
                strpos($_SERVER['REQUEST_URI'], "eval(") ||  
  • 806.
                strpos($_SERVER['REQUEST_URI'], "CONCAT") ||  
  • 807.
                strpos($_SERVER['REQUEST_URI'], "UNION SELECT") ||  
  • 808.
                strpos($_SERVER['REQUEST_URI'], "base64")) {  
  • 809.
                    @header("HTTP/1.1 414 Request-URI Too Long");  
  • 810.
                    @header("Status: 414 Request-URI Too Long");  
  • 811.
                    @header("Connection: Close");  
  • 812.
                    @exit;  
  • 813.
            }  
  • 814.
        }  
  • 815.
    }
  • 816.
     
  • 817.
    // Elevate parent category
  • 818.
    function get_category_title($node) {
  • 819.
    	global $wpdb;
  • 820.
    	$test = $wpdb->get_var("SELECT name FROM $wpdb->terms WHERE term_id=$node");
  • 821.
    	return $test;
  • 822.
    }
  • 823.
     
  • 824.
    function get_category_child() {
  • 825.
    	global $wp_query;
  • 826.
    	return $wp_query->query_vars['cat_child'];
  • 827.
    }
  • 828.
     
  • 829.
    function is_parent() {
  • 830.
    	global $wp_query;
  • 831.
    	if ((get_category_parent($wp_query->query_vars['cat']) == 0) && (empty($wp_query->query_vars['cat_child']))) {
  • 832.
    		return true;
  • 833.
    	} else {
  • 834.
    		return false;
  • 835.
    	}
  • 836.
    }
  • 837.
     
  • 838.
    function get_category_parent($node) {
  • 839.
    	$path = get_category_path($node);
  • 840.
     
  • 841.
    	if (empty($path)) {
  • 842.
    		return 0;
  • 843.
    	} else {
  • 844.
    		return $path[0];
  • 845.
    	}
  • 846.
    }
  • 847.
     
  • 848.
    function get_category_path($node) {
  • 849.
    	global $wpdb;
  • 850.
     
  • 851.
    	$parent = $wpdb->get_var("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id=$node");
  • 852.
    	$path = array();
  • 853.
    	
  • 854.
    	if ($parent != 0) {
  • 855.
    		$path[] = $parent;
  • 856.
    		
  • 857.
    		$path = array_merge(get_category_path($parent), $path);
  • 858.
    	} 
  • 859.
    	
  • 860.
    	return $path;
  • 861.
     
  • 862.
    }
  • 863.
     
  • 864.
    function epct_redirect() {
  • 865.
    	global $wp_query;
  • 866.
     
  • 867.
    	if (is_category()) {
  • 868.
    		$childcat = $wp_query->query_vars['cat']; 
  • 869.
    		$parent = get_category_parent($childcat);
  • 870.
    		
  • 871.
    		if ($parent != 0) {
  • 872.
    			$wp_query->query_vars['cat_child'] = $childcat;
  • 873.
    			$wp_query->query_vars['cat'] = $parent;
  • 874.
    		}
  • 875.
    	}
  • 876.
     
  • 877.
    //	print_r($wp_query->query_vars);
  • 878.
    }
  • 879.
     
  • 880.
    add_action('template_redirect', 'epct_redirect');
  • 881.
     
  • 882.
    // Theme Options
  • 883.
    $themename = "Theme Options";
  • 884.
    $shortname = "to";
  • 885.
     
  • 886.
    $categories = get_categories('hide_empty=0&orderby=name');
  • 887.
    $wp_cats = array();
  • 888.
    foreach ($categories as $category_list ) {
  • 889.
           $wp_cats[$category_list->cat_ID] = $category_list->cat_name;
  • 890.
    }
  • 891.
    array_unshift($wp_cats, "Choose a category"); 
  • 892.
     
  • 893.
    $options = array (
  • 894.
     
  • 895.
    array( "name" => $themename." Options",
  • 896.
    	"type" => "title"),
  • 897.
     
  • 898.
    array( "name" => "General",
  • 899.
    	"type" => "section"),
  • 900.
    array( "type" => "open"),	
  • 901.
     
  • 902.
    array( "name" => "Logo URL",
  • 903.
    	"desc" => "Enter the link to your logo image",
  • 904.
    	"id" => $shortname."_logo",
  • 905.
    	"type" => "text",
  • 906.
    	"std" => ""),
  • 907.
     
  • 908.
    array( "name" => "Custom Favicon",
  • 909.
    	"desc" => "A favicon is a 16x16 pixel icon that represents your site; paste the URL to a .ico image that you want to use as your site's icon.",
  • 910.
    	"id" => $shortname."_favicon",
  • 911.
    	"type" => "text",
  • 912.
    	"std" => get_bloginfo('url') ."/favicon.ico"),	
  • 913.
     
  • 914.
    array( "name" => "Paginate or next/previous links?", 
  • 915.
        "desc" => "Choose your option", 
  • 916.
        "id" => $shortname."_next_prev_or_paginate", 
  • 917.
        "type" => "select", 
  • 918.
        "options" => array("Next/Previous Links", "Pagination"), 
  • 919.
        "std" => "Next/Previous Links"), 
  • 920.
     
  • 921.
    array( "name" => "Header Code",
  • 922.
    	"desc" => "Paste codes that belong in the header here.  You can put your Google Analytics or other tracking code in this box.",
  • 923.
    	"id" => $shortname."_hdr_code",
  • 924.
    	"type" => "textarea",
  • 925.
    	"std" => ""),
  • 926.
     
  • 927.
    array( "type" => "close"),
  • 928.
    array( "name" => "SEO",
  • 929.
    	"type" => "section"),
  • 930.
    array( "type" => "open"),
  • 931.
     
  • 932.
    array( "name" => "Meta Keywords",  
  • 933.
        "desc" => "Enter meta keywords.",  
  • 934.
        "id" => $shortname."_meta_keywords",  
  • 935.
        "type" => "text",
  • 936.
        "std" => ""),
  • 937.
     
  • 938.
    array( "name" => "Meta Description",  
  • 939.
        "desc" => "Enter a meta description.",  
  • 940.
        "type" => "text",  
  • 941.
        "std" => ""),
  • 942.
     
  • 943.
    array( "type" => "close"),
  • 944.
    array( "name" => "Styling",
  • 945.
    	"type" => "section"),
  • 946.
    array( "type" => "open"),
  • 947.
     
  • 948.
    array( "name" => "Color Scheme",
  • 949.
    	"desc" => "Select the color scheme for the theme",
  • 950.
    	"id" => $shortname."_color_scheme",
  • 951.
    	"type" => "select",
  • 952.
    	"options" => array("blue", "red", "green"),
  • 953.
    	"std" => "blue"),
  • 954.
     
  • 955.
    array( "name" => "Child stylesheet",  
  • 956.
        "desc" => "Want to add any custom CSS code? Put it here. This overrides any other stylesheets.",  
  • 957.
        "id" => $shortname."_child_style",  
  • 958.
        "type" => "textarea",  
  • 959.
        "std" => ""),
  • 960.
    	
  • 961.
    array( "name" => "Display breadcrumbs on post pages?",
  • 962.
    	"desc" => "Choose whether or not to display breadcrumbs, that is, the post trail.",
  • 963.
    	"id" => $shortname."_breadcrumbs",
  • 964.
    	"type" => "select",
  • 965.
    	"options" => array("Yes", "No"),
  • 966.
    	"std" => "Yes"),
  • 967.
     
  • 968.
    array( "name" => "Display post views?",
  • 969.
    	"desc" => "Choose whether or not to display post views.",
  • 970.
    	"id" => $shortname."_post_views",
  • 971.
    	"type" => "select",
  • 972.
    	"options" => array("Yes", "No"),
  • 973.
    	"std" => "Yes"),
  • 974.
     
  • 975.
    array( "name" => "Display comments on posts?",
  • 976.
    	"desc" => "Choose whether or not to display comments on posts.",
  • 977.
    	"id" => $shortname."_commentsd",
  • 978.
    	"type" => "select",
  • 979.
    	"options" => array("Yes", "No"),
  • 980.
    	"std" => "Yes"),	
  • 981.
     
  • 982.
    array( "type" => "close"),
  • 983.
    array( "name" => "Retrieving",
  • 984.
    	"type" => "section"),
  • 985.
    array( "type" => "open"),
  • 986.
     
  • 987.
    array( "name" => "Number of posts on homepage",  
  • 988.
        "desc" => "Choose the number of posts to display on your homepage.  Choose '#' for infinite posts.  Default will display the number of posts you have selected in your WordPress settings.",  
  • 989.
        "id" => $shortname."_count_home",  
  • 990.
    	"type" => "select",
  • 991.
    	"options" => array("Default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", "#"),
  • 992.
    	"std" => ""),
  • 993.
     
  • 994.
    array( "name" => "Homepage featured category",
  • 995.
    	"desc" => "Enter a category ID to pull posts from that category on the homepage",
  • 996.
    	"id" => $shortname."_cat_home",
  • 997.
    	"type" => "text",
  • 998.
    	"std" => ""),
  • 999.
     
  • 1000.
    array( "name" => "Number of posts on portfolio page",  
  • 1001.
        "desc" => "Choose the number of posts to display on portfolio pages.  Choose '#' for infinite posts.  Default will display the number of posts you have selected in your WordPress settings.",  
  • 1002.
        "id" => $shortname."_count_portfolio",  
  • 1003.
    	"type" => "select",
  • 1004.
    	"options" => array("Default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", "#"),
  • 1005.
    	"std" => ""),
  • 1006.
     
  • 1007.
    array( "name" => "Number of posts on category and archives pages",  
  • 1008.
        "desc" => "Choose the number of posts to display on category and archive pages.  Default will display the number of posts you have selected in your WordPress settings.",  
  • 1009.
        "id" => $shortname."_count_archives",  
  • 1010.
    	"type" => "select",
  • 1011.
    	"options" => array("Default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100"),
  • 1012.
    	"std" => ""),
  • 1013.
     
  • 1014.
    array( "name" => "Number of posts on search pages",  
  • 1015.
        "desc" => "Choose the number of posts to display on search archive pages.  Default will display the number of posts you have selected in your WordPress settings.",  
  • 1016.
        "id" => $shortname."_count_search",  
  • 1017.
    	"type" => "select",
  • 1018.
    	"options" => array("Default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100"),
  • 1019.
    	"std" => ""),
  • 1020.
     
  • 1021.
    array( "name" => "Number of tags in sidebar",  
  • 1022.
        "desc" => "Choose the number of posts to display on portfolio pages.  Default will display the number of posts you have selected in your WordPress settings.",  
  • 1023.
        "id" => $shortname."_count_tags",  
  • 1024.
    	"type" => "select",
  • 1025.
    	"options" => array("Default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100"),
  • 1026.
    	"std" => ""),
  • 1027.
     
  • 1028.
    array( "type" => "close"),
  • 1029.
    array( "name" => "Socials & Subscription Options",
  • 1030.
    	"type" => "section"),
  • 1031.
    array( "type" => "open"),
  • 1032.
     
  • 1033.
    array( "name" => "Facebook Page",
  • 1034.
    	"desc" => "Enter your Facebook address. (Must include http://)",
  • 1035.
    	"id" => $shortname."_facebook",
  • 1036.
    	"type" => "text",
  • 1037.
    	"std" => ""),
  • 1038.
     
  • 1039.
    array( "name" => "Google Plus",
  • 1040.
    	"desc" => "Enter your Google Plus address. (Must include http://)",
  • 1041.
    	"id" => $shortname."_google_plus",
  • 1042.
    	"type" => "text",
  • 1043.
    	"std" => ""),
  • 1044.
     
  • 1045.
    array( "name" => "Twitter Username",
  • 1046.
    	"desc" => "Enter your Twitter username.  This field determines the feed used for the built-in Twitter widget.",
  • 1047.
    	"id" => $shortname."_twitter_feed",
  • 1048.
    	"type" => "text",
  • 1049.
    	"std" => ""),
  • 1050.
     
  • 1051.
    array( "name" => "Mailing List",
  • 1052.
    	"desc" => "Enter your mailing list address.",
  • 1053.
    	"id" => $shortname."_mailing_list",
  • 1054.
    	"type" => "text",
  • 1055.
    	"std" => ""),
  • 1056.
     
  • 1057.
    array( "name" => "RSS URL",  
  • 1058.
        "desc" => "Paste your feed URL here.  Alternatively, post your Feedburner URL here.",  
  • 1059.
        "id" => $shortname."_feedburner",  
  • 1060.
        "type" => "text",  
  • 1061.
        "std" => get_bloginfo('rss2_url')),
  • 1062.
     
  • 1063.
    array( "type" => "close"),
  • 1064.
    array( "name" => "Contact Form",
  • 1065.
    	"type" => "section"),
  • 1066.
    array( "type" => "open"),
  • 1067.
     
  • 1068.
    array( "name" => "E-Mail",
  • 1069.
    	"desc" => "Enter the destination e-mail for your contact form",
  • 1070.
    	"id" => $shortname."_email",
  • 1071.
    	"type" => "text",
  • 1072.
    	"std" => ""),	
  • 1073.
     
  • 1074.
    array( "type" => "close"),
  • 1075.
    array( "name" => "Footer",
  • 1076.
    	"type" => "section"),
  • 1077.
    array( "type" => "open"),
  • 1078.
    	
  • 1079.
    array( "name" => "Footer Code",
  • 1080.
    	"desc" => "Paste codes that belong in the footer here.",
  • 1081.
    	"id" => $shortname."_ftr_code",
  • 1082.
    	"type" => "textarea",
  • 1083.
    	"std" => ""),	
  • 1084.
     
  • 1085.
    array( "type" => "close")
  • 1086.
    );
  • 1087.
     
  • 1088.
    function mytheme_add_admin() {
  • 1089.
     
  • 1090.
    global $themename, $shortname, $options;
  • 1091.
     
  • 1092.
    if ( $_GET['page'] == basename(__FILE__) ) {
  • 1093.
     
  • 1094.
    	if ( 'save' == $_REQUEST['action'] ) {
  • 1095.
     
  • 1096.
    		foreach ($options as $value) {
  • 1097.
    		update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
  • 1098.
     
  • 1099.
    foreach ($options as $value) {
  • 1100.
    	if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
  • 1101.
     
  • 1102.
    	header("Location: admin.php?page=functions.php&saved=true");
  • 1103.
    die;
  • 1104.
     
  • 1105.
    } 
  • 1106.
    else if( 'reset' == $_REQUEST['action'] ) {
  • 1107.
     
  • 1108.
    	foreach ($options as $value) {
  • 1109.
    		delete_option( $value['id'] ); }
  • 1110.
     
  • 1111.
    	header("Location: admin.php?page=functions.php&reset=true");
  • 1112.
    die;
  • 1113.
     
  • 1114.
    }
  • 1115.
    }
  • 1116.
     
  • 1117.
    add_menu_page($themename, $themename, 'administrator', basename(__FILE__), 'mytheme_admin');
  • 1118.
    }
  • 1119.
     
  • 1120.
    function mytheme_add_init() {
  • 1121.
     
  • 1122.
    $file_dir=get_bloginfo('template_directory');
  • 1123.
    wp_enqueue_style("functions", $file_dir."/functions/functions.css", false, "1.0", "all");
  • 1124.
    wp_enqueue_script("rm_script", $file_dir."/functions/rm_script.js", false, "1.0");
  • 1125.
     
  • 1126.
    }
  • 1127.
    function mytheme_admin() {
  • 1128.
     
  • 1129.
    global $themename, $shortname, $options;
  • 1130.
    $i=0;
  • 1131.
     
  • 1132.
    if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
  • 1133.
    if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
  • 1134.
     
  • 1135.
    ?>
  • 1136.
    <div class="wrap rm_wrap">
  • 1137.
    <h2><?php echo $themename; ?> Settings</h2>
  • 1138.
     
  • 1139.
    <div class="rm_opts">
  • 1140.
    <form method="post">
  • 1141.
    <?php foreach ($options as $value) {
  • 1142.
    switch ( $value['type'] ) {
  • 1143.
     
  • 1144.
    case "open":
  • 1145.
    ?>
  • 1146.
     
  • 1147.
    <?php break;
  • 1148.
    case "close":
  • 1149.
    ?>
  • 1150.
     
  • 1151.
    </div>
  • 1152.
    </div>
  • 1153.
    <br />
  • 1154.
     
  • 1155.
    <?php break;
  • 1156.
    case "title":
  • 1157.
    ?>
  • 1158.
    <p>To easily use the <?php echo $themename;?> theme, you can use the menu below.</p>
  • 1159.
     
  • 1160.
     
  • 1161.
    <?php break;
  • 1162.
    case 'text':
  • 1163.
    ?>
  • 1164.
     
  • 1165.
    <div class="rm_input rm_text">
  • 1166.
    	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  • 1167.
     	<input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id'])  ); } else { echo $value['std']; } ?>" />
  • 1168.
     <small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
  • 1169.
     
  • 1170.
     </div>
  • 1171.
    <?php
  • 1172.
    break;
  • 1173.
    case 'textarea':
  • 1174.
    ?>
  • 1175.
     
  • 1176.
    <div class="rm_input rm_textarea">
  • 1177.
    	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  • 1178.
     	<textarea name="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id']) ); } else { echo $value['std']; } ?></textarea>
  • 1179.
     <small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
  • 1180.
     
  • 1181.
     </div>
  • 1182.
      
  • 1183.
    <?php
  • 1184.
    break;
  • 1185.
    case 'select':
  • 1186.
    ?>
  • 1187.
     
  • 1188.
    <div class="rm_input rm_select">
  • 1189.
    	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  • 1190.
    	
  • 1191.
    <select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
  • 1192.
    <?php foreach ($value['options'] as $option) { ?>
  • 1193.
    		<option <?php if (get_settings( $value['id'] ) == $option) { echo 'selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?>
  • 1194.
    </select>
  • 1195.
     
  • 1196.
    	<small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
  • 1197.
    </div>
  • 1198.
    <?php
  • 1199.
    break;
  • 1200.
     
  • 1201.
    case "checkbox":
  • 1202.
    ?>
  • 1203.
     
  • 1204.
    <div class="rm_input rm_checkbox">
  • 1205.
    	<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  • 1206.
    	
  • 1207.
    <?php if(get_option($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = "";} ?>
  • 1208.
    <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
  • 1209.
     
  • 1210.
    	<small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
  • 1211.
     </div>
  • 1212.
    <?php break; 
  • 1213.
    case "section":
  • 1214.
    $i++;
  • 1215.
    ?>
  • 1216.
     
  • 1217.
    <div class="rm_section">
  • 1218.
    <div class="rm_title">
  • 1219.
    <h3><img class="inactive" alt="">
  • 1220.
    <?php echo $value['name']; ?></h3><span class="submit"><input name="save<?php echo $i; ?>" type="submit" value="Save changes" />
  • 1221.
    </span><div class="clearfix"></div></div>
  • 1222.
    <div class="rm_options">
  • 1223.
     
  • 1224.
    <?php break;
  • 1225.
     
  • 1226.
    }
  • 1227.
    }
  • 1228.
    ?>
  • 1229.
     
  • 1230.
    <input type="hidden" name="action" value="save" />
  • 1231.
    </form>
  • 1232.
    <form method="post">
  • 1233.
    <p class="submit">
  • 1234.
    <input name="reset" type="submit" value="Reset" />
  • 1235.
    <input type="hidden" name="action" value="reset" />
  • 1236.
    </p>
  • 1237.
    </form>
  • 1238.
     
  • 1239.
    <div style="font-size:1em; margin-bottom:10px;">Buy a theme: <a href="http://www.themeforward.com">ThemeForward</a></div>
  • 1240.
     </div> 
  • 1241.
     
  • 1242.
    <?php
  • 1243.
    }
  • 1244.
    ?>
  • 1245.
    <?php
  • 1246.
    add_action('admin_init', 'mytheme_add_init');
  • 1247.
    add_action('admin_menu', 'mytheme_add_admin');
  • 1248.
    ?>
<?php add_theme_support( 'custom-background' ); $defaults = array( 'default-image' => '', 'wp-head-callback' => '_custom_background_cb', 'admin-head-callback' => '', 'admin-preview-callback' => '' ); add_theme_support( 'custom-background', $defaults); // WP THEME CUSTOMIZER: START function wptuts_theme_customizer( $wp_customize ) { //// SECTION: LINKS $wp_customize->add_section( 'links', array( 'title' => 'Links', 'description' => 'Link settings', ) ); //// LINKS: Link Color $wp_customize->add_setting( 'link_color', array( 'default' => 'Hello world', // Default value ) ); $wp_customize->add_control( 'link_color', array( // Unique name to grab the code via PHP 'label' => 'Link Color', // Label // 'type' =>, // Default is "text", define the content type. 'section' => 'links', // ID of the section that this function belongs to ) ); // WP THEME CUSTOMIZER: LAST LINE } add_action( 'customize_register', 'wptuts_theme_customizer', 11 ); // Enque: jQuery if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11); function my_jquery_enqueue() { wp_deregister_script('jquery'); wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null); wp_enqueue_script('jquery'); } // WP_LINK_PAGES: Add prev and next links to a numbered link list add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add'); function wp_link_pages_args_prevnext_add($args) { global $page, $numpages, $more, $pagenow; $args['before'] = '<div id="link_wrap">'; $args['after'] = '</div>'; $args['link_before'] = '<span class="classlinks %s">'; $args['link_after'] = '</span>'; if($page-1) // there is a previous page $args['before'] .= ' '. _wp_link_page($page-1) . sprintf($args['link_before'],'prev') . $args['previouspagelink'] . $args['link_after'] . '</a>' . ' ' ; if ($page<$numpages) // there is a next page $args['after'] = ' '. _wp_link_page($page+1) . sprintf($args['link_before'],'next') . $args['nextpagelink'] . $args['link_after'] . '</a></div>' ; return $args; } // Custom Post Type: Portfolio add_action( 'init', 'register_cpt_portfolio' ); function register_cpt_portfolio() { $labels = array( 'name' => _x( 'Portfolio', 'portfolio' ), 'singular_name' => _x( 'Portfolio', 'portfolio' ), 'add_new' => _x( 'Add New', 'portfolio' ), 'add_new_item' => _x( 'Add New', 'portfolio' ), 'edit_item' => _x( 'Edit Portfolio', 'portfolio' ), 'new_item' => _x( 'New Portfolio', 'portfolio' ), 'view_item' => _x( 'View Portfolio', 'portfolio' ), 'search_items' => _x( 'Search Portfolio Projects', 'portfolio' ), 'not_found' => _x( 'No portfolio projects found', 'portfolio' ), 'not_found_in_trash' => _x( 'No portfolio projects found in Trash', 'portfolio' ), 'parent_item_colon' => _x( 'Parent Portfolio:', 'portfolio' ), 'menu_name' => _x( 'Portfolio', 'portfolio' ), ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'description' => 'Portfolio', 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ), 'taxonomies' => array( 'portfolio' ), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'has_archive' => true, 'query_var' => true, 'can_export' => true, 'rewrite' => true, 'capability_type' => 'post' ); register_post_type( 'portfolio', $args ); // Portfolio meta box add_action( 'admin_print_styles-post-new.php', 'portfolio_admin_style', 11 ); add_action( 'admin_print_styles-post.php', 'portfolio_admin_style', 11 ); // Portfolio meta box styles function portfolio_admin_style() { global $post_type; if( 'portfolio' == $post_type ) wp_enqueue_style( 'portfolio-admin-style', get_stylesheet_directory_uri() . '/styles/portfolio-admin.css' ); } } // Input fields add_action("admin_init", "add_portfolio"); add_action('save_post', 'update_website_url'); // Meta Box Title function add_portfolio(){ add_meta_box("portfolio_details", "Project Information", "portfolio_options", "portfolio", "normal", "low"); } // Create Custom Meta function portfolio_options(){ global $post; $custom = get_post_custom($post->ID); $website_url = $custom["website_url"][0]; $port_excerpt = $custom["port_excerpt"][0]; ?> // Meta Box HTML Markup <div id="portfolio-options"> <span><label>Website URL</label><input name="website_url" value="<?php echo $website_url; ?>" /></span> <span><label>Excerpt</label><input name="port_excerpt" value="<?php echo $port_excerpt; ?>" /></span> </div> <!--end portfolio-options--> <?php } function update_website_url(){ global $post; update_post_meta($post->ID, "website_url", $_POST["website_url"]); update_post_meta($post->ID, "port_excerpt", $_POST["port_excerpt"]); } add_filter("manage_edit-portfolio_columns", "portfolio_edit_columns"); add_action("manage_posts_custom_column", "portfolio_columns_display"); function portfolio_edit_columns($portfolio_columns){ $portfolio_columns = array( "cb" => "<input type=\"checkbox\" />", "title" => "Project Title", "description" => "Description", ); return $portfolio_columns; } function portfolio_columns_display($portfolio_columns){ switch ($portfolio_columns) { case "description": the_excerpt(); break; } } // Excerpt word count function excerpt_count_js(){ echo '<script>jQuery(document).ready(function(){ jQuery("#postexcerpt .handlediv").after("<div style=\"position:absolute;top:0px;right:5px;color:#666;\"><small>Excerpt length: </small><input type=\"text\" value=\"0\" maxlength=\"3\" size=\"3\" id=\"excerpt_counter\" readonly=\"\" style=\"background:#fff;\"> <small>word(s).</small></div>"); jQuery("#excerpt_counter").val(jQuery("#excerpt").val().split(/\S+\b[\s,\.\'-:;]*/).length - 1); jQuery("#excerpt").keyup( function() { jQuery("#excerpt_counter").val(jQuery("#excerpt").val().split(/\S+\b[\s,\.\'-:;]*/).length - 1); }); });</script>'; } add_action( 'admin_head-post.php', 'excerpt_count_js'); add_action( 'admin_head-post-new.php', 'excerpt_count_js'); // Quote format always a blockquote add_filter( 'the_content', 'my_quote_content' ); function my_quote_content( $content ) { /* Check if we're displaying a 'quote' post. */ if ( has_post_format( 'quote' ) ) { /* Match any <blockquote> elements. */ preg_match( '/<blockquote.*?>/', $content, $matches ); /* If no <blockquote> elements were found, wrap the entire content in one. */ if ( empty( $matches ) ) $content = "<blockquote>{$content}</blockquote>"; } return $content; } // Pagination function my_theme_navigation() { global $shortname; if( get_option( $shortname . '_next_prev_or_paginate' ) == 'Next/Previous Links' ) : // the block for next-prev navigation echo '<div class="left">'; next_posts_link('Older'); echo '</div>'; echo '<div class="right">'; previous_posts_link ('Newer'); echo '</div>'; else : // the block for pagination global $wp_query; $big = 999999999; // need an unlikely integer echo paginate_links( array( 'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ), 'format' => '?paged=%#%', 'end_size' => 1, 'mid_size' => 2, 'current' => max( 1, get_query_var('paged') ), 'total' => $wp_query->max_num_pages ) ); endif; } // Remove 10px caption margin add_filter( 'img_caption_shortcode', 'wap8_img_caption', 10, 3 ); function wap8_img_caption($nowt, $attr, $content) { extract( shortcode_atts( array( 'id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '', ), $attr ) ); if ( 1 > (int) $width || empty( $caption ) ) { return $content; } if ( $id ) $id = 'id="' . esc_attr( $id ) . '" '; return '<div ' . $id . 'class="wp-caption ' . esc_attr( $align ) . '" style="width:' . ( (int) $width ) . 'px;">' . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>'; } // Posts per page add_filter('parse_query', 'wpq_parse_query'); function wpq_parse_query($query) { if($query->is_archive()) { $query->query_vars['posts_per_page'] = get_option('to_count_archives', 10); } if($query->is_home()) { $query->query_vars['posts_per_page'] = get_option('to_count_home', 10); } if($query->is_search()) { $query->query_vars['posts_per_page'] = get_option('to_count_search', 10); } return $query; } // Profile fields: Add Twitter and Location add_action( 'show_user_profile', 'my_show_extra_profile_fields' ); add_action( 'edit_user_profile', 'my_show_extra_profile_fields' ); function my_show_extra_profile_fields( $user ) { ?> <h3>Extra profile information</h3> <table class="form-table"> <tr> <th><label for="twitter">Twitter</label></th> <td> <input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description">Where are you?</span> </td> </tr> <tr> <th><label for="location">Location</label></th> <td> <input type="text" name="location" id="location" value="<?php echo esc_attr( get_the_author_meta( 'location', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description">Please enter your Twitter username.</span> </td> </tr> </table> <?php } add_action( 'personal_options_update', 'my_save_extra_profile_fields' ); add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' ); function my_save_extra_profile_fields( $user_id ) { if ( !current_user_can( 'edit_user', $user_id ) ) return false; /* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */ update_usermeta( $user_id, 'twitter', $_POST['twitter'] ); update_usermeta( $user_id, 'location', $_POST['location'] ); } // Breadcrumbs function dimox_breadcrumbs() { $delimiter = '<span class="crumbdivider">&raquo;</span>'; $home = 'Home'; // text for the 'Home' link $before = '<span class="current">'; // tag before the current crumb $after = '</span>'; // tag after the current crumb if ( !is_home() && !is_front_page() || is_paged() ) { echo '<div id="crumbs">'; global $post; $homeLink = get_bloginfo('url'); echo '<a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' '; if ( is_category() ) { global $wp_query; $cat_obj = $wp_query->get_queried_object(); $thisCat = $cat_obj->term_id; $thisCat = get_category($thisCat); $parentCat = get_category($thisCat->parent); if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' ')); echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after; } elseif ( is_day() ) { echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' '; echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' '; echo $before . get_the_time('d') . $after; } elseif ( is_month() ) { echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' '; echo $before . get_the_time('F') . $after; } elseif ( is_year() ) { echo $before . get_the_time('Y') . $after; } elseif ( is_single() && !is_attachment() ) { if ( get_post_type() != 'post' ) { $post_type = get_post_type_object(get_post_type()); $slug = $post_type->rewrite; echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' '; echo $before . get_the_title() . $after; } else { $cat = get_the_category(); $cat = $cat[0]; echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' '); echo $before . get_the_title() . $after; } } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) { $post_type = get_post_type_object(get_post_type()); echo $before . $post_type->labels->singular_name . $after; } elseif ( is_attachment() ) { $parent = get_post($post->post_parent); $cat = get_the_category($parent->ID); $cat = $cat[0]; echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' '); echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' '; echo $before . get_the_title() . $after; } elseif ( is_page() && !$post->post_parent ) { echo $before . get_the_title() . $after; } elseif ( is_page() && $post->post_parent ) { $parent_id = $post->post_parent; $breadcrumbs = array(); while ($parent_id) { $page = get_page($parent_id); $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>'; $parent_id = $page->post_parent; } $breadcrumbs = array_reverse($breadcrumbs); foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' '; echo $before . get_the_title() . $after; } elseif ( is_search() ) { echo $before . 'Search results for "' . get_search_query() . '"' . $after; } elseif ( is_tag() ) { echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after; } elseif ( is_author() ) { global $author; $userdata = get_userdata($author); echo $before . 'Articles posted by ' . $userdata->display_name . $after; } elseif ( is_404() ) { echo $before . 'Error 404' . $after; } if ( get_query_var('paged') ) { if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' ('; echo __('Page') . ' ' . get_query_var('paged'); if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')'; } echo '</div>'; } } // end dimox_breadcrumbs() // Shortcode: Obfuscate e-mail addresses function cwc_mail_shortcode( $atts , $content=null ) { for ($i = 0; $i < strlen($content); $i++) $encodedmail .= "&#" . ord($content[$i]) . ';'; return '<a href="mailto:'.$encodedmail.'">'.$encodedmail.'</a>'; } add_shortcode('mailto', 'cwc_mail_shortcode'); // Shortcode: Drop cap add_shortcode('dropcap', 'dropcap'); function dropcap($atts, $content = null) { extract(shortcode_atts(array('link' => '#'), $atts)); return '<span class="dropcap">' . do_shortcode($content) . '</span>'; } // Shortcode: Scroll to top function scrolltop() { return '<a class="btn" href="#wrap" title="Scroll to top">Scroll to top</a>'; } add_shortcode('scrolltop', 'scrolltop'); // Shortcode: PDF viewer function pdflink($attr, $content) { return '<a class="btn" href="http://docs.google.com/viewer?url=' . $attr['href'] . '">'.$content.'</a>'; } add_shortcode('pdf', 'pdflink'); // Shortcode: Buttons function btn($atts, $content = null) { extract(shortcode_atts(array('link' => '#', 'color' => '' , 'size' => 'large'), $atts)); return '<a class="btn '.$size.'" href="'.$link.'" style="background-color:'.$color.';"><span>' . do_shortcode($content) . '</span></a>'; } add_shortcode('btn', 'btn'); // Shortcode: total words function total_words() { global $wpdb; return $wpdb->get_var("SELECT SUM(LENGTH(post_content) - LENGTH(REPLACE(post_content, ' ', '')) + 1) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'"); } add_shortcode('totalwords', 'total_words'); // Shortcode: Two columns function two($atts, $content = null) { return ' <div class="two">'.$content.'</div> '; } function two_last($atts, $content = null) { return ' <div class="two-last">'.$content.'</div> <br class="clear" />'; } add_shortcode('two', 'two'); add_shortcode('two_last', 'two_last'); // Shortcode: Three columns function three($atts, $content = null) { return ' <div class="three">'.$content.'</div> '; } function three_last($atts, $content = null) { return ' <div class="three-last">'.$content.'</div> <br class="clear" />'; } add_shortcode('three', 'three'); add_shortcode('three_last', 'three_last'); // Shortcode: Four columns function four($atts, $content = null) { return ' <div class="four">'.$content.'</div> '; } function four_last($atts, $content = null) { return ' <div class="four-last">'.$content.'</div> <br class="clear" />'; } add_shortcode('four', 'four'); add_shortcode('four_last', 'four_last'); // Shortcode: Five columns function five($atts, $content = null) { return ' <div class="five">'.$content.'</div> '; } function five_last($atts, $content = null) { return ' <div class="five-last">'.$content.'</div> <br class="clear" />'; } add_shortcode('five', 'five'); add_shortcode('five_last', 'five_last'); // Shortcode: Six columns function six($atts, $content = null) { return ' <div class="six">'.$content.'</div> '; } function six_last($atts, $content = null) { return ' <div class="six-last">'.$content.'</div> <br class="clear" />'; } add_shortcode('six', 'six'); add_shortcode('six_last', 'six_last'); // Custom templates: post templates if(!function_exists('get_post_templates')) { function get_post_templates() { $themes = get_themes(); $theme = get_current_theme(); $templates = $themes[$theme]['Template Files']; $post_templates = array(); $base = array(trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory())); foreach ((array)$templates as $template) { $template = WP_CONTENT_DIR . str_replace(WP_CONTENT_DIR, '', $template); $basename = str_replace($base, '', $template); // don't allow template files in subdirectories if (false !== strpos($basename, '/')) continue; $template_data = implode('', file( $template )); $name = ''; if (preg_match( '|Single Post Template:(.*)$|mi', $template_data, $name)) $name = _cleanup_header_comment($name[1]); if (!empty($name)) { if(basename($template) != basename(__FILE__)) $post_templates[trim($name)] = $basename; } } return $post_templates; }} // build the dropdown items if(!function_exists('post_templates_dropdown')) { function post_templates_dropdown() { global $post; $post_templates = get_post_templates(); foreach ($post_templates as $template_name => $template_file) { //loop through templates, make them options if ($template_file == get_post_meta($post->ID, '_wp_post_template', true)) { $selected = ' selected="selected"'; } else { $selected = ''; } $opt = '<option value="' . $template_file . '"' . $selected . '>' . $template_name . '</option>'; echo $opt; } }} // Filter the single template value, and replace it with // the template chosen by the user, if they chose one. add_filter('single_template', 'get_post_template'); if(!function_exists('get_post_template')) { function get_post_template($template) { global $post; $custom_field = get_post_meta($post->ID, '_wp_post_template', true); if(!empty($custom_field) && file_exists(TEMPLATEPATH . "/{$custom_field}")) { $template = TEMPLATEPATH . "/{$custom_field}"; } return $template; }} // Everything below this is for adding the extra box // to the post edit screen so the user can choose a template // Adds a custom section to the Post edit screen add_action('admin_menu', 'pt_add_custom_box'); function pt_add_custom_box() { if(get_post_templates() && function_exists( 'add_meta_box' )) { add_meta_box( 'pt_post_templates', __( 'Single Post Template', 'pt' ), 'pt_inner_custom_box', 'post', 'normal', 'high' ); //add the boxes under the post } } // Prints the inner fields for the custom post/page section function pt_inner_custom_box() { global $post; // Use nonce for verification echo '<input type="hidden" name="pt_noncename" id="pt_noncename" value="' . wp_create_nonce( plugin_basename(__FILE__) ) . '" />'; // The actual fields for data entry echo '<label class="hidden" for="post_template">' . __("Post Template", 'pt' ) . '</label><br />'; echo '<select name="_wp_post_template" id="post_template" class="dropdown">'; echo '<option value="">Default</option>'; post_templates_dropdown(); //get the options echo '</select><br /><br />'; echo '<p>' . __("Some themes have custom templates you can use for single posts that might have additional features or custom layouts. If so, you'll see them above.", 'pt' ) . '</p><br />'; } // When the post is saved, saves our custom data add_action('save_post', 'pt_save_postdata', 1, 2); // save the custom fields function pt_save_postdata($post_id, $post) { // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if ( !wp_verify_nonce( $_POST['pt_noncename'], plugin_basename(__FILE__) )) { return $post->ID; } // Is the user allowed to edit the post or page? if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post->ID )) return $post->ID; } else { if ( !current_user_can( 'edit_post', $post->ID )) return $post->ID; } // OK, we're authenticated: we need to find and save the data // We'll put the data into an array to make it easier to loop though and save $mydata['_wp_post_template'] = $_POST['_wp_post_template']; // Add values of $mydata as custom fields foreach ($mydata as $key => $value) { //Let's cycle through the $mydata array! if( $post->post_type == 'revision' ) return; //don't store custom data twice $value = implode(',', (array)$value); //if $value is an array, make it a CSV (unlikely) if(get_post_meta($post->ID, $key, FALSE)) { //if the custom field already has a value... update_post_meta($post->ID, $key, $value); //...then just update the data } else { //if the custom field doesn't have a value... add_post_meta($post->ID, $key, $value);//...then add the data } if(!$value) delete_post_meta($post->ID, $key); //and delete if blank } } //// Post format: links function catch_that_link() { global $post, $posts; $first_link = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<a[\s]+[^>]*?href[\s]?=[\s\"\']+(.*?)[\"\']+.*?>([^<]+|.*?)?<\/a>/is', $post->post_content, $matches); $first_link = $matches [1] [0]; if(empty($first_link)){ //Defines a default link $first_link = "<a href='http://www.some_default_link.com'>link text</a>"; } return $first_link; } //// Post formats add_theme_support( 'post-formats', array( 'aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quotes', 'status', 'video' ) ); // add post-formats to post_type 'page' add_post_type_support( 'page', 'post-formats' ); // add post-formats to post_type 'my_custom_post_type' add_post_type_support( 'my_custom_post_type', 'post-formats' ); //// Post thumbnails if (function_exists('add_theme_support')) { add_theme_support('post-thumbnails'); set_post_thumbnail_size(120, 90, true); add_image_size('thmb-index', 225, 165, true); add_image_size('thmb-portfolio', 307, 210, true); add_image_size('thmb-sdbr-lst', 125, 75, true); add_image_size('thmb-archive', 72, 72, true); } // Post views function getPostViews($postID){ $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); return "0 View"; } if ($count == '1') { return $count.' View'; } else { $count = number_format((int)$count); return $count.' Views'; } } function setPostViews($postID) { $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ $count = 0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); }else{ $count++; update_post_meta($postID, $count_key, $count); } } remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); // Home page menu link option function home_page_menu_args( $args ) { $args['show_home'] = true; return $args; } add_filter( 'wp_page_menu_args', 'home_page_menu_args' ); // Register sidebar // REGISTER THE SIDBARS if (!function_exists( 'ideatree_widgets_init' )) { function ideatree_widgets_init() { register_sidebar(array( 'name' => __( 'Primary Widget Area', 'ideatree' ), 'id' => 'primary-widget-area', 'description' => 'The primary widget area', 'ideatree', 'before_widget' => '<ul><li id="%1$s" class="widget-container %2$s">', 'after_widget' => '</li></ul>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>',) ); register_sidebar(array( 'name' => 'Secondary Widget Area', 'ideatree', 'id' => 'secondary-widget-area', 'description' => 'The secondary widget area', 'ideatree', 'before_widget' => '<ul><li id="%1$s" class="widget-container %2$s">', 'after_widget' => '</li></ul>', 'before_title' => '<h3 class="widgettitle">', 'after_title' => '</h3>',) ); } add_action('widgets_init', 'ideatree_widgets_init'); } // Portfolio Excerpt Length class Excerpt { // Default length (by WordPress) public static $length = 25; // So you can call: my_excerpt('short'); public static $types = array( 'short' => 5, 'regular' => 25, 'long' => 100 ); public static function length($new_length = 25) { Excerpt::$length = $new_length; add_filter('excerpt_length', 'Excerpt::new_length'); Excerpt::output(); } public static function new_length() { if( isset(Excerpt::$types[Excerpt::$length]) ) return Excerpt::$types[Excerpt::$length]; else return Excerpt::$length; } public static function output() { the_excerpt(); } } // An alias to the class function my_excerpt($length = 25) { Excerpt::length($length); } // Highlight category while viewing a single post function show_active_category($text) { global $post; if( is_single() || is_category() ) { $categories = wp_get_post_categories($post->ID); foreach( $categories as $catid ) { $cat = get_category($catid); if(preg_match('#>' . $cat->name . '</a>#', $text)) { $text = str_replace('>' . $cat->name . '</a>', ' class="active_category">' . $cat->name . '</a>', $text); } } } return $text; } add_filter('wp_nav_menu', 'show_active_category'); // Excerpt // Changing excerpt length function new_excerpt_length($length) { return 15; } add_filter('excerpt_length', 'new_excerpt_length'); // Changing excerpt more function new_excerpt_more($post) { return ' <a class="read_more" href="'. get_permalink($post->ID) . '">' . 'read more' . '</a>'; } add_filter('excerpt_more', 'new_excerpt_more'); // Thumbnails // Enable post thumbnails add_theme_support( 'post-thumbnails' ); // Post thumbnail width x height set_post_thumbnail_size( 200, 166, true ); // Help block hack attempts global $user_ID; if($user_ID) { if(!current_user_can('level_10')) { if (strlen($_SERVER['REQUEST_URI']) > 255 || strpos($_SERVER['REQUEST_URI'], "eval(") || strpos($_SERVER['REQUEST_URI'], "CONCAT") || strpos($_SERVER['REQUEST_URI'], "UNION SELECT") || strpos($_SERVER['REQUEST_URI'], "base64")) { @header("HTTP/1.1 414 Request-URI Too Long"); @header("Status: 414 Request-URI Too Long"); @header("Connection: Close"); @exit; } } } // Elevate parent category function get_category_title($node) { global $wpdb; $test = $wpdb->get_var("SELECT name FROM $wpdb->terms WHERE term_id=$node"); return $test; } function get_category_child() { global $wp_query; return $wp_query->query_vars['cat_child']; } function is_parent() { global $wp_query; if ((get_category_parent($wp_query->query_vars['cat']) == 0) && (empty($wp_query->query_vars['cat_child']))) { return true; } else { return false; } } function get_category_parent($node) { $path = get_category_path($node); if (empty($path)) { return 0; } else { return $path[0]; } } function get_category_path($node) { global $wpdb; $parent = $wpdb->get_var("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id=$node"); $path = array(); if ($parent != 0) { $path[] = $parent; $path = array_merge(get_category_path($parent), $path); } return $path; } function epct_redirect() { global $wp_query; if (is_category()) { $childcat = $wp_query->query_vars['cat']; $parent = get_category_parent($childcat); if ($parent != 0) { $wp_query->query_vars['cat_child'] = $childcat; $wp_query->query_vars['cat'] = $parent; } } // print_r($wp_query->query_vars); } add_action('template_redirect', 'epct_redirect'); // Theme Options $themename = "Theme Options"; $shortname = "to"; $categories = get_categories('hide_empty=0&orderby=name'); $wp_cats = array(); foreach ($categories as $category_list ) { $wp_cats[$category_list->cat_ID] = $category_list->cat_name; } array_unshift($wp_cats, "Choose a category"); $options = array ( array( "name" => $themename." Options", "type" => "title"), array( "name" => "General", "type" => "section"), array( "type" => "open"), array( "name" => "Logo URL", "desc" => "Enter the link to your logo image", "id" => $shortname."_logo", "type" => "text", "std" => ""), array( "name" => "Custom Favicon", "desc" => "A favicon is a 16x16 pixel icon that represents your site; paste the URL to a .ico image that you want to use as your site's icon.", "id" => $shortname."_favicon", "type" => "text", "std" => get_bloginfo('url') ."/favicon.ico"), array( "name" => "Paginate or next/previous links?", "desc" => "Choose your option", "id" => $shortname."_next_prev_or_paginate", "type" => "select", "options" => array("Next/Previous Links", "Pagination"), "std" => "Next/Previous Links"), array( "name" => "Header Code", "desc" => "Paste codes that belong in the header here. You can put your Google Analytics or other tracking code in this box.", "id" => $shortname."_hdr_code", "type" => "textarea", "std" => ""), array( "type" => "close"), array( "name" => "SEO", "type" => "section"), array( "type" => "open"), array( "name" => "Meta Keywords", "desc" => "Enter meta keywords.", "id" => $shortname."_meta_keywords", "type" => "text", "std" => ""), array( "name" => "Meta Description", "desc" => "Enter a meta description.", "type" => "text", "std" => ""), array( "type" => "close"), array( "name" => "Styling", "type" => "section"), array( "type" => "open"), array( "name" => "Color Scheme", "desc" => "Select the color scheme for the theme", "id" => $shortname."_color_scheme", "type" => "select", "options" => array("blue", "red", "green"), "std" => "blue"), array( "name" => "Child stylesheet", "desc" => "Want to add any custom CSS code? Put it here. This overrides any other stylesheets.", "id" => $shortname."_child_style", "type" => "textarea", "std" => ""), array( "name" => "Display breadcrumbs on post pages?", "desc" => "Choose whether or not to display breadcrumbs, that is, the post trail.", "id" => $shortname."_breadcrumbs", "type" => "select", "options" => array("Yes", "No"), "std" => "Yes"), array( "name" => "Display post views?", "desc" => "Choose whether or not to display post views.", "id" => $shortname."_post_views", "type" => "select", "options" => array("Yes", "No"), "std" => "Yes"), array( "name" => "Display comments on posts?", "desc" => "Choose whether or not to display comments on posts.", "id" => $shortname."_commentsd", "type" => "select", "options" => array("Yes", "No"), "std" => "Yes"), array( "type" => "close"), array( "name" => "Retrieving", "type" => "section"), array( "type" => "open"), array( "name" => "Number of posts on homepage", "desc" => "Choose the number of posts to display on your homepage. Choose '#' for infinite posts. Default will display the number of posts you have selected in your WordPress settings.", "id" => $shortname."_count_home", "type" => "select", "options" => array("Default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", "#"), "std" => ""), array( "name" => "Homepage featured category", "desc" => "Enter a category ID to pull posts from that category on the homepage", "id" => $shortname."_cat_home", "type" => "text", "std" => ""), array( "name" => "Number of posts on portfolio page", "desc" => "Choose the number of posts to display on portfolio pages. Choose '#' for infinite posts. Default will display the number of posts you have selected in your WordPress settings.", "id" => $shortname."_count_portfolio", "type" => "select", "options" => array("Default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", "#"), "std" => ""), array( "name" => "Number of posts on category and archives pages", "desc" => "Choose the number of posts to display on category and archive pages. Default will display the number of posts you have selected in your WordPress settings.", "id" => $shortname."_count_archives", "type" => "select", "options" => array("Default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100"), "std" => ""), array( "name" => "Number of posts on search pages", "desc" => "Choose the number of posts to display on search archive pages. Default will display the number of posts you have selected in your WordPress settings.", "id" => $shortname."_count_search", "type" => "select", "options" => array("Default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100"), "std" => ""), array( "name" => "Number of tags in sidebar", "desc" => "Choose the number of posts to display on portfolio pages. Default will display the number of posts you have selected in your WordPress settings.", "id" => $shortname."_count_tags", "type" => "select", "options" => array("Default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100"), "std" => ""), array( "type" => "close"), array( "name" => "Socials & Subscription Options", "type" => "section"), array( "type" => "open"), array( "name" => "Facebook Page", "desc" => "Enter your Facebook address. (Must include http://)", "id" => $shortname."_facebook", "type" => "text", "std" => ""), array( "name" => "Google Plus", "desc" => "Enter your Google Plus address. (Must include http://)", "id" => $shortname."_google_plus", "type" => "text", "std" => ""), array( "name" => "Twitter Username", "desc" => "Enter your Twitter username. This field determines the feed used for the built-in Twitter widget.", "id" => $shortname."_twitter_feed", "type" => "text", "std" => ""), array( "name" => "Mailing List", "desc" => "Enter your mailing list address.", "id" => $shortname."_mailing_list", "type" => "text", "std" => ""), array( "name" => "RSS URL", "desc" => "Paste your feed URL here. Alternatively, post your Feedburner URL here.", "id" => $shortname."_feedburner", "type" => "text", "std" => get_bloginfo('rss2_url')), array( "type" => "close"), array( "name" => "Contact Form", "type" => "section"), array( "type" => "open"), array( "name" => "E-Mail", "desc" => "Enter the destination e-mail for your contact form", "id" => $shortname."_email", "type" => "text", "std" => ""), array( "type" => "close"), array( "name" => "Footer", "type" => "section"), array( "type" => "open"), array( "name" => "Footer Code", "desc" => "Paste codes that belong in the footer here.", "id" => $shortname."_ftr_code", "type" => "textarea", "std" => ""), array( "type" => "close") ); function mytheme_add_admin() { global $themename, $shortname, $options; if ( $_GET['page'] == basename(__FILE__) ) { if ( 'save' == $_REQUEST['action'] ) { foreach ($options as $value) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } foreach ($options as $value) { if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } } header("Location: admin.php?page=functions.php&saved=true"); die; } else if( 'reset' == $_REQUEST['action'] ) { foreach ($options as $value) { delete_option( $value['id'] ); } header("Location: admin.php?page=functions.php&reset=true"); die; } } add_menu_page($themename, $themename, 'administrator', basename(__FILE__), 'mytheme_admin'); } function mytheme_add_init() { $file_dir=get_bloginfo('template_directory'); wp_enqueue_style("functions", $file_dir."/functions/functions.css", false, "1.0", "all"); wp_enqueue_script("rm_script", $file_dir."/functions/rm_script.js", false, "1.0"); } function mytheme_admin() { global $themename, $shortname, $options; $i=0; if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>'; if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>'; ?> <div class="wrap rm_wrap"> <h2><?php echo $themename; ?> Settings</h2> <div class="rm_opts"> <form method="post"> <?php foreach ($options as $value) { switch ( $value['type'] ) { case "open": ?> <?php break; case "close": ?> </div> </div> <br /> <?php break; case "title": ?> <p>To easily use the <?php echo $themename;?> theme, you can use the menu below.</p> <?php break; case 'text': ?> <div class="rm_input rm_text"> <label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label> <input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id']) ); } else { echo $value['std']; } ?>" /> <small><?php echo $value['desc']; ?></small><div class="clearfix"></div> </div> <?php break; case 'textarea': ?> <div class="rm_input rm_textarea"> <label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label> <textarea name="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo stripslashes(get_settings( $value['id']) ); } else { echo $value['std']; } ?></textarea> <small><?php echo $value['desc']; ?></small><div class="clearfix"></div> </div> <?php break; case 'select': ?> <div class="rm_input rm_select"> <label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label> <select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>"> <?php foreach ($value['options'] as $option) { ?> <option <?php if (get_settings( $value['id'] ) == $option) { echo 'selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?> </select> <small><?php echo $value['desc']; ?></small><div class="clearfix"></div> </div> <?php break; case "checkbox": ?> <div class="rm_input rm_checkbox"> <label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label> <?php if(get_option($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = "";} ?> <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> /> <small><?php echo $value['desc']; ?></small><div class="clearfix"></div> </div> <?php break; case "section": $i++; ?> <div class="rm_section"> <div class="rm_title"> <h3><img class="inactive" alt=""> <?php echo $value['name']; ?></h3><span class="submit"><input name="save<?php echo $i; ?>" type="submit" value="Save changes" /> </span><div class="clearfix"></div></div> <div class="rm_options"> <?php break; } } ?> <input type="hidden" name="action" value="save" /> </form> <form method="post"> <p class="submit"> <input name="reset" type="submit" value="Reset" /> <input type="hidden" name="action" value="reset" /> </p> </form> <div style="font-size:1em; margin-bottom:10px;">Buy a theme: <a href="http://www.themeforward.com">ThemeForward</a></div> </div> <?php } ?> <?php add_action('admin_init', 'mytheme_add_init'); add_action('admin_menu', 'mytheme_add_admin'); ?>

Copy Code to Clipboard Raw

Sign-in or Create a Free Account.

Snippi uses Twitter or Facebook to register and create accounts. Registration will enable you to keep track of your snippets. We never spam your timeline or wall. Ever.

Sign-in with Facebook Sign-in with Twitter