Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( isset($attachments[$k]) ) {
- $nav_link = wp_get_attachment_link($attachments[$k]->ID, $size, true, false, $text); // save in $nav_link instead of displaying with 'echo'
- }
- // This if statement has been added
- if (empty($nav_link) || $nav_link == __('Missing Attachment')) {
- // If a new version of WP has been released, check this code snippet to behave equivalent to function wp_get_attachment_link()
- // in post-template.php. Also the string 'Missing Attachment' has to be checked for changes.
- // $text = $text ? esc_attr($text) : ''; // this is simply the text which you set when calling lwy_previous_image_link() / lwy_next_image_link()
- $text = __('More Galleries', 'lwy_translate'); // display a fixed text like 'More Galleries'
- $title = __('Go to more galleries page', 'lwy_translate'); // the text which does popup when mouseover the link
- $gallery_page = '/link_to/more/galleries_page'; // !!! REPLACE WITH THE URL TO THE MORE GALLERIES PAGE !!!
- $nav_link = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $gallery_page, $title, $text);
- $nav_link = apply_filters( 'wp_get_attachment_link', $nav_link, $attachments[$k]->ID, $size, true, false, $text );
- }
- echo $nav_link;
- // 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>';
- }
- // 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' );
- }
- add_action('init', 'create_portfolio');
- function create_portfolio() {
- $portfolio_args = array(
- 'label' => __('Portfolio'),
- 'singular_label' => __('Portfolio'),
- 'public' => true,
- 'show_ui' => true,
- 'capability_type' => 'post',
- 'hierarchical' => false,
- 'rewrite' => true,
- 'supports' => array('title', 'editor', 'thumbnail')
- );
- register_post_type('portfolio',$portfolio_args);
- }
- // Input fields
- add_action("admin_init", "add_portfolio");
- add_action('save_post', 'update_website_url');
- function add_portfolio(){
- add_meta_box("portfolio_details", "Project Information", "portfolio_options", "portfolio", "normal", "low");
- }
- function portfolio_options(){
- global $post;
- $custom = get_post_custom($post->ID);
- $website_url = $custom["website_url"][0];
- $port_excerpt = $custom["port_excerpt"][0];
- ?>
- <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;
- }
- }
- // 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_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">»</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: Facebook Share
- function fbshare_script() { return '<div class="fbshare"><script type="text/javascript" src="http://widgets.fbshare.me/files/fbshare.js"></script></div>'; } add_shortcode( 'facebook', 'fbshare_script' );
- // Shortcode: Tweet Meme
- function tweetmeme(){
- return '<div class="tweetmeme"><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div>';
- }
- add_shortcode('tweet', 'tweetmeme');
- // 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 style="clear: both;" />';
- }
- 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 style="clear: both;" />';
- }
- 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 style="clear: both;" />';
- }
- 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 style="clear: both;" />';
- }
- 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 style="clear: both;" />';
- }
- 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
- }
- }
- // Gallery
- add_filter('gallery_style',
- create_function(
- '$css',
- 'return preg_replace("#<style type=\'text/css\'>(.*?)</style>#s", "", $css);'
- )
- );
- // Remove default gallery styling
- add_filter( 'use_default_gallery_style', '__return_false' );
- // Short URL/Tiny URL generation
- function getTinyUrl($url) {
- $tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
- return $tinyurl;
- }
- //// 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', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video', 'audio' ) );
- // 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', 200, 125, true);
- add_image_size('thmb-portfolio', 307, 210, true);
- add_image_size('thmb-sdbr-lst', 75, 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";
- }
- return $count.' ';
- }
- 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);
- }
- }
- // Disable Admin Bar
- add_filter( 'show_admin_bar', '__return_false' );
- remove_action( 'personal_options', '_admin_bar_preferences' );
- // Pagination
- function pagination($pages = '', $range = 4)
- {
- $showitems = ($range * 2)+1;
- global $paged;
- if(empty($paged)) $paged = 1;
- if($pages == '')
- {
- global $wp_query;
- $pages = $wp_query->max_num_pages;
- if(!$pages)
- {
- $pages = 1;
- }
- }
- if(1 != $pages)
- {
- echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
- if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>« First</a>";
- if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹ Previous</a>";
- for ($i=1; $i <= $pages; $i++)
- {
- if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
- {
- echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
- }
- }
- if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next ›</a>";
- if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last »</a>";
- echo "</div>\n";
- }
- }
- // 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 );
- // Grab and resize first image for additional thumbnails
- function catch_that_image() {
- global $post, $posts;
- $first_img = '';
- ob_start();
- ob_end_clean();
- $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
- $first_img = $matches [1] [0];
- if(empty($first_img)){ //Defines a default image
- $first_img = '';
- }
- return $first_img;
- }
- // 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');
- // Tag Map
- function wp_mcTagMap($options='') {
- $ns_options = array(
- "columns" => "2",
- "more" => "View More",
- "hide" => "no",
- "num_show" => "5",
- "toggle" => "no",
- "show_empty" => "yes",
- );
- if(strpos($options, '|')) {
- $options = explode("|",$options);
- } else {
- $options = explode("&",$options);
- }
- foreach ($options as $option) {
- $parts = explode("=",$option);
- $options[$parts[0]] = $parts[1];
- }
- if ($options['columns']) {
- $ns_options['columns'] = $options['columns'];
- } else {
- $options['columns'] = 2;
- }
- if ($options['more']) {
- $ns_options['more'] = htmlentities($options['more'], ENT_QUOTES);
- } else {
- $options['more'] = "View more";
- }
- if ($options['hide']) {
- $ns_options['hide'] = $options['hide'];
- } else {
- $options['hide'] = "no";
- }
- if ($options['num_show']) {
- $ns_options['num_show'] = $options['num_show'];
- } else {
- $options['num_show'] = 5;
- }
- if ($options['toggle']) {
- $ns_options['toggle'] = $options['toggle'];
- } else {
- $options['toggle'] = "no";
- }
- if ($options['show_empty']) {
- $ns_options['show_empty'] = $options['show_empty'];
- } else {
- $options['show_empty'] = "yes";
- }
- $show_empty = $options['show_empty'];
- if($show_empty == "yes"){
- $show_empty = "0";
- }
- if($show_empty == "no"){
- $show_empty = "1";
- }
- $list = '<!-- begin list --><div id="mcTagMap">';
- $tags = get_terms('post_tag', 'order=ASC&hide_empty='.$show_empty.''); // new code!
- $groups = array();
- if( $tags && is_array( $tags ) ) {
- foreach( $tags as $tag ) {
- $first_letter = strtoupper( $tag->name[0] );
- $groups[ $first_letter ][] = $tag;
- }
- if( !empty ( $groups ) ) {
- $count = 0;
- $howmany = count($groups);
- // this makes 2 columns
- if ($options['columns'] == 2){
- $firstrow = ceil($howmany * 0.5);
- $secondrow = ceil($howmany * 1);
- $firstrown1 = ceil(($howmany * 0.5)-1);
- $secondrown1 = ceil(($howmany * 1)-0);
- }
- //this makes 3 columns
- if ($options['columns'] == 3){
- $firstrow = ceil($howmany * 0.33);
- $secondrow = ceil($howmany * 0.66);
- $firstrown1 = ceil(($howmany * 0.33)-1);
- $secondrown1 = ceil(($howmany * 0.66)-1);
- }
- //this makes 4 columns
- if ($options['columns'] == 4){
- $firstrow = ceil($howmany * 0.25);
- $secondrow = ceil(($howmany * 0.5)+1);
- $firstrown1 = ceil(($howmany * 0.25)-1);
- $secondrown1 = ceil(($howmany * 0.5)-0);
- $thirdrow = ceil(($howmany * 0.75)-0);
- $thirdrow1 = ceil(($howmany * 0.75)-1);
- }
- //this makes 5 columns
- if ($options['columns'] == 5){
- $firstrow = ceil($howmany * 0.2);
- $firstrown1 = ceil(($howmany * 0.2)-1);
- $secondrow = ceil(($howmany * 0.4));
- $secondrown1 = ceil(($howmany * 0.4)-1);
- $thirdrow = ceil(($howmany * 0.6)-0);
- $thirdrow1 = ceil(($howmany * 0.6)-1);
- $fourthrow = ceil(($howmany * 0.8)-0);
- $fourthrow1 = ceil(($howmany * 0.8)-1);
- }
- foreach( $groups as $letter => $tags ) {
- if ($options['columns'] == 2){
- if ($count == 0 || $count == $firstrow || $count == $secondrow) {
- if ($count == $firstrow){
- $list .= "\n<div class='holdleft noMargin'>\n";
- $list .="\n";
- } else {
- $list .= "\n<div class='holdleft'>\n";
- $list .="\n";
- }
- }
- }
- if ($options['columns'] == 3){
- if ($count == 0 || $count == $firstrow || $count == $secondrow) {
- if ($count == $secondrow){
- $list .= "\n<div class='holdleft noMargin'>\n";
- $list .="\n";
- } else {
- $list .= "\n<div class='holdleft'>\n";
- $list .="\n";
- }
- }
- }
- if ($options['columns'] == 4){
- if ($count == 0 || $count == $firstrow || $count == $secondrow || $count == $thirdrow) {
- if ($count == $thirdrow){
- $list .= "\n<div class='holdleft noMargin'>\n";
- $list .="\n";
- } else {
- $list .= "\n<div class='holdleft'>\n";
- $list .="\n";
- }
- }
- }
- if ($options['columns'] == 5){
- if ($count == 0 || $count == $firstrow || $count == $secondrow || $count == $thirdrow || $count == $fourthrow ) {
- if ($count == $fourthrow){
- $list .= "\n<div class='holdleft noMargin'>\n";
- $list .="\n";
- } else {
- $list .= "\n<div class='holdleft'>\n";
- $list .="\n";
- }
- }
- }
- $list .= '<div class="tagindex">';
- $list .="\n";
- $list .='<h4>' . apply_filters( 'the_title', $letter ) . '</h4>';
- $list .="\n";
- $list .= '<ul class="links">';
- $list .="\n";
- $i = 0;
- foreach( $tags as $tag ) {
- $url = attribute_escape( get_tag_link( $tag->term_id ) );
- $name = apply_filters( 'the_title', $tag->name );
- // $name = ucfirst($name);
- $i++;
- $counti = $i;
- if ($options['hide'] == "yes"){
- $num2show = $options['num_show'];
- $num2show1 = ($options['num_show'] +1);
- $toggle = ($options['toggle']);
- if ($i != 0 and $i <= $num2show) {
- $list .= '<li><a title="' . $name . '" href="' . $url . '">' . $name . '</a></li>';
- $list .="\n";
- }
- if ($i > $num2show && $i == $num2show1 && $toggle == "no") {
- $list .= "<li class=\"morelink\">"."<a href=\"#x\" class=\"more\">".$options['more']."</a>"."</li>"."\n";
- }
- if ($i >= $num2show1){
- $list .= '<li class="hideli"><a title="' . $name . '" href="' . $url . '">' . $name . '</a></li>';
- $list .="\n";
- }
- } else {
- $list .= '<li><a title="' . $name . '" href="' . $url . '">' . $name . '</a></li>';
- $list .="\n";
- }
- }
- if ($options['hide'] == "yes" && $toggle != "no" && $i == $counti && $i > $num2show) {
- $list .= "<li class=\"morelink\">"."<a href=\"#x\" class=\"more\">".$options['more']."</a>"."<a href=\"#x\" class=\"less\">".$options['toggle']."</a>"."</li>"."\n";
- }
- $list .= '</ul>';
- $list .="\n";
- $list .= '</div>';
- $list .="\n\n";
- if ($options['columns'] == 3 || $options['columns'] == 2){
- if ( $count == $firstrown1 || $count == $secondrown1) {
- $list .= "</div>";
- }
- }
- if ($options['columns'] == 4){
- if ( $count == $firstrown1 || $count == $secondrown1 || $count == $thirdrow1) {
- $list .= "</div>";
- }
- }
- if ($options['columns'] == 5){
- if ( $count == $firstrown1 || $count == $secondrown1 || $count == $thirdrow1 || $count == $fourthrow1) {
- $list .= "</div>";
- }
- }
- $count++;
- }
- }
- $list .="</div>";
- $list .= "<div style='clear: both;'></div></div><!-- end list -->";
- }
- else $list .= '<p>Sorry, but no tags were found</p>';
- print $list ;
- }
- // end long code
- // short code begins
- function sc_mcTagMap($atts, $content = null) {
- extract(shortcode_atts(array(
- "columns" => "2",
- "more" => "View More",
- "hide" => "no",
- "num_show" => "5",
- "toggle" => "no",
- "show_empty" => "yes",
- ), $atts));
- if($show_empty == "yes"){
- $show_empty = "0";
- }
- if($show_empty == "no"){
- $show_empty = "1";
- }
- $list = '<!-- begin list --><div id="mcTagMap">';
- $tags = get_terms('post_tag', 'order=ASC&hide_empty='.$show_empty.''); // new code!
- $groups = array();
- if( $tags && is_array( $tags ) ) {
- foreach( $tags as $tag ) {
- $first_letter = strtoupper( $tag->name[0] );
- $groups[ $first_letter ][] = $tag;
- }
- if( !empty ( $groups ) ) {
- $count = 0;
- $howmany = count($groups);
- // this makes 2 columns
- if ($columns == 2){
- $firstrow = ceil($howmany * 0.5);
- $secondrow = ceil($howmany * 1);
- $firstrown1 = ceil(($howmany * 0.5)-1);
- $secondrown1 = ceil(($howmany * 1)-0);
- }
- //this makes 3 columns
- if ($columns == 3){
- $firstrow = ceil($howmany * 0.33);
- $secondrow = ceil($howmany * 0.66);
- $firstrown1 = ceil(($howmany * 0.33)-1);
- $secondrown1 = ceil(($howmany * 0.66)-1);
- }
- //this makes 4 columns
- if ($columns == 4){
- $firstrow = ceil($howmany * 0.25);
- $secondrow = ceil(($howmany * 0.5)+1);
- $firstrown1 = ceil(($howmany * 0.25)-1);
- $secondrown1 = ceil(($howmany * 0.5)-0);
- $thirdrow = ceil(($howmany * 0.75)-0);
- $thirdrow1 = ceil(($howmany * 0.75)-1);
- }
- //this makes 5 columns
- if ($columns == 5){
- $firstrow = ceil($howmany * 0.2);
- $firstrown1 = ceil(($howmany * 0.2)-1);
- $secondrow = ceil(($howmany * 0.4));
- $secondrown1 = ceil(($howmany * 0.4)-1);
- $thirdrow = ceil(($howmany * 0.6)-0);
- $thirdrow1 = ceil(($howmany * 0.6)-1);
- $fourthrow = ceil(($howmany * 0.8)-0);
- $fourthrow1 = ceil(($howmany * 0.8)-1);
- }
- foreach( $groups as $letter => $tags ) {
- if ($columns == 2){
- if ($count == 0 || $count == $firstrow || $count == $secondrow) {
- if ($count == $firstrow){
- $list .= "\n<div class='holdleft noMargin'>\n";
- $list .="\n";
- } else {
- $list .= "\n<div class='holdleft'>\n";
- $list .="\n";
- }
- }
- }
- if ($columns == 3){
- if ($count == 0 || $count == $firstrow || $count == $secondrow) {
- if ($count == $secondrow){
- $list .= "\n<div class='holdleft noMargin'>\n";
- $list .="\n";
- } else {
- $list .= "\n<div class='holdleft'>\n";
- $list .="\n";
- }
- }
- }
- if ($columns == 4){
- if ($count == 0 || $count == $firstrow || $count == $secondrow || $count == $thirdrow) {
- if ($count == $thirdrow){
- $list .= "\n<div class='holdleft noMargin'>\n";
- $list .="\n";
- } else {
- $list .= "\n<div class='holdleft'>\n";
- $list .="\n";
- }
- }
- }
- if ($columns == 5){
- if ($count == 0 || $count == $firstrow || $count == $secondrow || $count == $thirdrow || $count == $fourthrow ) {
- if ($count == $fourthrow){
- $list .= "\n<div class='holdleft noMargin'>\n";
- $list .="\n";
- } else {
- $list .= "\n<div class='holdleft'>\n";
- $list .="\n";
- }
- }
- }
- $list .= '<div class="tagindex">';
- $list .="\n";
- $list .='<h4>' . apply_filters( 'the_title', $letter ) . '</h4>';
- $list .="\n";
- $list .= '<ul class="links">';
- $list .="\n";
- $i = 0;
- foreach( $tags as $tag ) {
- $url = attribute_escape( get_tag_link( $tag->term_id ) );
- $name = apply_filters( 'the_title', $tag->name );
- // $name = ucfirst($name);
- $i++;
- $counti = $i;
- if ($hide == "yes"){
- $num2show = $num_show;
- $num2show1 = ($num_show +1);
- //$toggle = ($options['toggle']);
- if ($i != 0 and $i <= $num2show) {
- $list .= '<li><a title="' . $name . '" href="' . $url . '">' . $name . '</a></li>';
- $list .="\n";
- }
- if ($i > $num2show && $i == $num2show1 && $toggle == "no") {
- $list .= "<li class=\"morelink\">"."<a href=\"#x\" class=\"more\">".$more."</a>"."</li>"."\n";
- }
- if ($i >= $num2show1){
- $list .= '<li class="hideli"><a title="' . $name . '" href="' . $url . '">' . $name . '</a></li>';
- $list .="\n";
- }
- } else {
- $list .= '<li><a title="' . $name . '" href="' . $url . '">' . $name . '</a></li>';
- $list .="\n";
- }
- }
- if ($hide == "yes" && $toggle != "no" && $i == $counti && $i > $num2show) {
- $list .= "<li class=\"morelink\">"."<a href=\"#x\" class=\"more\">".$more."</a>"."<a href=\"#x\" class=\"less\">".$toggle."</a>"."</li>"."\n";
- }
- $list .= '</ul>';
- $list .="\n";
- $list .= '</div>';
- $list .="\n\n";
- if ($columns == 3 || $columns == 2){
- if ( $count == $firstrown1 || $count == $secondrown1) {
- $list .= "</div>";
- }
- }
- if ($columns == 4){
- if ( $count == $firstrown1 || $count == $secondrown1 || $count == $thirdrow1) {
- $list .= "</div>";
- }
- }
- if ($columns == 5){
- if ( $count == $firstrown1 || $count == $secondrown1 || $count == $thirdrow1 || $count == $fourthrow1) {
- $list .= "</div>";
- }
- }
- $count++;
- }
- }
- $list .="</div>";
- $list .= "<div style='clear: both;'></div></div><!-- end list -->";
- }
- else $list .= '<p>Sorry, but no tags were found</p>';
- return $list;
- }
- add_shortcode("mctagmap", "sc_mcTagMap");
- // end shortcode
- // the JS and CSS
- add_action('wp_head', 'mcTagMapCSSandJS');
- function mcTagMapCSSandJS()
- {
- if ($toggle == "no"){
- echo '<link rel="stylesheet" href="'.get_template_directory_uri().'/tagmap.css" type="text/css" media="screen" />';
- echo "\n\n";
- echo "<script type=\"text/javascript\">
- jQuery(document).ready(function() {
- jQuery('ul.links li.hideli').hide();
- jQuery('ul.links li.morelink').show();
- jQuery('a.more').click(function() {
- jQuery(this).parent().siblings('li.hideli').slideToggle('fast');
- jQuery(this).parent('li.morelink').remove();
- });
- });
- </script>\n\n";
- }
- if ($toggle != "no"){
- echo '<link rel="stylesheet" href="'.get_template_directory_uri().'/tagmap.css" type="text/css" media="screen" />';
- echo "\n\n";
- echo "<script type=\"text/javascript\">
- jQuery(document).ready(function() {
- jQuery('a.less').hide();
- jQuery('ul.links li.hideli').hide();
- jQuery('ul.links li.morelink').show();
- jQuery('a.more').click(function() {
- jQuery(this).parent().siblings('li.hideli').slideToggle('fast');
- jQuery(this).parent('li.morelink').children('a.less').show();
- jQuery(this).hide();
- });
- jQuery('a.less').click(function() {
- jQuery(this).parent().siblings('li.hideli').slideToggle('fast');
- jQuery(this).parent('li.morelink').children('a.more').show();
- jQuery(this).hide();
- });
- });
- </script>\n\n";
- }
- }
- // 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" => "Ad Big Blocks Code",
- "desc" => "Paste the code for your block ads here",
- "id" => $shortname."_ad_blocks",
- "type" => "textarea",
- "std" => ""),
- 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" => "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 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. 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. 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');
- ?>
Add Comment
Please, Sign In to add comment