Guest User

Untitled

a guest
Dec 23rd, 2011
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 54.87 KB | None | 0 0
  1. <?php
  2.  
  3. if ( isset($attachments[$k]) ) {
  4. $nav_link = wp_get_attachment_link($attachments[$k]->ID, $size, true, false, $text); // save in $nav_link instead of displaying with 'echo'
  5. }
  6. // This if statement has been added
  7. if (empty($nav_link) || $nav_link == __('Missing Attachment')) {
  8. // If a new version of WP has been released, check this code snippet to behave equivalent to function wp_get_attachment_link()
  9. // in post-template.php. Also the string 'Missing Attachment' has to be checked for changes.
  10.  
  11. // $text = $text ? esc_attr($text) : ''; // this is simply the text which you set when calling lwy_previous_image_link() / lwy_next_image_link()
  12. $text = __('More Galleries', 'lwy_translate'); // display a fixed text like 'More Galleries'
  13. $title = __('Go to more galleries page', 'lwy_translate'); // the text which does popup when mouseover the link
  14. $gallery_page = '/link_to/more/galleries_page'; // !!! REPLACE WITH THE URL TO THE MORE GALLERIES PAGE !!!
  15.  
  16. $nav_link = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', $gallery_page, $title, $text);
  17. $nav_link = apply_filters( 'wp_get_attachment_link', $nav_link, $attachments[$k]->ID, $size, true, false, $text );
  18. }
  19. echo $nav_link;
  20.  
  21. // Remove 10px caption margin
  22. add_filter( 'img_caption_shortcode', 'wap8_img_caption', 10, 3 );
  23. function wap8_img_caption($nowt, $attr, $content) {
  24. extract( shortcode_atts( array(
  25. 'id' => '',
  26. 'align' => 'alignnone',
  27. 'width' => '',
  28. 'caption' => '',
  29. ), $attr ) );
  30.  
  31. if ( 1 > (int) $width || empty( $caption ) ) {
  32. return $content;
  33. }
  34. if ( $id )
  35. $id = 'id="' . esc_attr( $id ) . '" ';
  36. 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>';
  37. }
  38.  
  39. // Portfolio meta box
  40. add_action( 'admin_print_styles-post-new.php', 'portfolio_admin_style', 11 );
  41. add_action( 'admin_print_styles-post.php', 'portfolio_admin_style', 11 );
  42.  
  43. // Portfolio meta box styles
  44. function portfolio_admin_style() {
  45. global $post_type;
  46. if( 'portfolio' == $post_type )
  47. wp_enqueue_style( 'portfolio-admin-style', get_stylesheet_directory_uri() . '/styles/portfolio-admin.css' );
  48. }
  49.  
  50. add_action('init', 'create_portfolio');
  51. function create_portfolio() {
  52. $portfolio_args = array(
  53. 'label' => __('Portfolio'),
  54. 'singular_label' => __('Portfolio'),
  55. 'public' => true,
  56. 'show_ui' => true,
  57. 'capability_type' => 'post',
  58. 'hierarchical' => false,
  59. 'rewrite' => true,
  60. 'supports' => array('title', 'editor', 'thumbnail')
  61. );
  62. register_post_type('portfolio',$portfolio_args);
  63. }
  64.  
  65. // Input fields
  66. add_action("admin_init", "add_portfolio");
  67. add_action('save_post', 'update_website_url');
  68. function add_portfolio(){
  69. add_meta_box("portfolio_details", "Project Information", "portfolio_options", "portfolio", "normal", "low");
  70. }
  71. function portfolio_options(){
  72. global $post;
  73. $custom = get_post_custom($post->ID);
  74. $website_url = $custom["website_url"][0];
  75. $port_excerpt = $custom["port_excerpt"][0];
  76. ?>
  77.  
  78. <div id="portfolio-options">
  79.  
  80. <span><label>Website URL</label><input name="website_url" value="<?php echo $website_url; ?>" /></span>
  81. <span><label>Excerpt</label><input name="port_excerpt" value="<?php echo $port_excerpt; ?>" /></span>
  82. </div>
  83. <!--end portfolio-options-->
  84. <?php
  85. }
  86. function update_website_url(){
  87. global $post;
  88. update_post_meta($post->ID, "website_url", $_POST["website_url"]);
  89. update_post_meta($post->ID, "port_excerpt", $_POST["port_excerpt"]);
  90. }
  91.  
  92. add_filter("manage_edit-portfolio_columns", "portfolio_edit_columns");
  93. add_action("manage_posts_custom_column", "portfolio_columns_display");
  94.  
  95. function portfolio_edit_columns($portfolio_columns){
  96. $portfolio_columns = array(
  97. "cb" => "<input type=\"checkbox\" />",
  98. "title" => "Project Title",
  99. "description" => "Description",
  100. );
  101. return $portfolio_columns;
  102. }
  103.  
  104. function portfolio_columns_display($portfolio_columns){
  105. switch ($portfolio_columns)
  106. {
  107. case "description":
  108. the_excerpt();
  109. break;
  110. }
  111. }
  112.  
  113. // Posts per page
  114. add_filter('parse_query', 'wpq_parse_query');
  115. function wpq_parse_query($query)
  116. {
  117. if($query->is_archive())
  118. {
  119. $query->query_vars['posts_per_page'] = get_option('to_count_archives', 10);
  120. }
  121. if($query->is_search())
  122. {
  123. $query->query_vars['posts_per_page'] = get_option('to_count_search', 10);
  124. }
  125. return $query;
  126. }
  127.  
  128.  
  129. // Profile fields: Add Twitter and Location
  130. add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
  131. add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
  132. function my_show_extra_profile_fields( $user ) { ?>
  133. <h3>Extra profile information</h3>
  134. <table class="form-table">
  135. <tr>
  136. <th><label for="twitter">Twitter</label></th>
  137. <td>
  138. <input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br />
  139. <span class="description">Where are you?</span>
  140. </td>
  141. </tr>
  142.  
  143. <tr>
  144. <th><label for="location">Location</label></th>
  145. <td>
  146. <input type="text" name="location" id="location" value="<?php echo esc_attr( get_the_author_meta( 'location', $user->ID ) ); ?>" class="regular-text" /><br />
  147. <span class="description">Please enter your Twitter username.</span>
  148. </td>
  149. </tr>
  150. </table>
  151. <?php }
  152.  
  153. add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
  154. add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
  155.  
  156. function my_save_extra_profile_fields( $user_id ) {
  157.  
  158. if ( !current_user_can( 'edit_user', $user_id ) )
  159. return false;
  160.  
  161. /* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
  162. update_usermeta( $user_id, 'twitter', $_POST['twitter'] );
  163. update_usermeta( $user_id, 'location', $_POST['location'] );
  164. }
  165.  
  166. // Breadcrumbs
  167. function dimox_breadcrumbs() {
  168. $delimiter = '<span class="crumbdivider">&raquo;</span>';
  169. $home = 'Home'; // text for the 'Home' link
  170. $before = '<span class="current">'; // tag before the current crumb
  171. $after = '</span>'; // tag after the current crumb
  172. if ( !is_home() && !is_front_page() || is_paged() ) {
  173. echo '<div id="crumbs">';
  174. global $post;
  175. $homeLink = get_bloginfo('url');
  176. echo '<a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' ';
  177. if ( is_category() ) {
  178. global $wp_query;
  179. $cat_obj = $wp_query->get_queried_object();
  180. $thisCat = $cat_obj->term_id;
  181. $thisCat = get_category($thisCat);
  182. $parentCat = get_category($thisCat->parent);
  183. if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
  184. echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after;
  185. } elseif ( is_day() ) {
  186. echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
  187. echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
  188. echo $before . get_the_time('d') . $after;
  189. } elseif ( is_month() ) {
  190. echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
  191. echo $before . get_the_time('F') . $after;
  192. } elseif ( is_year() ) {
  193. echo $before . get_the_time('Y') . $after;
  194. } elseif ( is_single() && !is_attachment() ) {
  195. if ( get_post_type() != 'post' ) {
  196. $post_type = get_post_type_object(get_post_type());
  197. $slug = $post_type->rewrite;
  198. echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' ';
  199. echo $before . get_the_title() . $after;
  200. } else {
  201. $cat = get_the_category(); $cat = $cat[0];
  202. echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
  203. echo $before . get_the_title() . $after;
  204. }
  205.  
  206. } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
  207. $post_type = get_post_type_object(get_post_type());
  208. echo $before . $post_type->labels->singular_name . $after;
  209.  
  210. } elseif ( is_attachment() ) {
  211. $parent = get_post($post->post_parent);
  212. $cat = get_the_category($parent->ID); $cat = $cat[0];
  213. echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
  214. echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
  215. echo $before . get_the_title() . $after;
  216.  
  217. } elseif ( is_page() && !$post->post_parent ) {
  218. echo $before . get_the_title() . $after;
  219.  
  220. } elseif ( is_page() && $post->post_parent ) {
  221. $parent_id = $post->post_parent;
  222. $breadcrumbs = array();
  223. while ($parent_id) {
  224. $page = get_page($parent_id);
  225. $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
  226. $parent_id = $page->post_parent;
  227. }
  228. $breadcrumbs = array_reverse($breadcrumbs);
  229. foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
  230. echo $before . get_the_title() . $after;
  231.  
  232. } elseif ( is_search() ) {
  233. echo $before . 'Search results for "' . get_search_query() . '"' . $after;
  234.  
  235. } elseif ( is_tag() ) {
  236. echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after;
  237.  
  238. } elseif ( is_author() ) {
  239. global $author;
  240. $userdata = get_userdata($author);
  241. echo $before . 'Articles posted by ' . $userdata->display_name . $after;
  242.  
  243. } elseif ( is_404() ) {
  244. echo $before . 'Error 404' . $after;
  245. }
  246.  
  247. if ( get_query_var('paged') ) {
  248. if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
  249. echo __('Page') . ' ' . get_query_var('paged');
  250. if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
  251. }
  252.  
  253. echo '</div>';
  254.  
  255. }
  256. } // end dimox_breadcrumbs()
  257.  
  258. // Shortcode: Facebook Share
  259. 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' );
  260.  
  261. // Shortcode: Tweet Meme
  262. function tweetmeme(){
  263. return '<div class="tweetmeme"><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div>';
  264. }
  265. add_shortcode('tweet', 'tweetmeme');
  266.  
  267. // Shortcode: Obfuscate e-mail addresses
  268. function cwc_mail_shortcode( $atts , $content=null ) {
  269. for ($i = 0; $i < strlen($content); $i++) $encodedmail .= "&#" . ord($content[$i]) . ';';
  270. return '<a href="mailto:'.$encodedmail.'">'.$encodedmail.'</a>';
  271. }
  272. add_shortcode('mailto', 'cwc_mail_shortcode');
  273.  
  274. // Shortcode: Drop cap
  275. add_shortcode('dropcap', 'dropcap');
  276. function dropcap($atts, $content = null) {
  277. extract(shortcode_atts(array('link' => '#'), $atts));
  278. return '<span class="dropcap">' . do_shortcode($content) . '</span>';
  279. }
  280.  
  281. // Shortcode: Scroll to top
  282. function scrolltop() {
  283. return '<a class="btn" href="#wrap" title="Scroll to top">Scroll to top</a>';
  284. }
  285.  
  286. add_shortcode('scrolltop', 'scrolltop');
  287.  
  288. // Shortcode: PDF viewer
  289. function pdflink($attr, $content) {
  290. return '<a class="btn" href="http://docs.google.com/viewer?url=' . $attr['href'] . '">'.$content.'</a>';
  291. }
  292. add_shortcode('pdf', 'pdflink');
  293.  
  294. // Shortcode: Buttons
  295. function btn($atts, $content = null) {
  296. extract(shortcode_atts(array('link' => '#', 'color' => '' , 'size' => 'large'), $atts));
  297. return '<a class="btn '.$size.'" href="'.$link.'" style="background-color:'.$color.';"><span>' . do_shortcode($content) . '</span></a>';
  298. }
  299. add_shortcode('btn', 'btn');
  300.  
  301. // Shortcode: total words
  302. function total_words() {
  303. global $wpdb;
  304. return $wpdb->get_var("SELECT SUM(LENGTH(post_content) - LENGTH(REPLACE(post_content, ' ', '')) + 1)
  305. FROM $wpdb->posts
  306. WHERE post_type = 'post'
  307. AND post_status = 'publish'");
  308. }
  309. add_shortcode('totalwords', 'total_words');
  310.  
  311. // Shortcode: Two columns
  312. function two($atts, $content = null) {
  313. return '
  314. <div class="two">'.$content.'</div>
  315. ';
  316. }
  317. function two_last($atts, $content = null) {
  318. return '
  319. <div class="two-last">'.$content.'</div>
  320. <br style="clear: both;" />';
  321. }
  322. add_shortcode('two', 'two');
  323. add_shortcode('two_last', 'two_last');
  324.  
  325. // Shortcode: Three columns
  326. function three($atts, $content = null) {
  327. return '
  328. <div class="three">'.$content.'</div>
  329. ';
  330. }
  331. function three_last($atts, $content = null) {
  332. return '
  333. <div class="three-last">'.$content.'</div>
  334. <br style="clear: both;" />';
  335. }
  336. add_shortcode('three', 'three');
  337. add_shortcode('three_last', 'three_last');
  338.  
  339. // Shortcode: Four columns
  340. function four($atts, $content = null) {
  341. return '
  342. <div class="four">'.$content.'</div>
  343. ';
  344. }
  345. function four_last($atts, $content = null) {
  346. return '
  347. <div class="four-last">'.$content.'</div>
  348. <br style="clear: both;" />';
  349. }
  350. add_shortcode('four', 'four');
  351. add_shortcode('four_last', 'four_last');
  352.  
  353. // Shortcode: Five columns
  354. function five($atts, $content = null) {
  355. return '
  356. <div class="five">'.$content.'</div>
  357. ';
  358. }
  359. function five_last($atts, $content = null) {
  360. return '
  361. <div class="five-last">'.$content.'</div>
  362. <br style="clear: both;" />';
  363. }
  364. add_shortcode('five', 'five');
  365. add_shortcode('five_last', 'five_last');
  366.  
  367. // Shortcode: Six columns
  368. function six($atts, $content = null) {
  369. return '
  370. <div class="six">'.$content.'</div>
  371. ';
  372. }
  373. function six_last($atts, $content = null) {
  374. return '
  375. <div class="six-last">'.$content.'</div>
  376. <br style="clear: both;" />';
  377. }
  378. add_shortcode('six', 'six');
  379. add_shortcode('six_last', 'six_last');
  380.  
  381. // Custom templates: post templates
  382. if(!function_exists('get_post_templates')) {
  383. function get_post_templates() {
  384. $themes = get_themes();
  385. $theme = get_current_theme();
  386. $templates = $themes[$theme]['Template Files'];
  387. $post_templates = array();
  388.  
  389. $base = array(trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()));
  390.  
  391. foreach ((array)$templates as $template) {
  392. $template = WP_CONTENT_DIR . str_replace(WP_CONTENT_DIR, '', $template);
  393. $basename = str_replace($base, '', $template);
  394.  
  395. // don't allow template files in subdirectories
  396. if (false !== strpos($basename, '/'))
  397. continue;
  398.  
  399. $template_data = implode('', file( $template ));
  400.  
  401. $name = '';
  402. if (preg_match( '|Single Post Template:(.*)$|mi', $template_data, $name))
  403. $name = _cleanup_header_comment($name[1]);
  404.  
  405. if (!empty($name)) {
  406. if(basename($template) != basename(__FILE__))
  407. $post_templates[trim($name)] = $basename;
  408. }
  409. }
  410.  
  411. return $post_templates;
  412.  
  413. }}
  414.  
  415. // build the dropdown items
  416. if(!function_exists('post_templates_dropdown')) {
  417. function post_templates_dropdown() {
  418. global $post;
  419. $post_templates = get_post_templates();
  420.  
  421. foreach ($post_templates as $template_name => $template_file) { //loop through templates, make them options
  422. if ($template_file == get_post_meta($post->ID, '_wp_post_template', true)) { $selected = ' selected="selected"'; } else { $selected = ''; }
  423. $opt = '<option value="' . $template_file . '"' . $selected . '>' . $template_name . '</option>';
  424. echo $opt;
  425. }
  426. }}
  427.  
  428. // Filter the single template value, and replace it with
  429. // the template chosen by the user, if they chose one.
  430. add_filter('single_template', 'get_post_template');
  431. if(!function_exists('get_post_template')) {
  432. function get_post_template($template) {
  433. global $post;
  434. $custom_field = get_post_meta($post->ID, '_wp_post_template', true);
  435. if(!empty($custom_field) && file_exists(TEMPLATEPATH . "/{$custom_field}")) {
  436. $template = TEMPLATEPATH . "/{$custom_field}"; }
  437. return $template;
  438. }}
  439.  
  440. // Everything below this is for adding the extra box
  441. // to the post edit screen so the user can choose a template
  442.  
  443. // Adds a custom section to the Post edit screen
  444. add_action('admin_menu', 'pt_add_custom_box');
  445. function pt_add_custom_box() {
  446. if(get_post_templates() && function_exists( 'add_meta_box' )) {
  447. add_meta_box( 'pt_post_templates', __( 'Single Post Template', 'pt' ),
  448. 'pt_inner_custom_box', 'post', 'normal', 'high' ); //add the boxes under the post
  449. }
  450. }
  451.  
  452. // Prints the inner fields for the custom post/page section
  453. function pt_inner_custom_box() {
  454. global $post;
  455. // Use nonce for verification
  456. echo '<input type="hidden" name="pt_noncename" id="pt_noncename" value="' . wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
  457. // The actual fields for data entry
  458. echo '<label class="hidden" for="post_template">' . __("Post Template", 'pt' ) . '</label><br />';
  459. echo '<select name="_wp_post_template" id="post_template" class="dropdown">';
  460. echo '<option value="">Default</option>';
  461. post_templates_dropdown(); //get the options
  462. echo '</select><br /><br />';
  463. 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 />';
  464. }
  465.  
  466. // When the post is saved, saves our custom data
  467. add_action('save_post', 'pt_save_postdata', 1, 2); // save the custom fields
  468. function pt_save_postdata($post_id, $post) {
  469.  
  470. // verify this came from the our screen and with proper authorization,
  471. // because save_post can be triggered at other times
  472. if ( !wp_verify_nonce( $_POST['pt_noncename'], plugin_basename(__FILE__) )) {
  473. return $post->ID;
  474. }
  475.  
  476. // Is the user allowed to edit the post or page?
  477. if ( 'page' == $_POST['post_type'] ) {
  478. if ( !current_user_can( 'edit_page', $post->ID ))
  479. return $post->ID;
  480. } else {
  481. if ( !current_user_can( 'edit_post', $post->ID ))
  482. return $post->ID;
  483. }
  484.  
  485. // OK, we're authenticated: we need to find and save the data
  486.  
  487. // We'll put the data into an array to make it easier to loop though and save
  488. $mydata['_wp_post_template'] = $_POST['_wp_post_template'];
  489. // Add values of $mydata as custom fields
  490. foreach ($mydata as $key => $value) { //Let's cycle through the $mydata array!
  491. if( $post->post_type == 'revision' ) return; //don't store custom data twice
  492. $value = implode(',', (array)$value); //if $value is an array, make it a CSV (unlikely)
  493. if(get_post_meta($post->ID, $key, FALSE)) { //if the custom field already has a value...
  494. update_post_meta($post->ID, $key, $value); //...then just update the data
  495. } else { //if the custom field doesn't have a value...
  496. add_post_meta($post->ID, $key, $value);//...then add the data
  497. }
  498. if(!$value) delete_post_meta($post->ID, $key); //and delete if blank
  499. }
  500. }
  501.  
  502. // Gallery
  503. add_filter('gallery_style',
  504. create_function(
  505. '$css',
  506. 'return preg_replace("#<style type=\'text/css\'>(.*?)</style>#s", "", $css);'
  507. )
  508. );
  509.  
  510. // Remove default gallery styling
  511. add_filter( 'use_default_gallery_style', '__return_false' );
  512.  
  513. // Short URL/Tiny URL generation
  514. function getTinyUrl($url) {
  515. $tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
  516. return $tinyurl;
  517. }
  518.  
  519. //// Post format: links
  520. function catch_that_link() {
  521. global $post, $posts;
  522. $first_link = '';
  523. ob_start();
  524. ob_end_clean();
  525. $output = preg_match_all('/<a[\s]+[^>]*?href[\s]?=[\s\"\']+(.*?)[\"\']+.*?>([^<]+|.*?)?<\/a>/is', $post->post_content, $matches);
  526. $first_link = $matches [1] [0];
  527. if(empty($first_link)){ //Defines a default link
  528. $first_link = "<a href='http://www.some_default_link.com'>link text</a>";
  529. }
  530. return $first_link;
  531. }
  532.  
  533. //// Post formats
  534. add_theme_support( 'post-formats', array( 'aside', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video', 'audio' ) );
  535. // add post-formats to post_type 'page'
  536. add_post_type_support( 'page', 'post-formats' );
  537.  
  538. // add post-formats to post_type 'my_custom_post_type'
  539. add_post_type_support( 'my_custom_post_type', 'post-formats' );
  540.  
  541. //// Post thumbnails
  542. if (function_exists('add_theme_support')) {
  543. add_theme_support('post-thumbnails');
  544. set_post_thumbnail_size(120, 90, true);
  545. add_image_size('thmb-index', 200, 125, true);
  546. add_image_size('thmb-portfolio', 307, 210, true);
  547. add_image_size('thmb-sdbr-lst', 75, 75, true);
  548. add_image_size('thmb-archive', 72, 72, true);
  549. }
  550.  
  551. // Post views
  552. function getPostViews($postID){
  553. $count_key = 'post_views_count';
  554. $count = get_post_meta($postID, $count_key, true);
  555. if($count==''){
  556. delete_post_meta($postID, $count_key);
  557. add_post_meta($postID, $count_key, '0');
  558. return "0";
  559. }
  560. return $count.' ';
  561. }
  562. function setPostViews($postID) {
  563. $count_key = 'post_views_count';
  564. $count = get_post_meta($postID, $count_key, true);
  565. if($count==''){
  566. $count = 0;
  567. delete_post_meta($postID, $count_key);
  568. add_post_meta($postID, $count_key, '0');
  569. }else{
  570. $count++;
  571. update_post_meta($postID, $count_key, $count);
  572. }
  573. }
  574.  
  575. // Disable Admin Bar
  576. add_filter( 'show_admin_bar', '__return_false' );
  577. remove_action( 'personal_options', '_admin_bar_preferences' );
  578.  
  579.  
  580. // Pagination
  581. function pagination($pages = '', $range = 4)
  582. {
  583. $showitems = ($range * 2)+1;
  584. global $paged;
  585. if(empty($paged)) $paged = 1;
  586. if($pages == '')
  587. {
  588. global $wp_query;
  589. $pages = $wp_query->max_num_pages;
  590. if(!$pages)
  591. {
  592. $pages = 1;
  593. }
  594. }
  595. if(1 != $pages)
  596. {
  597. echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
  598. if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
  599. if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";
  600.  
  601. for ($i=1; $i <= $pages; $i++)
  602. {
  603. if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
  604. {
  605. echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
  606. }
  607. }
  608.  
  609. if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";
  610. if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
  611. echo "</div>\n";
  612. }
  613. }
  614.  
  615. // Home page menu link option
  616. function home_page_menu_args( $args ) {
  617. $args['show_home'] = true;
  618. return $args;
  619. }
  620. add_filter( 'wp_page_menu_args', 'home_page_menu_args' );
  621.  
  622.  
  623. // Register sidebar
  624. // REGISTER THE SIDBARS
  625. if (!function_exists( 'ideatree_widgets_init' )) {
  626. function ideatree_widgets_init() {
  627. register_sidebar(array(
  628. 'name' => __( 'Primary Widget Area', 'ideatree' ),
  629. 'id' => 'primary-widget-area',
  630. 'description' => 'The primary widget area', 'ideatree',
  631. 'before_widget' => '<ul><li id="%1$s" class="widget-container %2$s">',
  632. 'after_widget' => '</li></ul>',
  633. 'before_title' => '<h3 class="widgettitle">',
  634. 'after_title' => '</h3>',)
  635. );
  636. register_sidebar(array(
  637. 'name' => 'Secondary Widget Area', 'ideatree',
  638. 'id' => 'secondary-widget-area',
  639. 'description' => 'The secondary widget area', 'ideatree',
  640. 'before_widget' => '<ul><li id="%1$s" class="widget-container %2$s">',
  641. 'after_widget' => '</li></ul>',
  642. 'before_title' => '<h3 class="widgettitle">',
  643. 'after_title' => '</h3>',)
  644. );
  645.  
  646. }
  647. add_action('widgets_init', 'ideatree_widgets_init');
  648. }
  649.  
  650. // Portfolio Excerpt Length
  651. class Excerpt {
  652.  
  653. // Default length (by WordPress)
  654. public static $length = 25;
  655.  
  656. // So you can call: my_excerpt('short');
  657. public static $types = array(
  658. 'short' => 5,
  659. 'regular' => 25,
  660. 'long' => 100
  661. );
  662.  
  663. public static function length($new_length = 25) {
  664. Excerpt::$length = $new_length;
  665. add_filter('excerpt_length', 'Excerpt::new_length');
  666. Excerpt::output();
  667. }
  668. public static function new_length() {
  669. if( isset(Excerpt::$types[Excerpt::$length]) )
  670. return Excerpt::$types[Excerpt::$length];
  671. else
  672. return Excerpt::$length;
  673. }
  674. public static function output() {
  675. the_excerpt();
  676. }
  677. }
  678.  
  679. // An alias to the class
  680. function my_excerpt($length = 25) {
  681. Excerpt::length($length);
  682. }
  683.  
  684. // Highlight category while viewing a single post
  685. function show_active_category($text) {
  686. global $post;
  687. if( is_single() || is_category() ) {
  688. $categories = wp_get_post_categories($post->ID);
  689. foreach( $categories as $catid ) {
  690. $cat = get_category($catid);
  691. if(preg_match('#>' . $cat->name . '</a>#', $text)) {
  692. $text = str_replace('>' . $cat->name . '</a>', ' class="active_category">' . $cat->name . '</a>', $text);
  693. }
  694. }
  695. }
  696. return $text;
  697. }
  698. add_filter('wp_nav_menu', 'show_active_category');
  699.  
  700. // Excerpt
  701. // Changing excerpt length
  702. function new_excerpt_length($length) {
  703. return 15;
  704. }
  705. add_filter('excerpt_length', 'new_excerpt_length');
  706.  
  707. // Changing excerpt more
  708. function new_excerpt_more($post) {
  709. return ' <a class="read_more" href="'. get_permalink($post->ID) . '">' . 'read more' . '</a>';
  710. }
  711. add_filter('excerpt_more', 'new_excerpt_more');
  712.  
  713. // Thumbnails
  714. // Enable post thumbnails
  715. add_theme_support( 'post-thumbnails' );
  716.  
  717. // Post thumbnail width x height
  718. set_post_thumbnail_size( 200, 166, true );
  719.  
  720. // Grab and resize first image for additional thumbnails
  721. function catch_that_image() {
  722. global $post, $posts;
  723. $first_img = '';
  724. ob_start();
  725. ob_end_clean();
  726. $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  727. $first_img = $matches [1] [0];
  728. if(empty($first_img)){ //Defines a default image
  729. $first_img = '';
  730. }
  731. return $first_img;
  732. }
  733.  
  734. // Help block hack attempts
  735. global $user_ID; if($user_ID) {
  736. if(!current_user_can('level_10')) {
  737. if (strlen($_SERVER['REQUEST_URI']) > 255 ||
  738. strpos($_SERVER['REQUEST_URI'], "eval(") ||
  739. strpos($_SERVER['REQUEST_URI'], "CONCAT") ||
  740. strpos($_SERVER['REQUEST_URI'], "UNION SELECT") ||
  741. strpos($_SERVER['REQUEST_URI'], "base64")) {
  742. @header("HTTP/1.1 414 Request-URI Too Long");
  743. @header("Status: 414 Request-URI Too Long");
  744. @header("Connection: Close");
  745. @exit;
  746. }
  747. }
  748. }
  749.  
  750. // Elevate parent category
  751. function get_category_title($node) {
  752. global $wpdb;
  753. $test = $wpdb->get_var("SELECT name FROM $wpdb->terms WHERE term_id=$node");
  754. return $test;
  755. }
  756.  
  757. function get_category_child() {
  758. global $wp_query;
  759. return $wp_query->query_vars['cat_child'];
  760. }
  761.  
  762. function is_parent() {
  763. global $wp_query;
  764. if ((get_category_parent($wp_query->query_vars['cat']) == 0) && (empty($wp_query->query_vars['cat_child']))) {
  765. return true;
  766. } else {
  767. return false;
  768. }
  769. }
  770.  
  771. function get_category_parent($node) {
  772. $path = get_category_path($node);
  773.  
  774. if (empty($path)) {
  775. return 0;
  776. } else {
  777. return $path[0];
  778. }
  779. }
  780.  
  781. function get_category_path($node) {
  782. global $wpdb;
  783.  
  784. $parent = $wpdb->get_var("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id=$node");
  785. $path = array();
  786.  
  787. if ($parent != 0) {
  788. $path[] = $parent;
  789.  
  790. $path = array_merge(get_category_path($parent), $path);
  791. }
  792.  
  793. return $path;
  794.  
  795. }
  796.  
  797. function epct_redirect() {
  798. global $wp_query;
  799.  
  800. if (is_category()) {
  801. $childcat = $wp_query->query_vars['cat'];
  802. $parent = get_category_parent($childcat);
  803.  
  804. if ($parent != 0) {
  805. $wp_query->query_vars['cat_child'] = $childcat;
  806. $wp_query->query_vars['cat'] = $parent;
  807. }
  808. }
  809.  
  810. // print_r($wp_query->query_vars);
  811. }
  812.  
  813. add_action('template_redirect', 'epct_redirect');
  814.  
  815. // Tag Map
  816. function wp_mcTagMap($options='') {
  817.  
  818. $ns_options = array(
  819. "columns" => "2",
  820. "more" => "View More",
  821. "hide" => "no",
  822. "num_show" => "5",
  823. "toggle" => "no",
  824. "show_empty" => "yes",
  825. );
  826.  
  827. if(strpos($options, '|')) {
  828. $options = explode("|",$options);
  829. } else {
  830. $options = explode("&",$options);
  831. }
  832.  
  833. foreach ($options as $option) {
  834.  
  835. $parts = explode("=",$option);
  836. $options[$parts[0]] = $parts[1];
  837.  
  838. }
  839.  
  840. if ($options['columns']) {
  841. $ns_options['columns'] = $options['columns'];
  842. } else {
  843. $options['columns'] = 2;
  844. }
  845.  
  846. if ($options['more']) {
  847. $ns_options['more'] = htmlentities($options['more'], ENT_QUOTES);
  848. } else {
  849. $options['more'] = "View more";
  850. }
  851.  
  852. if ($options['hide']) {
  853. $ns_options['hide'] = $options['hide'];
  854. } else {
  855. $options['hide'] = "no";
  856. }
  857.  
  858. if ($options['num_show']) {
  859. $ns_options['num_show'] = $options['num_show'];
  860. } else {
  861. $options['num_show'] = 5;
  862. }
  863.  
  864. if ($options['toggle']) {
  865. $ns_options['toggle'] = $options['toggle'];
  866. } else {
  867. $options['toggle'] = "no";
  868. }
  869.  
  870. if ($options['show_empty']) {
  871. $ns_options['show_empty'] = $options['show_empty'];
  872. } else {
  873. $options['show_empty'] = "yes";
  874. }
  875.  
  876. $show_empty = $options['show_empty'];
  877. if($show_empty == "yes"){
  878. $show_empty = "0";
  879. }
  880. if($show_empty == "no"){
  881. $show_empty = "1";
  882. }
  883. $list = '<!-- begin list --><div id="mcTagMap">';
  884. $tags = get_terms('post_tag', 'order=ASC&hide_empty='.$show_empty.''); // new code!
  885. $groups = array();
  886.  
  887. if( $tags && is_array( $tags ) ) {
  888. foreach( $tags as $tag ) {
  889. $first_letter = strtoupper( $tag->name[0] );
  890. $groups[ $first_letter ][] = $tag;
  891. }
  892. if( !empty ( $groups ) ) {
  893. $count = 0;
  894. $howmany = count($groups);
  895.  
  896. // this makes 2 columns
  897. if ($options['columns'] == 2){
  898. $firstrow = ceil($howmany * 0.5);
  899. $secondrow = ceil($howmany * 1);
  900. $firstrown1 = ceil(($howmany * 0.5)-1);
  901. $secondrown1 = ceil(($howmany * 1)-0);
  902. }
  903.  
  904.  
  905. //this makes 3 columns
  906. if ($options['columns'] == 3){
  907. $firstrow = ceil($howmany * 0.33);
  908. $secondrow = ceil($howmany * 0.66);
  909. $firstrown1 = ceil(($howmany * 0.33)-1);
  910. $secondrown1 = ceil(($howmany * 0.66)-1);
  911. }
  912.  
  913. //this makes 4 columns
  914. if ($options['columns'] == 4){
  915. $firstrow = ceil($howmany * 0.25);
  916. $secondrow = ceil(($howmany * 0.5)+1);
  917. $firstrown1 = ceil(($howmany * 0.25)-1);
  918. $secondrown1 = ceil(($howmany * 0.5)-0);
  919. $thirdrow = ceil(($howmany * 0.75)-0);
  920. $thirdrow1 = ceil(($howmany * 0.75)-1);
  921. }
  922.  
  923. //this makes 5 columns
  924. if ($options['columns'] == 5){
  925. $firstrow = ceil($howmany * 0.2);
  926. $firstrown1 = ceil(($howmany * 0.2)-1);
  927. $secondrow = ceil(($howmany * 0.4));
  928. $secondrown1 = ceil(($howmany * 0.4)-1);
  929. $thirdrow = ceil(($howmany * 0.6)-0);
  930. $thirdrow1 = ceil(($howmany * 0.6)-1);
  931. $fourthrow = ceil(($howmany * 0.8)-0);
  932. $fourthrow1 = ceil(($howmany * 0.8)-1);
  933. }
  934.  
  935. foreach( $groups as $letter => $tags ) {
  936. if ($options['columns'] == 2){
  937. if ($count == 0 || $count == $firstrow || $count == $secondrow) {
  938. if ($count == $firstrow){
  939. $list .= "\n<div class='holdleft noMargin'>\n";
  940. $list .="\n";
  941. } else {
  942. $list .= "\n<div class='holdleft'>\n";
  943. $list .="\n";
  944. }
  945. }
  946. }
  947. if ($options['columns'] == 3){
  948. if ($count == 0 || $count == $firstrow || $count == $secondrow) {
  949. if ($count == $secondrow){
  950. $list .= "\n<div class='holdleft noMargin'>\n";
  951. $list .="\n";
  952. } else {
  953. $list .= "\n<div class='holdleft'>\n";
  954. $list .="\n";
  955. }
  956. }
  957. }
  958. if ($options['columns'] == 4){
  959. if ($count == 0 || $count == $firstrow || $count == $secondrow || $count == $thirdrow) {
  960. if ($count == $thirdrow){
  961. $list .= "\n<div class='holdleft noMargin'>\n";
  962. $list .="\n";
  963. } else {
  964. $list .= "\n<div class='holdleft'>\n";
  965. $list .="\n";
  966. }
  967. }
  968. }
  969. if ($options['columns'] == 5){
  970. if ($count == 0 || $count == $firstrow || $count == $secondrow || $count == $thirdrow || $count == $fourthrow ) {
  971. if ($count == $fourthrow){
  972. $list .= "\n<div class='holdleft noMargin'>\n";
  973. $list .="\n";
  974. } else {
  975. $list .= "\n<div class='holdleft'>\n";
  976. $list .="\n";
  977. }
  978. }
  979. }
  980.  
  981. $list .= '<div class="tagindex">';
  982. $list .="\n";
  983. $list .='<h4>' . apply_filters( 'the_title', $letter ) . '</h4>';
  984. $list .="\n";
  985. $list .= '<ul class="links">';
  986. $list .="\n";
  987. $i = 0;
  988. foreach( $tags as $tag ) {
  989. $url = attribute_escape( get_tag_link( $tag->term_id ) );
  990. $name = apply_filters( 'the_title', $tag->name );
  991. // $name = ucfirst($name);
  992. $i++;
  993. $counti = $i;
  994. if ($options['hide'] == "yes"){
  995. $num2show = $options['num_show'];
  996. $num2show1 = ($options['num_show'] +1);
  997. $toggle = ($options['toggle']);
  998.  
  999. if ($i != 0 and $i <= $num2show) {
  1000. $list .= '<li><a title="' . $name . '" href="' . $url . '">' . $name . '</a></li>';
  1001. $list .="\n";
  1002. }
  1003. if ($i > $num2show && $i == $num2show1 && $toggle == "no") {
  1004. $list .= "<li class=\"morelink\">"."<a href=\"#x\" class=\"more\">".$options['more']."</a>"."</li>"."\n";
  1005. }
  1006. if ($i >= $num2show1){
  1007. $list .= '<li class="hideli"><a title="' . $name . '" href="' . $url . '">' . $name . '</a></li>';
  1008. $list .="\n";
  1009. }
  1010. } else {
  1011. $list .= '<li><a title="' . $name . '" href="' . $url . '">' . $name . '</a></li>';
  1012. $list .="\n";
  1013. }
  1014.  
  1015. }
  1016. if ($options['hide'] == "yes" && $toggle != "no" && $i == $counti && $i > $num2show) {
  1017. $list .= "<li class=\"morelink\">"."<a href=\"#x\" class=\"more\">".$options['more']."</a>"."<a href=\"#x\" class=\"less\">".$options['toggle']."</a>"."</li>"."\n";
  1018. }
  1019. $list .= '</ul>';
  1020. $list .="\n";
  1021. $list .= '</div>';
  1022. $list .="\n\n";
  1023. if ($options['columns'] == 3 || $options['columns'] == 2){
  1024. if ( $count == $firstrown1 || $count == $secondrown1) {
  1025. $list .= "</div>";
  1026. }
  1027. }
  1028. if ($options['columns'] == 4){
  1029. if ( $count == $firstrown1 || $count == $secondrown1 || $count == $thirdrow1) {
  1030. $list .= "</div>";
  1031. }
  1032. }
  1033. if ($options['columns'] == 5){
  1034. if ( $count == $firstrown1 || $count == $secondrown1 || $count == $thirdrow1 || $count == $fourthrow1) {
  1035. $list .= "</div>";
  1036. }
  1037. }
  1038.  
  1039. $count++;
  1040. }
  1041. }
  1042. $list .="</div>";
  1043. $list .= "<div style='clear: both;'></div></div><!-- end list -->";
  1044. }
  1045. else $list .= '<p>Sorry, but no tags were found</p>';
  1046.  
  1047. print $list ;
  1048.  
  1049. }
  1050. // end long code
  1051.  
  1052. // short code begins
  1053. function sc_mcTagMap($atts, $content = null) {
  1054. extract(shortcode_atts(array(
  1055. "columns" => "2",
  1056. "more" => "View More",
  1057. "hide" => "no",
  1058. "num_show" => "5",
  1059. "toggle" => "no",
  1060. "show_empty" => "yes",
  1061. ), $atts));
  1062.  
  1063.  
  1064.  
  1065. if($show_empty == "yes"){
  1066. $show_empty = "0";
  1067. }
  1068. if($show_empty == "no"){
  1069. $show_empty = "1";
  1070. }
  1071.  
  1072. $list = '<!-- begin list --><div id="mcTagMap">';
  1073. $tags = get_terms('post_tag', 'order=ASC&hide_empty='.$show_empty.''); // new code!
  1074. $groups = array();
  1075. if( $tags && is_array( $tags ) ) {
  1076. foreach( $tags as $tag ) {
  1077. $first_letter = strtoupper( $tag->name[0] );
  1078. $groups[ $first_letter ][] = $tag;
  1079. }
  1080. if( !empty ( $groups ) ) {
  1081. $count = 0;
  1082. $howmany = count($groups);
  1083.  
  1084. // this makes 2 columns
  1085. if ($columns == 2){
  1086. $firstrow = ceil($howmany * 0.5);
  1087. $secondrow = ceil($howmany * 1);
  1088. $firstrown1 = ceil(($howmany * 0.5)-1);
  1089. $secondrown1 = ceil(($howmany * 1)-0);
  1090. }
  1091.  
  1092.  
  1093. //this makes 3 columns
  1094. if ($columns == 3){
  1095. $firstrow = ceil($howmany * 0.33);
  1096. $secondrow = ceil($howmany * 0.66);
  1097. $firstrown1 = ceil(($howmany * 0.33)-1);
  1098. $secondrown1 = ceil(($howmany * 0.66)-1);
  1099. }
  1100.  
  1101. //this makes 4 columns
  1102. if ($columns == 4){
  1103. $firstrow = ceil($howmany * 0.25);
  1104. $secondrow = ceil(($howmany * 0.5)+1);
  1105. $firstrown1 = ceil(($howmany * 0.25)-1);
  1106. $secondrown1 = ceil(($howmany * 0.5)-0);
  1107. $thirdrow = ceil(($howmany * 0.75)-0);
  1108. $thirdrow1 = ceil(($howmany * 0.75)-1);
  1109. }
  1110.  
  1111. //this makes 5 columns
  1112. if ($columns == 5){
  1113. $firstrow = ceil($howmany * 0.2);
  1114. $firstrown1 = ceil(($howmany * 0.2)-1);
  1115. $secondrow = ceil(($howmany * 0.4));
  1116. $secondrown1 = ceil(($howmany * 0.4)-1);
  1117. $thirdrow = ceil(($howmany * 0.6)-0);
  1118. $thirdrow1 = ceil(($howmany * 0.6)-1);
  1119. $fourthrow = ceil(($howmany * 0.8)-0);
  1120. $fourthrow1 = ceil(($howmany * 0.8)-1);
  1121. }
  1122.  
  1123. foreach( $groups as $letter => $tags ) {
  1124. if ($columns == 2){
  1125. if ($count == 0 || $count == $firstrow || $count == $secondrow) {
  1126. if ($count == $firstrow){
  1127. $list .= "\n<div class='holdleft noMargin'>\n";
  1128. $list .="\n";
  1129. } else {
  1130. $list .= "\n<div class='holdleft'>\n";
  1131. $list .="\n";
  1132. }
  1133. }
  1134. }
  1135. if ($columns == 3){
  1136. if ($count == 0 || $count == $firstrow || $count == $secondrow) {
  1137. if ($count == $secondrow){
  1138. $list .= "\n<div class='holdleft noMargin'>\n";
  1139. $list .="\n";
  1140. } else {
  1141. $list .= "\n<div class='holdleft'>\n";
  1142. $list .="\n";
  1143. }
  1144. }
  1145. }
  1146. if ($columns == 4){
  1147. if ($count == 0 || $count == $firstrow || $count == $secondrow || $count == $thirdrow) {
  1148. if ($count == $thirdrow){
  1149. $list .= "\n<div class='holdleft noMargin'>\n";
  1150. $list .="\n";
  1151. } else {
  1152. $list .= "\n<div class='holdleft'>\n";
  1153. $list .="\n";
  1154. }
  1155. }
  1156. }
  1157. if ($columns == 5){
  1158. if ($count == 0 || $count == $firstrow || $count == $secondrow || $count == $thirdrow || $count == $fourthrow ) {
  1159. if ($count == $fourthrow){
  1160. $list .= "\n<div class='holdleft noMargin'>\n";
  1161. $list .="\n";
  1162. } else {
  1163. $list .= "\n<div class='holdleft'>\n";
  1164. $list .="\n";
  1165. }
  1166. }
  1167. }
  1168.  
  1169. $list .= '<div class="tagindex">';
  1170. $list .="\n";
  1171. $list .='<h4>' . apply_filters( 'the_title', $letter ) . '</h4>';
  1172. $list .="\n";
  1173. $list .= '<ul class="links">';
  1174. $list .="\n";
  1175. $i = 0;
  1176. foreach( $tags as $tag ) {
  1177. $url = attribute_escape( get_tag_link( $tag->term_id ) );
  1178. $name = apply_filters( 'the_title', $tag->name );
  1179. // $name = ucfirst($name);
  1180.  
  1181. $i++;
  1182. $counti = $i;
  1183. if ($hide == "yes"){
  1184. $num2show = $num_show;
  1185. $num2show1 = ($num_show +1);
  1186. //$toggle = ($options['toggle']);
  1187. if ($i != 0 and $i <= $num2show) {
  1188. $list .= '<li><a title="' . $name . '" href="' . $url . '">' . $name . '</a></li>';
  1189. $list .="\n";
  1190. }
  1191. if ($i > $num2show && $i == $num2show1 && $toggle == "no") {
  1192. $list .= "<li class=\"morelink\">"."<a href=\"#x\" class=\"more\">".$more."</a>"."</li>"."\n";
  1193. }
  1194. if ($i >= $num2show1){
  1195. $list .= '<li class="hideli"><a title="' . $name . '" href="' . $url . '">' . $name . '</a></li>';
  1196. $list .="\n";
  1197. }
  1198. } else {
  1199. $list .= '<li><a title="' . $name . '" href="' . $url . '">' . $name . '</a></li>';
  1200. $list .="\n";
  1201. }
  1202.  
  1203. }
  1204. if ($hide == "yes" && $toggle != "no" && $i == $counti && $i > $num2show) {
  1205. $list .= "<li class=\"morelink\">"."<a href=\"#x\" class=\"more\">".$more."</a>"."<a href=\"#x\" class=\"less\">".$toggle."</a>"."</li>"."\n";
  1206. }
  1207.  
  1208. $list .= '</ul>';
  1209. $list .="\n";
  1210. $list .= '</div>';
  1211. $list .="\n\n";
  1212. if ($columns == 3 || $columns == 2){
  1213. if ( $count == $firstrown1 || $count == $secondrown1) {
  1214. $list .= "</div>";
  1215. }
  1216. }
  1217. if ($columns == 4){
  1218. if ( $count == $firstrown1 || $count == $secondrown1 || $count == $thirdrow1) {
  1219. $list .= "</div>";
  1220. }
  1221. }
  1222. if ($columns == 5){
  1223. if ( $count == $firstrown1 || $count == $secondrown1 || $count == $thirdrow1 || $count == $fourthrow1) {
  1224. $list .= "</div>";
  1225. }
  1226. }
  1227.  
  1228. $count++;
  1229. }
  1230. }
  1231. $list .="</div>";
  1232. $list .= "<div style='clear: both;'></div></div><!-- end list -->";
  1233. }
  1234. else $list .= '<p>Sorry, but no tags were found</p>';
  1235.  
  1236. return $list;
  1237.  
  1238. }
  1239.  
  1240. add_shortcode("mctagmap", "sc_mcTagMap");
  1241. // end shortcode
  1242.  
  1243.  
  1244. // the JS and CSS
  1245. add_action('wp_head', 'mcTagMapCSSandJS');
  1246. function mcTagMapCSSandJS()
  1247. {
  1248. if ($toggle == "no"){
  1249. echo '<link rel="stylesheet" href="'.get_template_directory_uri().'/tagmap.css" type="text/css" media="screen" />';
  1250. echo "\n\n";
  1251. echo "<script type=\"text/javascript\">
  1252. jQuery(document).ready(function() {
  1253. jQuery('ul.links li.hideli').hide();
  1254. jQuery('ul.links li.morelink').show();
  1255. jQuery('a.more').click(function() {
  1256. jQuery(this).parent().siblings('li.hideli').slideToggle('fast');
  1257. jQuery(this).parent('li.morelink').remove();
  1258. });
  1259. });
  1260. </script>\n\n";
  1261. }
  1262. if ($toggle != "no"){
  1263. echo '<link rel="stylesheet" href="'.get_template_directory_uri().'/tagmap.css" type="text/css" media="screen" />';
  1264. echo "\n\n";
  1265. echo "<script type=\"text/javascript\">
  1266. jQuery(document).ready(function() {
  1267. jQuery('a.less').hide();
  1268. jQuery('ul.links li.hideli').hide();
  1269. jQuery('ul.links li.morelink').show();
  1270. jQuery('a.more').click(function() {
  1271. jQuery(this).parent().siblings('li.hideli').slideToggle('fast');
  1272. jQuery(this).parent('li.morelink').children('a.less').show();
  1273. jQuery(this).hide();
  1274. });
  1275. jQuery('a.less').click(function() {
  1276. jQuery(this).parent().siblings('li.hideli').slideToggle('fast');
  1277. jQuery(this).parent('li.morelink').children('a.more').show();
  1278. jQuery(this).hide();
  1279. });
  1280. });
  1281. </script>\n\n";
  1282. }
  1283. }
  1284.  
  1285. // Theme Options
  1286. $themename = "Theme Options";
  1287. $shortname = "to";
  1288.  
  1289. $categories = get_categories('hide_empty=0&orderby=name');
  1290. $wp_cats = array();
  1291. foreach ($categories as $category_list ) {
  1292. $wp_cats[$category_list->cat_ID] = $category_list->cat_name;
  1293. }
  1294. array_unshift($wp_cats, "Choose a category");
  1295.  
  1296. $options = array (
  1297.  
  1298. array( "name" => $themename." Options",
  1299. "type" => "title"),
  1300.  
  1301. array( "name" => "General",
  1302. "type" => "section"),
  1303. array( "type" => "open"),
  1304.  
  1305. array( "name" => "Ad Big Blocks Code",
  1306. "desc" => "Paste the code for your block ads here",
  1307. "id" => $shortname."_ad_blocks",
  1308. "type" => "textarea",
  1309. "std" => ""),
  1310.  
  1311. array( "name" => "Logo URL",
  1312. "desc" => "Enter the link to your logo image",
  1313. "id" => $shortname."_logo",
  1314. "type" => "text",
  1315. "std" => ""),
  1316.  
  1317. array( "name" => "Custom Favicon",
  1318. "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.",
  1319. "id" => $shortname."_favicon",
  1320. "type" => "text",
  1321. "std" => get_bloginfo('url') ."/favicon.ico"),
  1322.  
  1323. array( "name" => "Header Code",
  1324. "desc" => "Paste codes that belong in the header here. You can put your Google Analytics or other tracking code in this box.",
  1325. "id" => $shortname."_hdr_code",
  1326. "type" => "textarea",
  1327. "std" => ""),
  1328.  
  1329. array( "type" => "close"),
  1330. array( "name" => "SEO",
  1331. "type" => "section"),
  1332. array( "type" => "open"),
  1333.  
  1334. array( "name" => "Meta Keywords",
  1335. "desc" => "Enter meta keywords.",
  1336. "id" => $shortname."_meta_keywords",
  1337. "type" => "text",
  1338. "std" => ""),
  1339.  
  1340. array( "name" => "Meta Description",
  1341. "desc" => "Enter a meta description.",
  1342. "type" => "text",
  1343. "std" => ""),
  1344.  
  1345. array( "type" => "close"),
  1346. array( "name" => "Styling",
  1347. "type" => "section"),
  1348. array( "type" => "open"),
  1349.  
  1350. array( "name" => "Color Scheme",
  1351. "desc" => "Select the color scheme for the theme",
  1352. "id" => $shortname."_color_scheme",
  1353. "type" => "select",
  1354. "options" => array("blue", "red", "green"),
  1355. "std" => "blue"),
  1356.  
  1357. array( "name" => "Child stylesheet",
  1358. "desc" => "Want to add any custom CSS code? Put it here. This overrides any other stylesheets.",
  1359. "id" => $shortname."_child_style",
  1360. "type" => "textarea",
  1361. "std" => ""),
  1362.  
  1363. array( "name" => "Display breadcrumbs on post pages?",
  1364. "desc" => "Choose whether or not to display breadcrumbs, that is, the post trail.",
  1365. "id" => $shortname."_breadcrumbs",
  1366. "type" => "select",
  1367. "options" => array("Yes", "No"),
  1368. "std" => "Yes"),
  1369.  
  1370. array( "name" => "Display comments on posts?",
  1371. "desc" => "Choose whether or not to display comments on posts.",
  1372. "id" => $shortname."_commentsd",
  1373. "type" => "select",
  1374. "options" => array("Yes", "No"),
  1375. "std" => "Yes"),
  1376.  
  1377. array( "type" => "close"),
  1378. array( "name" => "Retrieving",
  1379. "type" => "section"),
  1380. array( "type" => "open"),
  1381.  
  1382. array( "name" => "Number of posts on homepage",
  1383. "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.",
  1384. "id" => $shortname."_count_home",
  1385. "type" => "select",
  1386. "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"),
  1387. "std" => ""),
  1388.  
  1389. array( "name" => "Homepage featured category",
  1390. "desc" => "Enter a category ID to pull posts from that category on the homepage",
  1391. "id" => $shortname."_cat_home",
  1392. "type" => "text",
  1393. "std" => ""),
  1394.  
  1395. array( "name" => "Number of posts on portfolio page",
  1396. "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.",
  1397. "id" => $shortname."_count_portfolio",
  1398. "type" => "select",
  1399. "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"),
  1400. "std" => ""),
  1401.  
  1402. array( "name" => "Number of posts on category and archives pages",
  1403. "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.",
  1404. "id" => $shortname."_count_archives",
  1405. "type" => "select",
  1406. "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"),
  1407. "std" => ""),
  1408.  
  1409. array( "name" => "Number of posts on search pages",
  1410. "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.",
  1411. "id" => $shortname."_count_search",
  1412. "type" => "select",
  1413. "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"),
  1414. "std" => ""),
  1415.  
  1416. array( "name" => "Number of tags in sidebar",
  1417. "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.",
  1418. "id" => $shortname."_count_tags",
  1419. "type" => "select",
  1420. "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"),
  1421. "std" => ""),
  1422.  
  1423. array( "type" => "close"),
  1424. array( "name" => "Socials & Subscription Options",
  1425. "type" => "section"),
  1426. array( "type" => "open"),
  1427.  
  1428. array( "name" => "Facebook Page",
  1429. "desc" => "Enter your Facebook address. (Must include http://)",
  1430. "id" => $shortname."_facebook",
  1431. "type" => "text",
  1432. "std" => ""),
  1433.  
  1434. array( "name" => "Google Plus",
  1435. "desc" => "Enter your Google Plus address. (Must include http://)",
  1436. "id" => $shortname."_google_plus",
  1437. "type" => "text",
  1438. "std" => ""),
  1439.  
  1440. array( "name" => "Twitter Username",
  1441. "desc" => "Enter your Twitter username. This field determines the feed used for the built-in Twitter widget.",
  1442. "id" => $shortname."_twitter_feed",
  1443. "type" => "text",
  1444. "std" => ""),
  1445.  
  1446. array( "name" => "Mailing List",
  1447. "desc" => "Enter your mailing list address.",
  1448. "id" => $shortname."_mailing_list",
  1449. "type" => "text",
  1450. "std" => ""),
  1451.  
  1452. array( "name" => "RSS URL",
  1453. "desc" => "Paste your feed URL here. Alternatively, post your Feedburner URL here.",
  1454. "id" => $shortname."_feedburner",
  1455. "type" => "text",
  1456. "std" => get_bloginfo('rss2_url')),
  1457.  
  1458. array( "type" => "close"),
  1459. array( "name" => "Contact Form",
  1460. "type" => "section"),
  1461. array( "type" => "open"),
  1462.  
  1463. array( "name" => "E-Mail",
  1464. "desc" => "Enter the destination e-mail for your contact form",
  1465. "id" => $shortname."_email",
  1466. "type" => "text",
  1467. "std" => ""),
  1468.  
  1469. array( "type" => "close"),
  1470. array( "name" => "Footer",
  1471. "type" => "section"),
  1472. array( "type" => "open"),
  1473.  
  1474. array( "name" => "Footer Code",
  1475. "desc" => "Paste codes that belong in the footer here.",
  1476. "id" => $shortname."_ftr_code",
  1477. "type" => "textarea",
  1478. "std" => ""),
  1479.  
  1480. array( "type" => "close")
  1481. );
  1482.  
  1483. function mytheme_add_admin() {
  1484.  
  1485. global $themename, $shortname, $options;
  1486.  
  1487. if ( $_GET['page'] == basename(__FILE__) ) {
  1488.  
  1489. if ( 'save' == $_REQUEST['action'] ) {
  1490.  
  1491. foreach ($options as $value) {
  1492. update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
  1493.  
  1494. foreach ($options as $value) {
  1495. if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } }
  1496.  
  1497. header("Location: admin.php?page=functions.php&saved=true");
  1498. die;
  1499.  
  1500. }
  1501. else if( 'reset' == $_REQUEST['action'] ) {
  1502.  
  1503. foreach ($options as $value) {
  1504. delete_option( $value['id'] ); }
  1505.  
  1506. header("Location: admin.php?page=functions.php&reset=true");
  1507. die;
  1508.  
  1509. }
  1510. }
  1511.  
  1512. add_menu_page($themename, $themename, 'administrator', basename(__FILE__), 'mytheme_admin');
  1513. }
  1514.  
  1515. function mytheme_add_init() {
  1516.  
  1517. $file_dir=get_bloginfo('template_directory');
  1518. wp_enqueue_style("functions", $file_dir."/functions/functions.css", false, "1.0", "all");
  1519. wp_enqueue_script("rm_script", $file_dir."/functions/rm_script.js", false, "1.0");
  1520.  
  1521. }
  1522. function mytheme_admin() {
  1523.  
  1524. global $themename, $shortname, $options;
  1525. $i=0;
  1526.  
  1527. if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
  1528. if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
  1529.  
  1530. ?>
  1531. <div class="wrap rm_wrap">
  1532. <h2><?php echo $themename; ?> Settings</h2>
  1533.  
  1534. <div class="rm_opts">
  1535. <form method="post">
  1536. <?php foreach ($options as $value) {
  1537. switch ( $value['type'] ) {
  1538.  
  1539. case "open":
  1540. ?>
  1541.  
  1542. <?php break;
  1543.  
  1544. case "close":
  1545. ?>
  1546.  
  1547. </div>
  1548. </div>
  1549. <br />
  1550.  
  1551. <?php break;
  1552.  
  1553. case "title":
  1554. ?>
  1555. <p>To easily use the <?php echo $themename;?> theme, you can use the menu below.</p>
  1556.  
  1557.  
  1558. <?php break;
  1559.  
  1560. case 'text':
  1561. ?>
  1562.  
  1563. <div class="rm_input rm_text">
  1564. <label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  1565. <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']; } ?>" />
  1566. <small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
  1567.  
  1568. </div>
  1569. <?php
  1570. break;
  1571.  
  1572. case 'textarea':
  1573. ?>
  1574.  
  1575. <div class="rm_input rm_textarea">
  1576. <label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  1577. <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>
  1578. <small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
  1579.  
  1580. </div>
  1581.  
  1582. <?php
  1583. break;
  1584.  
  1585. case 'select':
  1586. ?>
  1587.  
  1588. <div class="rm_input rm_select">
  1589. <label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  1590.  
  1591. <select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
  1592. <?php foreach ($value['options'] as $option) { ?>
  1593. <option <?php if (get_settings( $value['id'] ) == $option) { echo 'selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?>
  1594. </select>
  1595.  
  1596. <small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
  1597. </div>
  1598. <?php
  1599. break;
  1600.  
  1601. case "checkbox":
  1602. ?>
  1603.  
  1604. <div class="rm_input rm_checkbox">
  1605. <label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
  1606.  
  1607. <?php if(get_option($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = "";} ?>
  1608. <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
  1609.  
  1610. <small><?php echo $value['desc']; ?></small><div class="clearfix"></div>
  1611. </div>
  1612. <?php break;
  1613. case "section":
  1614. $i++;
  1615. ?>
  1616.  
  1617. <div class="rm_section">
  1618. <div class="rm_title">
  1619. <h3><img class="inactive" alt="">
  1620. <?php echo $value['name']; ?></h3><span class="submit"><input name="save<?php echo $i; ?>" type="submit" value="Save changes" />
  1621. </span><div class="clearfix"></div></div>
  1622. <div class="rm_options">
  1623.  
  1624. <?php break;
  1625.  
  1626. }
  1627. }
  1628. ?>
  1629.  
  1630. <input type="hidden" name="action" value="save" />
  1631. </form>
  1632. <form method="post">
  1633. <p class="submit">
  1634. <input name="reset" type="submit" value="Reset" />
  1635. <input type="hidden" name="action" value="reset" />
  1636. </p>
  1637. </form>
  1638.  
  1639. <div style="font-size:1em; margin-bottom:10px;">Buy a theme: <a href="http://www.themeforward.com">ThemeForward</a></div>
  1640. </div>
  1641.  
  1642. <?php
  1643. }
  1644. ?>
  1645. <?php
  1646. add_action('admin_init', 'mytheme_add_init');
  1647. add_action('admin_menu', 'mytheme_add_admin');
  1648. ?>
Add Comment
Please, Sign In to add comment