Advertisement
Guest User

functions.php

a guest
Apr 7th, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.25 KB | None | 0 0
  1. <?php
  2. /*
  3. This file is part of codium_extend. Hack and customize by henri labarre and based on the marvelous sandbox theme
  4.  
  5. codium_extend is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
  6.  
  7. */
  8.  
  9.  
  10. // This theme allows users to set a custom background
  11. add_custom_background();
  12.  
  13. // This theme allows users to set a custom header image
  14. define('HEADER_TEXTCOLOR', '444');
  15. define('HEADER_IMAGE_WIDTH', 980); // use width and height appropriate for your theme
  16. define('HEADER_IMAGE_HEIGHT', 250);
  17.  
  18. // gets included in the site header
  19. function header_style() {
  20. if (get_header_image() != ''){
  21. ?><style type="text/css">
  22. div#header {
  23. background: url(<?php header_image(); ?>); height :230px; -moz-border-radius-topleft:6px;border-top-left-radius:6px;-moz-border-radius-topright:6px;border-top-right-radius:6px;
  24. }
  25. <?php if ( 'blank' == get_header_textcolor() ) { ?>
  26. h1.blogtitle,.description { display: none; }
  27. <?php } else { ?>
  28. h1.blogtitle a,.description { color:#<?php header_textcolor() ?>; }
  29. <?php
  30. } ?>
  31. </style><?php
  32. }
  33. }
  34.  
  35.  
  36. // gets included in the admin header
  37. function admin_header_style() {
  38. ?><style type="text/css">
  39. #headimg {
  40. width: <?php echo HEADER_IMAGE_WIDTH; ?>px;
  41. height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
  42. }
  43. </style><?php
  44. }
  45.  
  46. add_custom_image_header('header_style', 'admin_header_style');
  47.  
  48. // Set the content width based on the theme's design and stylesheet.
  49. if ( ! isset( $content_width ) )
  50. $content_width = 620;
  51.  
  52. // Make theme available for translation
  53. // Translations can be filed in the /languages/ directory
  54. load_theme_textdomain( 'codium_extend', TEMPLATEPATH . '/languages' );
  55.  
  56. $locale = get_locale();
  57. $locale_file = TEMPLATEPATH . "/languages/$locale.php";
  58. if ( is_readable( $locale_file ) )
  59. require_once( $locale_file );
  60.  
  61. //feed
  62. add_theme_support('automatic-feed-links');
  63.  
  64.  
  65. // Generates semantic classes for BODY element
  66. function codium_extend_body_class( $print = true ) {
  67. global $wp_query, $current_user;
  68.  
  69. // It's surely a WordPress blog, right?
  70. $c = array('wordpress');
  71.  
  72. // Applies the time- and date-based classes (below) to BODY element
  73. codium_extend_date_classes( time(), $c );
  74.  
  75. // Generic semantic classes for what type of content is displayed
  76. is_front_page() ? $c[] = 'home' : null; // For the front page, if set
  77. is_home() ? $c[] = 'blog' : null; // For the blog posts page, if set
  78. is_archive() ? $c[] = 'archive' : null;
  79. is_date() ? $c[] = 'date' : null;
  80. is_search() ? $c[] = 'search' : null;
  81. is_paged() ? $c[] = 'paged' : null;
  82. is_attachment() ? $c[] = 'attachment' : null;
  83. is_404() ? $c[] = 'four04' : null; // CSS does not allow a digit as first character
  84. is_tax() ? $c[] = 'taxonomy' : null;
  85. is_sticky() ? $c[] = 'sticky' : null;
  86.  
  87. // Special classes for BODY element when a single post
  88. if ( is_single() ) {
  89. $postID = $wp_query->post->ID;
  90. the_post();
  91.  
  92. // Adds 'single' class and class with the post ID
  93. $c[] = 'single postid-' . $postID;
  94.  
  95. // Adds classes for the month, day, and hour when the post was published
  96. if ( isset( $wp_query->post->post_date ) )
  97. codium_extend_date_classes( mysql2date( 'U', $wp_query->post->post_date ), $c, 's-' );
  98.  
  99. // Adds category classes for each category on single posts
  100. if ( $cats = get_the_category() )
  101. foreach ( $cats as $cat )
  102. $c[] = 's-category-' . $cat->slug;
  103.  
  104. // Adds tag classes for each tags on single posts
  105. if ( $tags = get_the_tags() )
  106. foreach ( $tags as $tag )
  107. $c[] = 's-tag-' . $tag->slug;
  108.  
  109. // Adds MIME-specific classes for attachments
  110. if ( is_attachment() ) {
  111. $mime_type = get_post_mime_type();
  112. $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
  113. $c[] = 'attachmentid-' . $postID . ' attachment-' . str_replace( $mime_prefix, "", "$mime_type" );
  114. }
  115.  
  116. // Adds author class for the post author
  117. $c[] = 's-author-' . sanitize_title_with_dashes(strtolower(get_the_author_meta('login')));
  118. rewind_posts();
  119. }
  120.  
  121. // Author name classes for BODY on author archives
  122. elseif ( is_author() ) {
  123. $author = $wp_query->get_queried_object();
  124. $c[] = 'author';
  125. $c[] = 'author-' . $author->user_nicename;
  126. }
  127.  
  128. // Category name classes for BODY on category archvies
  129. elseif ( is_category() ) {
  130. $cat = $wp_query->get_queried_object();
  131. $c[] = 'category';
  132. $c[] = 'category-' . $cat->slug;
  133. }
  134.  
  135. // Tag name classes for BODY on tag archives
  136. elseif ( is_tag() ) {
  137. $tags = $wp_query->get_queried_object();
  138. $c[] = 'tag';
  139. $c[] = 'tag-' . $tags->slug;
  140. }
  141.  
  142. // Page author for BODY on 'pages'
  143. elseif ( is_page() ) {
  144. $pageID = $wp_query->post->ID;
  145. $page_children = wp_list_pages("child_of=$pageID&echo=0");
  146. the_post();
  147. $c[] = 'page pageid-' . $pageID;
  148. $c[] = 'page-author-' . sanitize_title_with_dashes(strtolower(get_the_author()));
  149. // Checks to see if the page has children and/or is a child page; props to Adam
  150. if ( $page_children )
  151. $c[] = 'page-parent';
  152. if ( $wp_query->post->post_parent )
  153. $c[] = 'page-child parent-pageid-' . $wp_query->post->post_parent;
  154. if ( is_page_template() ) // Hat tip to Ian, themeshaper.com
  155. $c[] = 'page-template page-template-' . str_replace( '.php', '-php', get_post_meta( $pageID, '_wp_page_template', true ) );
  156. rewind_posts();
  157. }
  158.  
  159. // Search classes for results or no results
  160. elseif ( is_search() ) {
  161. the_post();
  162. if ( have_posts() ) {
  163. $c[] = 'search-results';
  164. } else {
  165. $c[] = 'search-no-results';
  166. }
  167. rewind_posts();
  168. }
  169.  
  170. // For when a visitor is logged in while browsing
  171. if ( $current_user->ID )
  172. $c[] = 'loggedin';
  173.  
  174. // Paged classes; for 'page X' classes of index, single, etc.
  175. if ( ( ( $page = $wp_query->get('paged') ) || ( $page = $wp_query->get('page') ) ) && $page > 1 ) {
  176. // Thanks to Prentiss Riddle, twitter.com/pzriddle, for the security fix below.
  177. $page = intval($page); // Ensures that an integer (not some dangerous script) is passed for the variable
  178. $c[] = 'paged-' . $page;
  179. if ( is_single() ) {
  180. $c[] = 'single-paged-' . $page;
  181. } elseif ( is_page() ) {
  182. $c[] = 'page-paged-' . $page;
  183. } elseif ( is_category() ) {
  184. $c[] = 'category-paged-' . $page;
  185. } elseif ( is_tag() ) {
  186. $c[] = 'tag-paged-' . $page;
  187. } elseif ( is_date() ) {
  188. $c[] = 'date-paged-' . $page;
  189. } elseif ( is_author() ) {
  190. $c[] = 'author-paged-' . $page;
  191. } elseif ( is_search() ) {
  192. $c[] = 'search-paged-' . $page;
  193. }
  194. }
  195.  
  196. // Separates classes with a single space, collates classes for BODY
  197. $c = join( ' ', apply_filters( 'body_class', $c ) ); // Available filter: body_class
  198.  
  199. // And tada!
  200. return $print ? print($c) : $c;
  201. }
  202.  
  203. // Generates semantic classes for each post DIV element
  204. function codium_extend_post_class( $print = true ) {
  205. global $post, $codium_extend_post_alt;
  206.  
  207. // hentry for hAtom compliace, gets 'alt' for every other post DIV, describes the post type and p[n]
  208. $c = array( 'hentry', "p$codium_extend_post_alt", $post->post_type, $post->post_status );
  209.  
  210. // Author for the post queried
  211. $c[] = 'author-' . sanitize_title_with_dashes(strtolower(get_the_author()));
  212.  
  213. //If post is a sticky post
  214. if (is_sticky())
  215. $c[] = 'sticky';
  216.  
  217. // Category for the post queried
  218. foreach ( (array) get_the_category() as $cat )
  219. $c[] = 'category-' . $cat->slug;
  220.  
  221. // Tags for the post queried; if not tagged, use .untagged
  222. if ( get_the_tags() == null ) {
  223. $c[] = 'untagged';
  224. } else {
  225. foreach ( (array) get_the_tags() as $tag )
  226. $c[] = 'tag-' . $tag->slug;
  227. }
  228.  
  229. // For password-protected posts
  230. if ( $post->post_password )
  231. $c[] = 'protected';
  232.  
  233. // Applies the time- and date-based classes (below) to post DIV
  234. codium_extend_date_classes( mysql2date( 'U', $post->post_date ), $c );
  235.  
  236. // If it's the other to the every, then add 'alt' class
  237. if ( ++$codium_extend_post_alt % 2 )
  238. $c[] = 'alt';
  239.  
  240. // Separates classes with a single space, collates classes for post DIV
  241. $c = join( ' ', apply_filters( 'post_class', $c ) ); // Available filter: post_class
  242.  
  243. // And tada!
  244. return $print ? print($c) : $c;
  245. }
  246.  
  247. // Define the num val for 'alt' classes (in post DIV and comment LI)
  248. $codium_extend_post_alt = 1;
  249. //$codium_extend_comment_alt = 1;
  250.  
  251. // Generates semantic classes for each comment LI element
  252. function codium_extend_comment_class( $print = true ) {
  253. global $comment, $post, $codium_extend_comment_alt;
  254.  
  255. // Collects the comment type (comment, trackback),
  256. $c = array( get_comment_type() );
  257.  
  258. // Counts trackbacks (t[n]) or comments (c[n])
  259. if ( $comment->comment_type == 'comment' ) {
  260. $c[] = "c$codium_extend_comment_alt";
  261. } else {
  262. $c[] = "t$codium_extend_comment_alt";
  263. }
  264.  
  265. // If the comment author has an id (registered), then print the log in name
  266. if ( $comment->user_id > 0 ) {
  267. $user = get_userdata($comment->user_id);
  268. // For all registered users, 'byuser'; to specificy the registered user, 'commentauthor+[log in name]'
  269. $c[] = 'byuser comment-author-' . sanitize_title_with_dashes(strtolower( $user->user_login ));
  270. // For comment authors who are the author of the post
  271. if ( $comment->user_id === $post->post_author )
  272. $c[] = 'bypostauthor';
  273. }
  274.  
  275. // If it's the other to the every, then add 'alt' class; collects time- and date-based classes
  276. codium_extend_date_classes( mysql2date( 'U', $comment->comment_date ), $c, 'c-' );
  277. if ( ++$codium_extend_comment_alt % 2 )
  278. $c[] = 'alt';
  279.  
  280. // Separates classes with a single space, collates classes for comment LI
  281. $c = join( ' ', apply_filters( 'comment_class', $c ) ); // Available filter: comment_class
  282.  
  283. // Tada again!
  284. return $print ? print($c) : $c;
  285. }
  286.  
  287. // count comment
  288. function codium_extend_comment_count( $print = true ) {
  289. global $comment, $post, $codium_extend_comment_alt;
  290.  
  291. // Counts trackbacks and comments
  292. if ( $comment->comment_type == 'comment' ) {
  293. $count[] = "$codium_extend_comment_alt";
  294. } else {
  295. $count[] = "$codium_extend_comment_alt";
  296. }
  297.  
  298. $count = join( ' ', $count ); // Available filter: comment_class
  299.  
  300. // Tada again!
  301. echo $count;
  302. //return $print ? print($count) : $count;
  303. }
  304.  
  305.  
  306. // Generates time- and date-based classes for BODY, post DIVs, and comment LIs; relative to GMT (UTC)
  307. function codium_extend_date_classes( $t, &$c, $p = '' ) {
  308. $t = $t + ( get_option('gmt_offset') * 3600 );
  309. $c[] = $p . 'y' . gmdate( 'Y', $t ); // Year
  310. $c[] = $p . 'm' . gmdate( 'm', $t ); // Month
  311. $c[] = $p . 'd' . gmdate( 'd', $t ); // Day
  312. $c[] = $p . 'h' . gmdate( 'H', $t ); // Hour
  313. }
  314.  
  315. // For category lists on category archives: Returns other categories except the current one (redundant)
  316. function codium_extend_cats_meow($glue) {
  317. $current_cat = single_cat_title( '', false );
  318. $separator = "\n";
  319. $cats = explode( $separator, get_the_category_list($separator) );
  320. foreach ( $cats as $i => $str ) {
  321. if ( strstr( $str, ">$current_cat<" ) ) {
  322. unset($cats[$i]);
  323. break;
  324. }
  325. }
  326. if ( empty($cats) )
  327. return false;
  328.  
  329. return trim(join( $glue, $cats ));
  330. }
  331.  
  332. // For tag lists on tag archives: Returns other tags except the current one (redundant)
  333. function codium_extend_tag_ur_it($glue) {
  334. $current_tag = single_tag_title( '', '', false );
  335. $separator = "\n";
  336. $tags = explode( $separator, get_the_tag_list( "", "$separator", "" ) );
  337. foreach ( $tags as $i => $str ) {
  338. if ( strstr( $str, ">$current_tag<" ) ) {
  339. unset($tags[$i]);
  340. break;
  341. }
  342. }
  343. if ( empty($tags) )
  344. return false;
  345.  
  346. return trim(join( $glue, $tags ));
  347. }
  348.  
  349. if ( ! function_exists( 'codium_extend_posted_on' ) ) :
  350. // data before post
  351. function codium_extend_posted_on() {
  352. printf( __( '<span class="%1$s">Posted on</span> %2$s <span class="meta-sep">by</span> %3$s.', 'codium_extend' ),
  353. 'meta-prep meta-prep-author',
  354. sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
  355. get_permalink(),
  356. esc_attr( get_the_time() ),
  357. get_the_date()
  358. ),
  359. sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>',
  360. get_author_posts_url( get_the_author_meta( 'ID' ) ),
  361. sprintf( esc_attr__( 'View all posts by %s', 'codium_extend' ), get_the_author() ),
  362. get_the_author()
  363. )
  364. );
  365. }
  366. endif;
  367.  
  368. if ( ! function_exists( 'codium_extend_posted_in' ) ) :
  369. // data after post
  370. function codium_extend_posted_in() {
  371. // Retrieves tag list of current post, separated by commas.
  372. $tag_list = get_the_tag_list( '', ', ' );
  373. if ( $tag_list ) {
  374. $posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'codium_extend' );
  375. } elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
  376. $posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'codium_extend' );
  377. } else {
  378. $posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'codium_extend' );
  379. }
  380. // Prints the string, replacing the placeholders.
  381. printf(
  382. $posted_in,
  383. get_the_category_list( ', ' ),
  384. $tag_list,
  385. get_permalink(),
  386. the_title_attribute( 'echo=0' )
  387. );
  388. }
  389. endif;
  390.  
  391.  
  392. // Widgets plugin: intializes the plugin after the widgets above have passed snuff
  393. function codium_extend_widgets_init() {
  394.  
  395. register_sidebar(array(
  396. 'name' => 'SidebarTop',
  397. 'description' => 'Top sidebar',
  398. 'before_widget' => "\n\t\t\t" . '<li id="%1$s" class="widget %2$s"><div class="widgetblock">',
  399. 'after_widget' => "\n\t\t\t</div></li>\n",
  400. 'before_title' => "\n\t\t\t\t". '<div class="widgettitleb"><h3 class="widgettitle">',
  401. 'after_title' => "</h3></div>\n" .''
  402. ));
  403.  
  404. register_sidebar(array(
  405. 'name' => 'SidebarBottom',
  406. 'description' => 'Bottom sidebar',
  407. 'before_widget' => "\n\t\t\t" . '<li id="%1$s" class="widget %2$s"><div class="widgetblock">',
  408. 'after_widget' => "\n\t\t\t</div></li>\n",
  409. 'before_title' => "\n\t\t\t\t". '<div class="widgettitleb"><h3 class="widgettitle">',
  410. 'after_title' => "</h3></div>\n" .''
  411. ));
  412.  
  413. }
  414.  
  415.  
  416.  
  417. // Changes default [...] in excerpt to a real link
  418. function codium_extend_excerpt_more($more) {
  419. global $post;
  420. $readmore = __(' read more <span class="meta-nav">&raquo;</span>', 'codium_extend' );
  421. return ' <a href="'. get_permalink($post->ID) . '">' . $readmore . '</a>';
  422. }
  423. add_filter('excerpt_more', 'codium_extend_excerpt_more');
  424.  
  425.  
  426. // Runs our code at the end to check that everything needed has loaded
  427. add_action( 'init', 'codium_extend_widgets_init' );
  428.  
  429.  
  430. // Adds filters for the description/meta content in archives.php
  431. add_filter( 'archive_meta', 'wptexturize' );
  432. add_filter( 'archive_meta', 'convert_smilies' );
  433. add_filter( 'archive_meta', 'convert_chars' );
  434. add_filter( 'archive_meta', 'wpautop' );
  435.  
  436. // Remember: the codium_extend is for play.
  437.  
  438. // footer link
  439. add_action('wp_footer', 'footer_link');
  440.  
  441. function footer_link() {
  442. $anchorthemeowner='<a href="http://www.code-2-reduction.fr/codium_extend/" title="code reduction" target="blank">code reduction</a>';
  443. $textfooter = __('Proudly powered by <a href="http://www.wordpress.org">Wordpress</a> and designed by ', 'codium_extend' );
  444. $content = '<div id="footerlink"><div class="alignright"><p>' .$textfooter. $anchorthemeowner.'</p></div><div class="clear"></div></div></div>';
  445. echo $content;
  446. }
  447.  
  448. //Remove <p> in excerpt
  449. function codium_extend_strip_para_tags ($content) {
  450. if ( is_home() && ($paged < 2 )) {
  451. $content = str_replace( '<p>', '', $content );
  452. $content = str_replace( '</p>', '', $content );
  453. return $content;
  454. }
  455. }
  456.  
  457. //Comment function
  458. function codium_extend_comment($comment, $args, $depth) {
  459. $GLOBALS['comment'] = $comment; ?>
  460.  
  461. <li id="comment-<?php comment_ID() ?>" class="<?php codium_extend_comment_class() ?>">
  462. <span class="count"><?php echo codium_extend_comment_count();?></span>
  463. <div class="comment-author vcard">
  464. <?php echo get_avatar( $comment, 48 ); ?>
  465. <?php printf(__('<div class="fn">%s</div> '), get_comment_author_link()) ?>
  466. </div>
  467.  
  468. <?php if ($comment->comment_approved == '0') : ?>
  469. <em><?php _e('Your comment is in moderation.') ?></em>
  470. <br />
  471. <?php endif; ?>
  472.  
  473. <div class="comment-meta"><?php printf(__('%1$s - %2$s <span class="meta-sep">|</span> <a href="%3$s" title="Permalink to this comment">Permalink</a>', 'codium_extend'),
  474. get_comment_date(),
  475. get_comment_time(),
  476. '#comment-' . get_comment_ID() );
  477. edit_comment_link(__('Edit', 'codium_extend'), ' <span class="meta-sep">|</span> <span class="edit-link">', '</span>'); ?></div>
  478. <div class="clear"></div>
  479.  
  480. <?php comment_text() ?>
  481.  
  482. <div class="reply">
  483. <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  484. </div>
  485. <?php
  486. }
  487.  
  488. //custom menu support
  489. add_action( 'init', 'codium_extend_register_my_menu' );
  490.  
  491. function codium_extend_register_my_menu() {
  492. register_nav_menu( 'primary-menu', __( 'Primary Menu' ) );
  493. }
  494.  
  495.  
  496. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement