Advertisement
Guest User

Johan

a guest
Jun 23rd, 2012
1,267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.21 KB | None | 0 0
  1. <?php
  2. /**
  3. * @package Skeleton WordPress Theme Framework
  4. * @subpackage skeleton
  5. * @author Simple Themes - www.simplethemes.com
  6. **/
  7.  
  8. function st_one_third( $atts, $content = null ) {
  9. return '<div class="one_third">' . do_shortcode($content) . '</div>';
  10. }
  11. add_shortcode('one_third', 'st_one_third');
  12.  
  13. function st_one_third_last( $atts, $content = null ) {
  14. return '<div class="one_third last">' . do_shortcode($content) . '</div><div class="clear"></div>';
  15. }
  16. add_shortcode('one_third_last', 'st_one_third_last');
  17.  
  18. function st_two_thirds( $atts, $content = null ) {
  19. return '<div class="two_thirds">' . do_shortcode($content) . '</div>';
  20. }
  21. add_shortcode('two_thirds', 'st_two_thirds');
  22.  
  23. function st_two_thirds_last( $atts, $content = null ) {
  24. return '<div class="two_thirds last">' . do_shortcode($content) . '</div><div class="clear"></div>';
  25. }
  26. add_shortcode('two_thirds_last', 'st_two_thirds_last');
  27.  
  28. // 1-4 col
  29.  
  30. function st_one_half( $atts, $content = null ) {
  31. return '<div class="one_half">' . do_shortcode($content) . '</div>';
  32. }
  33. add_shortcode('one_half', 'st_one_half');
  34.  
  35.  
  36. function st_one_half_last( $atts, $content = null ) {
  37. return '<div class="one_half last">' . do_shortcode($content) . '</div><div class="clear"></div>';
  38. }
  39. add_shortcode('one_half_last', 'st_one_half_last');
  40.  
  41.  
  42. function st_one_fourth( $atts, $content = null ) {
  43. return '<div class="one_fourth">' . do_shortcode($content) . '</div>';
  44. }
  45. add_shortcode('one_fourth', 'st_one_fourth');
  46.  
  47.  
  48. function st_one_fourth_last( $atts, $content = null ) {
  49. return '<div class="one_fourth last">' . do_shortcode($content) . '</div><div class="clear"></div>';
  50. }
  51. add_shortcode('one_fourth_last', 'st_one_fourth_last');
  52.  
  53. function st_three_fourths( $atts, $content = null ) {
  54. return '<div class="three_fourths">' . do_shortcode($content) . '</div>';
  55. }
  56. add_shortcode('three_fourths', 'st_three_fourths');
  57.  
  58.  
  59. function st_three_fourths_last( $atts, $content = null ) {
  60. return '<div class="three_fourths last">' . do_shortcode($content) . '</div><div class="clear"></div>';
  61. }
  62. add_shortcode('three_fourths_last', 'st_three_fourths_last');
  63.  
  64.  
  65. function st_one_fifth( $atts, $content = null ) {
  66. return '<div class="one_fifth">' . do_shortcode($content) . '</div>';
  67. }
  68. add_shortcode('one_fifth', 'st_one_fifth');
  69.  
  70. function st_two_fifth( $atts, $content = null ) {
  71. return '<div class="two_fifth">' . do_shortcode($content) . '</div>';
  72. }
  73. add_shortcode('two_fifth', 'st_two_fifth');
  74.  
  75. function st_three_fifth( $atts, $content = null ) {
  76. return '<div class="three_fifth">' . do_shortcode($content) . '</div>';
  77. }
  78. add_shortcode('three_fifth', 'st_three_fifth');
  79.  
  80. function st_four_fifth( $atts, $content = null ) {
  81. return '<div class="four_fifth">' . do_shortcode($content) . '</div>';
  82. }
  83. add_shortcode('four_fifth', 'st_four_fifth');
  84.  
  85. //
  86.  
  87. function st_one_fifth_last( $atts, $content = null ) {
  88. return '<div class="one_fifth last">' . do_shortcode($content) . '</div><div class="clear"></div>';
  89. }
  90. add_shortcode('one_fifth_last', 'st_one_fifth_last');
  91.  
  92. function st_two_fifth_last( $atts, $content = null ) {
  93. return '<div class="two_fifth last">' . do_shortcode($content) . '</div><div class="clear"></div>';
  94. }
  95. add_shortcode('two_fifth_last', 'st_two_fifth_last');
  96.  
  97. function st_three_fifth_last( $atts, $content = null ) {
  98. return '<div class="three_fifth last">' . do_shortcode($content) . '</div><div class="clear"></div>';
  99. }
  100. add_shortcode('three_fifth_last', 'st_three_fifth_last');
  101.  
  102. function st_four_fifth_last( $atts, $content = null ) {
  103. return '<div class="four_fifth last">' . do_shortcode($content) . '</div><div class="clear"></div>';
  104. }
  105. add_shortcode('four_fifth_last', 'st_four_fifth_last');
  106.  
  107. // 1-6 col
  108.  
  109. // one_sixth
  110. function st_one_sixth( $atts, $content = null ) {
  111. return '<div class="one_sixth">' . do_shortcode($content) . '</div>';
  112. }
  113. add_shortcode('one_sixth', 'st_one_sixth');
  114.  
  115. function st_one_sixth_last( $atts, $content = null ) {
  116. return '<div class="one_sixth last">' . do_shortcode($content) . '</div><div class="clear"></div>';
  117. }
  118. add_shortcode('one_sixth_last', 'st_one_sixth_last');
  119.  
  120. // five_sixth
  121. function st_five_sixth( $atts, $content = null ) {
  122. return '<div class="five_sixth">' . do_shortcode($content) . '</div>';
  123. }
  124. add_shortcode('five_sixth', 'st_five_sixth');
  125.  
  126. function st_five_sixth_last( $atts, $content = null ) {
  127. return '<div class="five_sixth last">' . do_shortcode($content) . '</div><div class="clear"></div>';
  128. }
  129. add_shortcode('five_sixth_last', 'st_five_sixth_last');
  130.  
  131.  
  132. // Callouts
  133.  
  134. function st_callout( $atts, $content = null ) {
  135. extract(shortcode_atts(array(
  136. 'width' => '',
  137. 'align' => ''
  138. ), $atts));
  139. $style;
  140. if ($width || $align) {
  141. $style .= 'style="';
  142. if ($width) $style .= 'width:'.$width.'px;';
  143. if ($align == 'left' || 'right') $style .= 'float:'.$align.';';
  144. if ($align == 'center') $style .= 'margin:0px auto;';
  145. $style .= '"';
  146. }
  147. return '<div class="cta" '.$style.'>' . do_shortcode($content) . '</div><div class="clear"></div>';
  148. }
  149. add_shortcode('callout', 'st_callout');
  150.  
  151.  
  152.  
  153. // Buttons
  154. function st_button( $atts, $content = null ) {
  155. extract(shortcode_atts(array(
  156. 'link' => '',
  157. 'size' => 'medium',
  158. 'color' => '',
  159. 'target' => '_self',
  160. 'caption' => '',
  161. 'align' => 'right'
  162. ), $atts));
  163. $button;
  164. $button .= '<div class="button '.$size.' '. $align.'">';
  165. $button .= '<a target="'.$target.'" class="button" name="modal" '.$color.'" href="'.$link.'">';
  166. $button .= $content;
  167. if ($caption != '') {
  168. $button .= '<br /><span class="btn_caption">'.$caption.'</span>';
  169. };
  170. $button .= '</a></div>';
  171. return $button;
  172. }
  173. add_shortcode('button', 'st_button');
  174.  
  175.  
  176. // Tabs
  177. add_shortcode( 'tabgroup', 'st_tabgroup' );
  178.  
  179. function st_tabgroup( $atts, $content ){
  180.  
  181. $GLOBALS['tab_count'] = 0;
  182. do_shortcode( $content );
  183.  
  184. if( is_array( $GLOBALS['tabs'] ) ){
  185.  
  186. foreach( $GLOBALS['tabs'] as $tab ){
  187. $tabs[] = '<li><a href="#'.$tab['id'].'">'.$tab['title'].'</a></li>';
  188. $panes[] = '<li id="'.$tab['id'].'Tab">'.$tab['content'].'</li>';
  189. }
  190. $return = "\n".'<!-- the tabs --><ul class="tabs">'.implode( "\n", $tabs ).'</ul>'."\n".'<!-- tab "panes" --><ul class="tabs-content">'.implode( "\n", $panes ).'</ul>'."\n";
  191. }
  192. return $return;
  193.  
  194. }
  195.  
  196. add_shortcode( 'tab', 'st_tab' );
  197. function st_tab( $atts, $content ){
  198. extract(shortcode_atts(array(
  199. 'title' => '%d',
  200. 'id' => '%d'
  201. ), $atts));
  202.  
  203. $x = $GLOBALS['tab_count'];
  204. $GLOBALS['tabs'][$x] = array(
  205. 'title' => sprintf( $title, $GLOBALS['tab_count'] ),
  206. 'content' => do_shortcode($content),
  207. 'id' => $id );
  208.  
  209. $GLOBALS['tab_count']++;
  210. }
  211.  
  212.  
  213. // Toggle
  214. function st_toggle( $atts, $content = null ) {
  215. extract(shortcode_atts(array(
  216. 'title' => '',
  217. 'style' => 'list'
  218. ), $atts));
  219. output;
  220. $output .= '<div class="'.$style.'"><p class="trigger"><a href="#">' .$title. '</a></p>';
  221. $output .= '<div class="toggle_container"><div class="block">';
  222. $output .= do_shortcode($content);
  223. $output .= '</div></div></div>';
  224.  
  225. return $output;
  226. }
  227. add_shortcode('toggle', 'st_toggle');
  228.  
  229.  
  230. /*-----------------------------------------------------------------------------------*/
  231. // Latest Posts
  232. // Example Use: [latest excerpt="true" thumbs="true" width="50" height="50" num="5" cat="8,10,11"]
  233. /*-----------------------------------------------------------------------------------*/
  234.  
  235.  
  236. function st_latest($atts, $content = null) {
  237. extract(shortcode_atts(array(
  238. "offset" => '',
  239. "num" => '5',
  240. "thumbs" => 'false',
  241. "excerpt" => 'false',
  242. "length" => '500',
  243. "morelink" => '',
  244. "width" => '100',
  245. "height" => '100',
  246. "type" => 'post',
  247. "parent" => '',
  248. "cat" => '',
  249. "orderby" => 'date',
  250. "order" => 'DESC'
  251. ), $atts));
  252. global $post;
  253.  
  254. $do_not_duplicate[] = $post->ID;
  255. $args = array(
  256. 'post__not_in' => $do_not_duplicate,
  257. 'cat' => $cat,
  258. 'post_type' => $type,
  259. 'post_parent' => $parent,
  260. 'showposts' => $num,
  261. 'orderby' => $orderby,
  262. 'offset' => $offset,
  263. 'order' => $order
  264. );
  265. // query
  266. $myposts = new WP_Query($args);
  267.  
  268. // container
  269. $result='<div id="category-'.$cat.'" class="latestposts">';
  270.  
  271. while($myposts->have_posts()) : $myposts->the_post();
  272. // item
  273. $result.='<div class="latest-item clearfix">';
  274. // title
  275. if ($excerpt == 'true') {
  276. $result.='
  277. <h4>'.the_title("","",false).'
  278. </h4>
  279. ';
  280.  
  281. } else {
  282. $result.='<div class="latest-title"><a href="'.get_permalink().'">'.the_title("","",false).'</a></div>';
  283. }
  284.  
  285.  
  286. // thumbnail
  287. if (has_post_thumbnail() && $thumbs == 'true') {
  288. $result.= '<img alt="'.get_the_title().'" class="alignleft latest-img" src="'.get_bloginfo('template_directory').'/thumb.php?src='.get_image_path().'&amp;h='.$height.'&amp;w='.$width.'"/>';
  289. }
  290.  
  291. // excerpt
  292. if ($excerpt == 'true') {
  293. // allowed tags in excerpts
  294. $allowed_tags = '<a>,<i>,<em>,<b>,<strong>,<ul>,<ol>,<li>,<blockquote>,<img>,<span>,<p>';
  295. // filter the content
  296. $text = preg_replace('/\[.*\]/', '', strip_tags(get_the_excerpt(), $allowed_tags));
  297. // remove the more-link
  298. $pattern = '/(<a.*?class="more-link"[^>]*>)(.*?)(<\/a>)/';
  299. // display the new excerpt
  300. $content = preg_replace($pattern,"", $text);
  301. $result.= '
  302.  
  303. <div class="latest-excerpt">
  304. <div class="my_room_meta">
  305. '.the_meta().'
  306. </div>
  307. '.st_limit_words($content,$length).'
  308.  
  309. </div>';
  310. }
  311.  
  312. // excerpt
  313. if ($morelink) {
  314. $result.= '<a class="more-link" href="'.get_permalink().'">L�s mer</a>';
  315. }
  316.  
  317. // item close
  318. $result.='
  319.  
  320. </div>
  321. ';
  322.  
  323. endwhile;
  324. wp_reset_postdata();
  325.  
  326. // container close
  327. $result.='</div>';
  328. return $result;
  329. }
  330. add_shortcode("latest", "st_latest");
  331.  
  332. // Example Use: [latest excerpt="true" thumbs="true" width="50" height="50" num="5" cat="8,10,11"]
  333.  
  334. /*-----------------------------------------------------------------------------------*/
  335. // Creates an additional hook to limit the excerpt
  336. /*-----------------------------------------------------------------------------------*/
  337.  
  338. function st_limit_words($string, $word_limit) {
  339. // creates an array of words from $string (this will be our excerpt)
  340. // explode divides the excerpt up by using a space character
  341. $words = explode(' ', $string);
  342. // this next bit chops the $words array and sticks it back together
  343. // starting at the first word '0' and ending at the $word_limit
  344. // the $word_limit which is passed in the function will be the number
  345. // of words we want to use
  346. // implode glues the chopped up array back together using a space character
  347. return implode(' ', array_slice($words, 0, $word_limit));
  348. }
  349.  
  350.  
  351. // Related Posts - [related_posts]
  352. add_shortcode('related_posts', 'st_related_posts');
  353. function st_related_posts( $atts ) {
  354. extract(shortcode_atts(array(
  355. 'limit' => '5',
  356. ), $atts));
  357.  
  358. global $wpdb, $post, $table_prefix;
  359.  
  360. if ($post->ID) {
  361. $retval = '<div class="st_relatedposts">';
  362. $retval .= '<h4>Related Posts</h4>';
  363. $retval .= '<ul>';
  364. // Get tags
  365. $tags = wp_get_post_tags($post->ID);
  366. $tagsarray = array();
  367. foreach ($tags as $tag) {
  368. $tagsarray[] = $tag->term_id;
  369. }
  370. $tagslist = implode(',', $tagsarray);
  371.  
  372. // Do the query
  373. $q = "SELECT p.*, count(tr.object_id) as count
  374. FROM $wpdb->term_taxonomy AS tt, $wpdb->term_relationships AS tr, $wpdb->posts AS p WHERE tt.taxonomy ='post_tag' AND tt.term_taxonomy_id = tr.term_taxonomy_id AND tr.object_id = p.ID AND tt.term_id IN ($tagslist) AND p.ID != $post->ID
  375. AND p.post_status = 'publish'
  376. AND p.post_date_gmt < NOW()
  377. GROUP BY tr.object_id
  378. ORDER BY count DESC, p.post_date_gmt DESC
  379. LIMIT $limit;";
  380.  
  381. $related = $wpdb->get_results($q);
  382. if ( $related ) {
  383. foreach($related as $r) {
  384. $retval .= '<li><a title="'.wptexturize($r->post_title).'" href="'.get_permalink($r->ID).'">'.wptexturize($r->post_title).'</a></li>';
  385. }
  386. } else {
  387. $retval .= '
  388. <li>No related posts found</li>';
  389. }
  390. $retval .= '</ul>';
  391. $retval .= '</div>';
  392. return $retval;
  393. }
  394. return;
  395. }
  396.  
  397. // Break
  398. function st_break( $atts, $content = null ) {
  399. return '<div class="clear"></div>';
  400. }
  401. add_shortcode('clear', 'st_break');
  402.  
  403.  
  404. // Line Break
  405. function st_linebreak( $atts, $content = null ) {
  406. return '<hr /><div class="clear"></div>';
  407. }
  408. add_shortcode('clearline', 'st_linebreak');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement