This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

conorp

By: a guest on Sep 28th, 2009  |  syntax: None  |  size: 26.08 KB  |  views: 43  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. // Generates semantic classes for BODY element
  4. function sandbox_body_class( $print = true ) {
  5.         global $wp_query, $current_user;
  6.        
  7.         // It's surely a WordPress blog, right?
  8.         $c = array('wordpress');
  9.  
  10.         // Applies the time- and date-based classes (below) to BODY element
  11.         sandbox_date_classes(time(), $c);
  12.  
  13.         // Generic semantic classes for what type of content is displayed
  14.         is_home()       ? $c[] = 'home'       : null;
  15.         is_archive()    ? $c[] = 'archive'    : null;
  16.         is_date()       ? $c[] = 'date'       : null;
  17.         is_search()     ? $c[] = 'search'     : null;
  18.         is_paged()      ? $c[] = 'paged'      : null;
  19.         is_attachment() ? $c[] = 'attachment' : null;
  20.         is_404()        ? $c[] = 'four04'     : null; // CSS does not allow a digit as first character
  21.  
  22.         // Special classes for BODY element when a single post
  23.         if ( is_single() ) {
  24.                 $postID = $wp_query->post->ID;
  25.                 the_post();
  26.  
  27.                 // Adds 'single' class and class with the post ID
  28.                 $c[] = 'single postid-' . $postID;
  29.  
  30.                 // Adds classes for the month, day, and hour when the post was published
  31.                 if ( isset($wp_query->post->post_date) )
  32.                         sandbox_date_classes(mysql2date('U', $wp_query->post->post_date), $c, 's-');
  33.  
  34.                 // Adds category classes for each category on single posts
  35.                 if ( $cats = get_the_category() )
  36.                         foreach ( $cats as $cat )
  37.                                 $c[] = 's-category-' . $cat->slug;
  38.  
  39.                 // Adds tag classes for each tags on single posts
  40.                 if ( $tags = get_the_tags() )
  41.                         foreach ( $tags as $tag )
  42.                                 $c[] = 's-tag-' . $tag->slug;
  43.  
  44.                 // Adds MIME-specific classes for attachments
  45.                 if ( is_attachment() ) {
  46.                         $the_mime = get_post_mime_type();
  47.                         $boring_stuff = array("application/", "image/", "text/", "audio/", "video/", "music/");
  48.                                 $c[] = 'attachment-' . str_replace($boring_stuff, "", "$the_mime");
  49.                 }
  50.  
  51.                 // Adds author class for the post author
  52.                 $c[] = 's-author-' . sanitize_title_with_dashes(strtolower(get_the_author_login()));
  53.                 rewind_posts();
  54.         }
  55.  
  56.         // Author name classes for BODY on author archives
  57.         else if ( is_author() ) {
  58.                 $author = $wp_query->get_queried_object();
  59.                 $c[] = 'author';
  60.                 $c[] = 'author-' . $author->user_nicename;
  61.         }
  62.  
  63.         // Category name classes for BODY on category archvies
  64.         else if ( is_category() ) {
  65.                 $cat = $wp_query->get_queried_object();
  66.                 $c[] = 'category';
  67.                 $c[] = 'category-' . $cat->slug;
  68.         }
  69.  
  70.         // Tag name classes for BODY on tag archives
  71.         else if ( is_tag() ) {
  72.                 $tags = $wp_query->get_queried_object();
  73.                 $c[] = 'tag';
  74.                 $c[] = 'tag-' . $tags->slug; // Does not work; however I try to return the tag I get a false. Grrr.
  75.         }
  76.  
  77.         // Page author for BODY on 'pages'
  78.         else if ( is_page() ) {
  79.                 $pageID = $wp_query->post->ID;
  80.                 the_post();
  81.                 $c[] = 'page pageid-' . $pageID;
  82.                 $c[] = 'page-author-' . sanitize_title_with_dashes(strtolower(get_the_author('login')));
  83.                 rewind_posts();
  84.         }
  85.  
  86.         // For when a visitor is logged in while browsing
  87.         if ( $current_user->ID )
  88.                 $c[] = 'loggedin';
  89.  
  90.         // Paged classes; for 'page X' classes of index, single, etc.
  91.         if ( ( ( $page = $wp_query->get("paged") ) || ( $page = $wp_query->get("page") ) ) && $page > 1 ) {
  92.                 $c[] = 'paged-'.$page.'';
  93.                 if ( is_single() ) {
  94.                         $c[] = 'single-paged-'.$page.'';
  95.                 } else if ( is_page() ) {
  96.                         $c[] = 'page-paged-'.$page.'';
  97.                 } else if ( is_category() ) {
  98.                         $c[] = 'category-paged-'.$page.'';
  99.                 } else if ( is_tag() ) {
  100.                         $c[] = 'tag-paged-'.$page.'';
  101.                 } else if ( is_date() ) {
  102.                         $c[] = 'date-paged-'.$page.'';
  103.                 } else if ( is_author() ) {
  104.                         $c[] = 'author-paged-'.$page.'';
  105.                 } else if ( is_search() ) {
  106.                         $c[] = 'search-paged-'.$page.'';
  107.                 }
  108.         }
  109.  
  110.         // Separates classes with a single space, collates classes for BODY
  111.         $c = join(' ', apply_filters('body_class',  $c));
  112.  
  113.         // And tada!
  114.         return $print ? print($c) : $c;
  115. }
  116.  
  117. // Generates semantic classes for each post DIV element
  118. function sandbox_post_class( $print = true ) {
  119.         global $post, $sandbox_post_alt;
  120.  
  121.         // hentry for hAtom compliace, gets 'alt' for every other post DIV, describes the post type and p[n]
  122.         $c = array('hentry', "p$sandbox_post_alt", $post->post_type, $post->post_status);
  123.  
  124.         // Author for the post queried
  125.         $c[] = 'author-' . sanitize_title_with_dashes(strtolower(get_the_author('login')));
  126.  
  127.         // Category for the post queried
  128.         foreach ( (array) get_the_category() as $cat )
  129.                 $c[] = 'category-' . $cat->slug;
  130.  
  131.         // Tags for the post queried
  132.         foreach ( (array) get_the_tags() as $tag )
  133.                 $c[] = 'tag-' . $tag->slug;
  134.  
  135.         // For password-protected posts
  136.         if ( $post->post_password )
  137.                 $c[] = 'protected';
  138.  
  139.         // Applies the time- and date-based classes (below) to post DIV
  140.         sandbox_date_classes(mysql2date('U', $post->post_date), $c);
  141.  
  142.         // If it's the other to the every, then add 'alt' class
  143.         if ( ++$sandbox_post_alt % 2 )
  144.                 $c[] = 'alt';
  145.  
  146.         // Separates classes with a single space, collates classes for post DIV
  147.         $c = join(' ', apply_filters('post_class', $c));
  148.  
  149.         // And tada!
  150.         return $print ? print($c) : $c;
  151. }
  152.  
  153. // Define the num val for 'alt' classes (in post DIV and comment LI)
  154. $sandbox_post_alt = 1;
  155.  
  156. // Generates semantic classes for each comment LI element
  157. function sandbox_comment_class( $print = true ) {
  158.         global $comment, $post, $sandbox_comment_alt;
  159.  
  160.         // Collects the comment type (comment, trackback),
  161.         $c = array($comment->comment_type);
  162.  
  163.         // Counts trackbacks (t[n]) or comments (c[n])
  164.         if ($comment->comment_type == 'trackback') {
  165.                 $c[] = "t$sandbox_comment_alt";
  166.         } else {
  167.                 $c[] = "c$sandbox_comment_alt";
  168.         }
  169.  
  170.         // If the comment author has an id (registered), then print the log in name
  171.         if ( $comment->user_id > 0 ) {
  172.                 $user = get_userdata($comment->user_id);
  173.  
  174.                 // For all registered users, 'byuser'; to specificy the registered user, 'commentauthor+[log in name]'
  175.                 $c[] = "byuser comment-author-" . sanitize_title_with_dashes(strtolower($user->user_login));
  176.                 // For comment authors who are the author of the post
  177.                 if ( $comment->user_id === $post->post_author )
  178.                         $c[] = 'bypostauthor';
  179.         }
  180.  
  181.         // If it's the other to the every, then add 'alt' class; collects time- and date-based classes
  182.         sandbox_date_classes(mysql2date('U', $comment->comment_date), $c, 'c-');
  183.         if ( ++$sandbox_comment_alt % 2 )
  184.                 $c[] = 'alt';
  185.  
  186.         // Separates classes with a single space, collates classes for comment LI
  187.         $c = join(' ', apply_filters('comment_class', $c));
  188.  
  189.         // Tada again!
  190.         return $print ? print($c) : $c;
  191. }
  192.  
  193. // Generates time- and date-based classes for BODY, post DIVs, and comment LIs; relative to GMT (UTC)
  194. function sandbox_date_classes($t, &$c, $p = '') {
  195.         $t = $t + (get_option('gmt_offset') * 3600);
  196.         $c[] = $p . 'y' . gmdate('Y', $t); // Year
  197.         $c[] = $p . 'm' . gmdate('m', $t); // Month
  198.         $c[] = $p . 'd' . gmdate('d', $t); // Day
  199.         $c[] = $p . 'h' . gmdate('H', $t); // Hour
  200. }
  201.  
  202. // For category lists on category archives: Returns other categories except the current one (redundant)
  203. function sandbox_cats_meow($glue) {
  204.         $current_cat = single_cat_title('', false);
  205.         $separator = "\n";
  206.         $cats = explode($separator, get_the_category_list($separator));
  207.  
  208.         foreach ( $cats as $i => $str ) {
  209.                 if ( strstr($str, ">$current_cat<") ) {
  210.                         unset($cats[$i]);
  211.                         break;
  212.                 }
  213.         }
  214.  
  215.         if ( empty($cats) )
  216.                 return false;
  217.  
  218.         return trim(join($glue, $cats));
  219. }
  220.  
  221. // For tag lists on tag archives: Returns other tags except the current one (redundant)
  222. function sandbox_tag_ur_it($glue) {
  223.         $current_tag = single_tag_title('', '',  false);
  224.         $separator = "\n";
  225.         $tags = explode($separator, get_the_tag_list("", "$separator", ""));
  226.  
  227.         foreach ( $tags as $i => $str ) {
  228.                 if ( strstr($str, ">$current_tag<") ) {
  229.                         unset($tags[$i]);
  230.                         break;
  231.                 }
  232.         }
  233.  
  234.         if ( empty($tags) )
  235.                 return false;
  236.  
  237.         return trim(join($glue, $tags));
  238. }
  239.  
  240. // Nice Tag Cloud
  241. function widget_nice_tagcloud($args) {
  242.     extract($args);
  243. ?>
  244.         <?php echo $before_widget; ?>
  245.             <?php echo $before_title
  246.                 . 'Tag Cloud'
  247.                 . $after_title; ?>
  248.  
  249. <?php if ( function_exists('wp_tag_cloud') ) : ?>
  250.                                         <p>
  251.                                                 <?php wp_tag_cloud('orderby=count&order=DESC'); ?>
  252.                                         </p>
  253. <?php endif; ?>
  254.                                
  255.         <?php echo $after_widget; ?>
  256. <?php
  257. }
  258. register_sidebar_widget('Nice Tag Cloud',
  259.     'widget_nice_tagcloud');
  260.  
  261.  
  262. // Widget: Search; to match the Sandbox style and replace Widget plugin default
  263. function widget_sandbox_search($args) {
  264.         extract($args);
  265.         if ( empty($title) )
  266.                 $title = __('Search', 'sandbox');
  267. ?>
  268.                         <?php echo $before_widget ?>
  269.                                 <?php echo $before_title ?><label for="s"><?php echo $title ?></label><?php echo $after_title ?>
  270.                                 <form id="searchform" method="get" action="<?php bloginfo('home') ?>">
  271.                                         <div>
  272.                                                 <input id="s" name="s" type="text" value="<?php echo wp_specialchars(stripslashes($_GET['s']), true) ?>" size="20" tabindex="1" />
  273.                                                 <input id="searchsubmit" name="searchsubmit" type="submit" value="<?php _e('Search', 'sandbox') ?>" tabindex="2" />
  274.                                         </div>
  275.                                 </form>
  276.                         <?php echo $after_widget ?>
  277.  
  278. <?php
  279. }
  280.  
  281. // Widget: Meta; to match the Sandbox style and replace Widget plugin default
  282. function widget_sandbox_meta($args) {
  283.         extract($args);
  284.         if ( empty($title) )
  285.                 $title = __('Meta', 'sandbox');
  286. ?>
  287.                         <?php echo $before_widget; ?>
  288.                                 <?php echo $before_title . $title . $after_title; ?>
  289.                                 <ul>
  290.                                         <?php wp_register() ?>
  291.                                         <li><?php wp_loginout() ?></li>
  292.                                         <?php wp_meta() ?>
  293.                                 </ul>
  294.                         <?php echo $after_widget; ?>
  295. <?php
  296. }
  297.  
  298. // Widget: RSS links; to match the Sandbox style
  299. function widget_sandbox_rsslinks($args) {
  300.         extract($args);
  301.         $options = get_option('widget_sandbox_rsslinks');
  302.         $title = empty($options['title']) ? __('RSS Links', 'sandbox') : $options['title'];
  303. ?>
  304.                 <?php echo $before_widget; ?>
  305.                         <?php echo $before_title . $title . $after_title; ?>
  306.                         <ul>
  307.                                 <li><a href="<?php bloginfo('rss2_url') ?>" title="<?php echo wp_specialchars(get_bloginfo('name'), 1) ?> <?php _e('Posts RSS feed', 'sandbox'); ?>" rel="alternate" type="application/rss+xml"><?php _e('All posts', 'sandbox') ?></a></li>
  308.                                 <li><a href="<?php bloginfo('comments_rss2_url') ?>" title="<?php echo wp_specialchars(bloginfo('name'), 1) ?> <?php _e('Comments RSS feed', 'sandbox'); ?>" rel="alternate" type="application/rss+xml"><?php _e('All comments', 'sandbox') ?></a></li>
  309.                         </ul>
  310.                 <?php echo $after_widget; ?>
  311. <?php
  312. }
  313.  
  314. // Widget: RSS links; element controls for customizing text within Widget plugin
  315. function widget_sandbox_rsslinks_control() {
  316.         $options = $newoptions = get_option('widget_sandbox_rsslinks');
  317.         if ( $_POST["rsslinks-submit"] ) {
  318.                 $newoptions['title'] = strip_tags(stripslashes($_POST["rsslinks-title"]));
  319.         }
  320.         if ( $options != $newoptions ) {
  321.                 $options = $newoptions;
  322.                 update_option('widget_sandbox_rsslinks', $options);
  323.         }
  324.         $title = htmlspecialchars($options['title'], ENT_QUOTES);
  325. ?>
  326.                         <p><label for="rsslinks-title"><?php _e('Title:'); ?> <input style="width: 250px;" id="rsslinks-title" name="rsslinks-title" type="text" value="<?php echo $title; ?>" /></label></p>
  327.                         <input type="hidden" id="rsslinks-submit" name="rsslinks-submit" value="1" />
  328. <?php
  329. }
  330.  
  331. // Widgets plugin: intializes the plugin after the widgets above have passed snuff
  332. function sandbox_widgets_init() {
  333.         if ( !function_exists('register_sidebars') )
  334.                 return;
  335.  
  336.         // Uses H3-level headings with all widgets to match Sandbox style
  337.         $p = array(
  338.                 'before_title' => "<h3 class='widgettitle'>",
  339.                 'after_title' => "</h3>\n",
  340.         );
  341.  
  342.         // Table for how many? Two? This way, please.
  343.         register_sidebars(2, $p);
  344.  
  345.         // Finished intializing Widgets plugin, now let's load the Sandbox default widgets
  346.         register_sidebar_widget(__('Search', 'sandbox'), 'widget_sandbox_search', null, 'search');
  347.         unregister_widget_control('search');
  348.         register_sidebar_widget(__('Meta', 'sandbox'), 'widget_sandbox_meta', null, 'meta');
  349.         unregister_widget_control('meta');
  350.         register_sidebar_widget(array(__('RSS Links', 'sandbox'), 'widgets'), 'widget_sandbox_rsslinks');
  351.         register_widget_control(array(__('RSS Links', 'sandbox'), 'widgets'), 'widget_sandbox_rsslinks_control', 300, 90);
  352. }
  353.  
  354. // Translate, if applicable
  355. load_theme_textdomain('sandbox');
  356.  
  357. // Runs our code at the end to check that everything needed has loaded
  358. add_action('init', 'sandbox_widgets_init');
  359.  
  360. // Adds filters so that things run smoothly
  361. add_filter('archive_meta', 'wptexturize');
  362. add_filter('archive_meta', 'convert_smilies');
  363. add_filter('archive_meta', 'convert_chars');
  364. add_filter('archive_meta', 'wpautop');
  365.  
  366. // Remember: the Sandbox is for play.
  367. ?>
  368. <?php
  369.  
  370. // Thanks very much to Thin & Light (http://thinlight.org/) for this custom function!
  371. function tl_excerpt($text, $excerpt_length = 25) {
  372.         $text = str_replace(']]>', ']]&gt;', $text);
  373.         $text = strip_tags($text);
  374.         $text = preg_replace("/\[.*?]/", "", $text);
  375.         $words = explode(' ', $text, $excerpt_length + 1);
  376.         if (count($words) > $excerpt_length) {
  377.                 array_pop($words);
  378.                 array_push($words, '...');
  379.                 $text = implode(' ', $words);
  380.         }
  381.        
  382.         return apply_filters('the_excerpt', $text);
  383. }
  384.  
  385. function tl_post_excerpt($post) {
  386.         $excerpt = ($post->post_excerpt == '') ? (tl_excerpt($post->post_content))
  387.                         : (apply_filters('the_excerpt', $post->post_excerpt));
  388.         return $excerpt;
  389. }
  390.  
  391. function previous_post_excerpt($in_same_cat = false, $excluded_categories = '') {
  392.         if ( is_attachment() )
  393.                 $post = &get_post($GLOBALS['post']->post_parent);
  394.         else
  395.                 $post = get_previous_post($in_same_cat, $excluded_categories);
  396.  
  397.         if ( !$post )
  398.                 return;
  399.         $post = &get_post($post->ID);
  400.         echo tl_post_excerpt($post);
  401. }
  402.  
  403. function next_post_excerpt($in_same_cat = false, $excluded_categories = '') {
  404.         $post = get_next_post($in_same_cat, $excluded_categories);
  405.  
  406.         if ( !$post )
  407.                 return;
  408.         $post = &get_post($post->ID);
  409.         echo tl_post_excerpt($post);
  410. }
  411.  
  412. // Much thanks goes out to Rob Bredow (http://www.185vfx.com) for this AWESOME plugin!
  413. function remove_first_image ($content) {
  414.    if (!is_page() && !is_feed() && !is_feed()) {
  415.         $content = preg_replace('/^<p><img(.*?)>/i', "<p><!-- Image removed by Remove First Image Plugin -->", $content, 1);
  416.         $content = preg_replace('/^<img(.*?)>/i', "<!-- Image removed by Remove First Image Plugin -->", $content, 1);
  417.         $content = preg_replace('/^<p><a(.*?)><img(.*?)><\/a>/i', '<p><!-- Link and image removed by Remove First Image Plugin -->', $content);
  418.                 $content = preg_replace('/^<a(.*?)><img(.*?)><\/a>/i', '<p><!-- Link and image removed by Remove First Image Plugin -->', $content);
  419.    } return $content;
  420. }
  421. add_filter('the_content', 'remove_first_image');
  422.  
  423. //      Custom IE Style Sheet
  424. function childtheme_iefix() { ?>
  425.     <!--[if lte IE 8]>
  426.                 <link rel="stylesheet" type="text/css" href="<?php echo bloginfo('stylesheet_directory') ?>/css/ie.css" />
  427.                 <script src="http://ie8-js.googlecode.com/svn/version/2.0(beta3)/IE8.js" type="text/javascript"></script>
  428.     <![endif]-->
  429.     <!--[if IE 6]>
  430.                 <link rel="stylesheet" type="text/css" href="<?php echo bloginfo('stylesheet_directory') ?>/css/ie6.css" />
  431.                 <script src="http://ie6-js.googlecode.com/svn/version/2.0(beta3)/IE6.js" type="text/javascript"></script>
  432.     <![endif]-->
  433. <?php }
  434. add_action('wp_head', 'childtheme_iefix');
  435.  
  436. // Custom the_excerpt formatting / hides [caption] short codes
  437. function the_autofocus_excerpt($text) { // Fakes an excerpt if needed
  438.         global $post;
  439.         if ( '' == $text ) {
  440.                 $text = get_the_content('');
  441.                 $text = apply_filters('the_content', $text);
  442.                 $text = str_replace(']]>', ']]&gt;', $text);
  443.                 $text = strip_tags($text, "<style>");
  444.                 $text = preg_replace("/\[.*?]/", "", $text);
  445.                 $excerpt_length = 25;
  446.                 $words = explode(' ', $text, $excerpt_length + 1);
  447.                 if (count($words)> $excerpt_length) {
  448.                         array_pop($words);
  449.                         array_push($words, '&hellip;');
  450.                         $text = implode(' ', $words);
  451.                 }
  452.         }
  453.         return $text;
  454. }
  455.  
  456. remove_filter('get_the_excerpt', 'wp_trim_excerpt');
  457. add_filter('get_the_excerpt', 'the_autofocus_excerpt');
  458.  
  459. // Produces a list of pages in the header without whitespace -- er, I mean negative space.
  460. function sandbox_globalnav() {
  461.     echo '<div id="menu"><ul><li class="page_item"><a href="'. get_settings('home') .'/" title="'. get_bloginfo('name') .'" rel="home">Home</a></li>';
  462.     $menu = wp_list_pages('title_li=&sort_column=menu_order&echo=0'); // Params for the page list in header.php
  463.     echo str_replace(array("\r", "\n", "\t"), '', $menu);
  464.     echo '<li class="page_item"><a href="'. get_bloginfo_rss('rss2_url') .'">RSS</a></li></ul></div>';
  465. }
  466.  
  467. // Post Attachment image function. Image URL for CSS Background.
  468. function the_post_image_url($size=large) {
  469.        
  470.         global $post;
  471.         $linkedimgurl = get_post_meta ($post->ID, 'image_url', true);
  472.  
  473.         if ( $images = get_children(array(
  474.                 'post_parent' => get_the_ID(),
  475.                 'post_type' => 'attachment',
  476.                 'numberposts' => 1,
  477.                 'post_mime_type' => 'image',)))
  478.         {
  479.                 foreach( $images as $image ) {
  480.                         $attachmenturl=wp_get_attachment_image_src($image->ID, $size);
  481.                         $attachmenturl=$attachmenturl[0];
  482.                         $attachmentimage=wp_get_attachment_image( $image->ID, $size );
  483.  
  484.                         echo ''.$attachmenturl.'';
  485.                 }
  486.                
  487.         } elseif ( $linkedimgurl ) {
  488.  
  489.                 echo $linkedimgurl;
  490.  
  491.         } elseif ( $linkedimgurl && $images = get_children(array(
  492.                 'post_parent' => get_the_ID(),
  493.                 'post_type' => 'attachment',
  494.                 'numberposts' => 1,
  495.                 'post_mime_type' => 'image',)))
  496.         {
  497.                 foreach( $images as $image ) {
  498.                         $attachmenturl=wp_get_attachment_image_src($image->ID, $size);
  499.                         $attachmenturl=$attachmenturl[0];
  500.                         $attachmentimage=wp_get_attachment_image( $image->ID, $size );
  501.  
  502.                         echo ''.$attachmenturl.'';
  503.                 }
  504.                
  505.         } else {
  506.                 echo '' . get_bloginfo ( 'stylesheet_directory' ) . '/img/no-attachment.gif';
  507.         }
  508. }
  509.  
  510. // Post Attachment image function. Direct link to file.
  511. function the_post_image($size=thumbnail) {
  512.        
  513.         global $post;
  514.         $linkedimgtag = get_post_meta ($post->ID, 'image_tag', true);
  515.  
  516.         if ( $images = get_children(array(
  517.                 'post_parent' => get_the_ID(),
  518.                 'post_type' => 'attachment',
  519.                 'numberposts' => 1,
  520.                 'post_mime_type' => 'image',)))
  521.                 {
  522.                 foreach( $images as $image ) {
  523.                         $attachmenturl=wp_get_attachment_url($image->ID);
  524.                         $attachmentimage=wp_get_attachment_image( $image->ID, $size );
  525.  
  526.                         echo ''.$attachmentimage.'';
  527.                 }
  528.                
  529.         } elseif ( $linkedimgtag ) {
  530.  
  531.                 echo $linkedimgtag;
  532.  
  533.         } elseif ( $linkedimgtag && $images = get_children(array(
  534.                 'post_parent' => get_the_ID(),
  535.                 'post_type' => 'attachment',
  536.                 'numberposts' => 1,
  537.                 'post_mime_type' => 'image',)))
  538.                 {
  539.                 foreach( $images as $image ) {
  540.                         $attachmenturl=wp_get_attachment_url($image->ID);
  541.                         $attachmentimage=wp_get_attachment_image( $image->ID, $size );
  542.  
  543.                         echo ''.$attachmentimage.'';
  544.                 }
  545.                
  546.         } else {
  547.                 echo '<img src="' . get_bloginfo ( 'stylesheet_directory' ) . '/img/no-attachment-large.gif" />';
  548.         }
  549. }
  550.  
  551. //Setup Images for Attachment functions
  552. function image_setup($postid) {
  553.         global $post;
  554.         $post = get_post($postid);
  555.  
  556.         // get url
  557.         if ( !preg_match('/<img ([^>]*)src=(\"|\')(.+?)(\2)([^>\/]*)\/*>/', $post->post_content, $matches) ) {
  558.                 return false;
  559.         }
  560.  
  561.         // url setup
  562.         $post->image_url = $matches[3];
  563.         if ( !$post->image_url = preg_replace('/\?w\=[0-9]+/','', $post->image_url) )
  564.                 return false;
  565.  
  566.         $post->image_url = clean_url( $post->image_url, 'raw' );
  567.        
  568.         delete_post_meta($post->ID, 'image_url');
  569.         delete_post_meta($post->ID, 'image_tag');
  570.  
  571.         add_post_meta($post->ID, 'image_url', $post->image_url);
  572.         add_post_meta($post->ID, 'image_tag', '<img src="'.$post->image_url.'" />');
  573.  
  574. }
  575.  
  576. add_action('publish_post', image_setup);
  577. add_action('publish_page', image_setup);
  578.  
  579. // Post Attachment image function for Attachment Pages.
  580. function the_attachment_image($size=large) {
  581.         $attachmenturl=wp_get_attachment_url($image->ID);
  582.         $attachmentimage=wp_get_attachment_image( $image->ID, $size );
  583.  
  584.         echo ''.$attachmentimage.'';
  585. }
  586.  
  587. // Post Attachment image function for Attachment Pages.
  588. function link_to_attachment($size=large) {
  589.         if ( $attachs = get_children(array(
  590.                 'post_parent' => get_the_ID(),
  591.                 'post_type' => 'attachment',
  592.                 'numberposts' => 1,
  593.                 'post_mime_type' => 'image',)))
  594.         {
  595.                 foreach( $attachs as $attach ) {
  596.                         $attachmentlink=get_attachment_link($attach->ID);
  597.  
  598.                         echo '<a href="' . $attachmentlink . '">View EXIF Data</a>';
  599.                 }
  600.         }
  601. }
  602.  
  603. // Grab EXIF Data from Attachments http://www.walkernews.net/2009/04/13/turn-on-wordpress-feature-to-display-photo-exif-data-and-iptc-information/
  604. function grab_exif_data() {
  605.         $imgmeta = wp_get_attachment_metadata($id);
  606.  
  607.         /*
  608.         // Convert the shutter speed retrieve from database to fraction DOES NOT WORK ON THE LIVE SERVER FOR SOME REASON >:-|
  609.         if ((1 / $imgmeta['image_meta']['shutter_speed']) > 1) {
  610.                 if ((number_format((1 / $imgmeta['image_meta']['shutter_speed']), 1)) == 1.3
  611.                 or number_format((1 / $imgmeta['image_meta']['shutter_speed']), 1) == 1.5
  612.                 or number_format((1 / $imgmeta['image_meta']['shutter_speed']), 1) == 1.6
  613.                 or number_format((1 / $imgmeta['image_meta']['shutter_speed']), 1) == 2.5) {
  614.                         $pshutter = "1/" . number_format((1 / $imgmeta['image_meta']['shutter_speed']), 1, '.', '') . " second";
  615.                 } else {
  616.                         $pshutter = "1/" . number_format((1 / $imgmeta['image_meta']['shutter_speed']), 0, '.', '') . " second";
  617.                 }
  618.  
  619.         } else {
  620.                 $pshutter = $imgmeta['image_meta']['shutter_speed'] . " seconds";
  621.         }*/
  622.  
  623.         // Start to display EXIF and IPTC data of digital photograph
  624.         echo "<ul><li<span class=\"exif-title\">Date Taken:</span> " . date("d-M-Y H:i:s", $imgmeta['image_meta']['created_timestamp'])."</li>";
  625.         echo "<li<span class=\"exif-title\">Copyright:</span> " . $imgmeta['image_meta']['copyright']."</li>";
  626.         echo "<li<span class=\"exif-title\">Credit:</span> " . $imgmeta['image_meta']['credit']."</li>";
  627.         echo "<li<span class=\"exif-title\">Title:</span> " . $imgmeta['image_meta']['title']."</li>";
  628.         echo "<li<span class=\"exif-title\">Caption:</span> " . $imgmeta['image_meta']['caption']."</li>";
  629.         echo "<li<span class=\"exif-title\">Camera:</span> " . $imgmeta['image_meta']['camera']."</li>";
  630.         echo "<li<span class=\"exif-title\">Focal Length:</span> " . $imgmeta['image_meta']['focal_length']."mm</li>";
  631.         echo "<li<span class=\"exif-title\">Aperture:</span> f/" . $imgmeta['image_meta']['aperture']."</li>";
  632.         echo "<li<span class=\"exif-title\">ISO:</span> " . $imgmeta['image_meta']['iso']."</li>";
  633.         // echo "<li<span class=\"exif-title\">Shutter Speed:</span> " . $pshutter . "</li></ul>";
  634. }
  635. // add_action('exif_data','grab_exif_data');
  636.  
  637. // Removes 'p' tags from excerpts.
  638. remove_filter('the_excerpt', 'wpautop');
  639.  
  640. // Fixes Next and Previous ATTACHMENT links
  641. function ps_previous_image_link( $f ) {
  642.     $i = ps_adjacent_image_link( true );
  643.         if ( $i ) {
  644.                 echo str_replace("%link", $i, $f);
  645.         }
  646. }
  647.  
  648. // Next ATTACHMENT link
  649. function ps_next_image_link( $f ) {
  650.     $i = ps_adjacent_image_link( false );
  651.         if ( $i ) {
  652.                 echo str_replace("%link", $i, $f);
  653.         }
  654. }
  655.  
  656. // Previous ATTACHMENT link
  657. function ps_adjacent_image_link($prev = true) {
  658.     global $post;
  659.     $post = get_post($post);
  660.     $attachments = array_values(get_children(Array('post_parent' => $post->post_parent,
  661.               'post_type' => 'attachment',
  662.               'post_mime_type' => 'image',
  663.               'orderby' => 'menu_order ASC, ID ASC')));
  664.  
  665.     foreach ( $attachments as $k => $attachment ) {
  666.         if ( $attachment->ID == $post->ID ) {
  667.             break;
  668.                 }
  669.         }
  670.  
  671.     $k = $prev ? $k - 1 : $k + 1;
  672.  
  673.     if ( isset($attachments[$k]) ) {
  674.         return wp_get_attachment_link($attachments[$k]->ID, 'thumbnail', true);
  675.         }
  676.         else {
  677.                 return false;
  678.         }
  679. }
  680.  
  681. // Overides default FULL size images size
  682. $GLOBALS['content_width'] = 800;
  683.  
  684. add_filter('the_content_rss', 'do_shortcode');
  685.  
  686. // Custom callback to list comments in the your-theme style
  687. function custom_comments($comment, $args, $depth) {
  688.   $GLOBALS['comment'] = $comment;
  689.         $GLOBALS['comment_depth'] = $depth;
  690.   ?>
  691.         <li id="comment-<?php comment_ID() ?>" <?php comment_class() ?>>
  692.                 <div class="comment-author vcard"><?php commenter_link() ?></div>
  693.                 <div class="comment-meta"><?php printf(__('Posted %1$s at %2$s <span class="meta-sep">|</span> <a href="%3$s" title="Permalink to this comment">#</a>', 'your-theme'),
  694.                                         get_comment_date(),
  695.                                         get_comment_time(),
  696.                                         '#comment-' . get_comment_ID() );
  697.                                         edit_comment_link(__('Edit', 'your-theme'), ' <span class="meta-sep">|</span> <span class="edit-link">', '</span>'); ?></div>
  698.   <?php if ($comment->comment_approved == '0') _e("\t\t\t\t\t<span class='unapproved'>Your comment is awaiting moderation.</span>\n", 'your-theme') ?>
  699.           <div class="comment-content">
  700.                 <?php comment_text() ?>
  701.                 </div>
  702.                 <?php // echo the comment reply link
  703.                         if($args['type'] == 'all' || get_comment_type() == 'comment') :
  704.                                 comment_reply_link(array_merge($args, array(
  705.                                         'reply_text' => __('Reply','your-theme'),
  706.                                         'login_text' => __('Log in to reply.','your-theme'),
  707.                                         'depth' => $depth,
  708.                                         'before' => '<div class="comment-reply-link">',
  709.                                         'after' => '</div>'
  710.                                 )));
  711.                         endif;
  712.                 ?>
  713. <?php } // end custom_comments
  714.  
  715. // Custom callback to list pings
  716. function custom_pings($comment, $args, $depth) {
  717.        $GLOBALS['comment'] = $comment;
  718.         ?>
  719.                 <li id="comment-<?php comment_ID() ?>" <?php comment_class() ?>>
  720.                         <div class="comment-author"><?php printf(__('By %1$s on %2$s at %3$s', 'your-theme'),
  721.                                         get_comment_author_link(),
  722.                                         get_comment_date(),
  723.                                         get_comment_time() );
  724.                                         edit_comment_link(__('Edit', 'your-theme'), ' <span class="meta-sep">|</span> <span class="edit-link">', '</span>'); ?></div>
  725.     <?php if ($comment->comment_approved == '0') _e('\t\t\t\t\t<span class="unapproved">Your trackback is awaiting moderation.</span>\n', 'your-theme') ?>
  726.             <div class="comment-content">
  727.                         <?php comment_text() ?>
  728.                         </div>
  729. <?php } // end custom_pings
  730.  
  731. // Produces an avatar image with the hCard-compliant photo class
  732. function commenter_link() {
  733.         $commenter = get_comment_author_link();
  734.         if ( ereg( '<a[^>]* class=[^>]+>', $commenter ) ) {
  735.                 $commenter = ereg_replace( '(<a[^>]* class=[\'"]?)', '\\1url ' , $commenter );
  736.         } else {
  737.                 $commenter = ereg_replace( '(<a )/', '\\1class="url "' , $commenter );
  738.         }
  739.         $avatar_email = get_comment_author_email();
  740.         $avatar = str_replace( "class='avatar", "class='photo avatar", get_avatar( $avatar_email, 50 ) );
  741.         echo $avatar . ' <span class="fn n">' . $commenter . '</span>';
  742. } // end commenter_link
  743.  
  744. ?>
clone this paste RAW Paste Data