An updated theme (based on Atticus Finch) for ClassicPress
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

336 lines
11 KiB

3 years ago
  1. <?php
  2. /**
  3. * Custom template tags for this theme.
  4. *
  5. * Eventually, some of the functionality here could be replaced by core features.
  6. *
  7. * @package Atticus Finch
  8. */
  9. if ( ! function_exists( 'atticus_finch_posted_on' ) ) :
  10. /**
  11. * Prints HTML with meta information for the current post-date/time and author.
  12. */
  13. function atticus_finch_posted_on() {
  14. $date = get_the_date();
  15. $modd = get_the_modified_date();
  16. if ( $modd == $date ) {
  17. printf(__( '<time class="entry-date published updated" datetime="%s">', 'atticus-finch' ), esc_attr( get_the_date( 'c' ) ) );
  18. echo '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">';
  19. printf(__( 'Posted on %s', 'atticus-finch' ), get_the_date() );
  20. $date;
  21. echo '</a></time>';
  22. } else {
  23. printf(__( '<time class="entry-date published updated" datetime="%s">', 'atticus-finch' ), esc_attr( get_the_date( 'c' ) ) );
  24. echo '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">';
  25. printf(__( 'Posted on %s', 'atticus-finch' ), get_the_date() );
  26. $date;
  27. echo '</a>; ';
  28. printf(__( '<time class="updated" datetime="%s">', 'atticus-finch') , esc_attr( get_the_modified_date( 'c' ) ) );
  29. printf(__( 'modified on %s', 'atticus-finch' ), get_the_modified_date() );
  30. echo '</time> ';
  31. }
  32. $byline = sprintf(
  33. esc_html_x( 'by %s', 'post author', 'atticus-finch' ),
  34. '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
  35. );
  36. echo '<span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK.
  37. }
  38. endif;
  39. /**
  40. * Returns true if a blog has more than 1 category.
  41. *
  42. * @return bool
  43. */
  44. function atticus_finch_categorized_blog() {
  45. if ( false === ( $all_the_cool_cats = get_transient( 'atticus_finch_categories' ) ) ) {
  46. // Create an array of all the categories that are attached to posts.
  47. $all_the_cool_cats = get_categories( array(
  48. 'fields' => 'ids',
  49. 'hide_empty' => 1,
  50. // We only need to know if there is more than one category.
  51. 'number' => 2,
  52. ) );
  53. // Count the number of categories that are attached to the posts.
  54. $all_the_cool_cats = count( $all_the_cool_cats );
  55. set_transient( 'atticus_finch_categories', $all_the_cool_cats );
  56. }
  57. if ( $all_the_cool_cats > 1 ) {
  58. // This blog has more than 1 category so atticus_finch_categorized_blog should return true.
  59. return true;
  60. } else {
  61. // This blog has only 1 category so atticus_finch_categorized_blog should return false.
  62. return false;
  63. }
  64. }
  65. /**
  66. * Flush out the transients used in atticus_finch_categorized_blog.
  67. */
  68. function atticus_finch_category_transient_flusher() {
  69. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
  70. return;
  71. }
  72. // Like, beat it. Dig?
  73. delete_transient( 'atticus_finch_categories' );
  74. }
  75. add_action( 'edit_category', 'atticus_finch_category_transient_flusher' );
  76. add_action( 'save_post', 'atticus_finch_category_transient_flusher' );
  77. /* My Stuff */
  78. // Determine whether or not to show page navigation at bottom of index/archive
  79. // Necessary because page navigation is in a styled <div> and should not appear
  80. // on non-paginated pages
  81. function atticus_finch_display_nav() {
  82. $atticus_finch_num_posts = wp_count_posts()->publish;
  83. $atticus_finch_posts_per_page = get_option('posts_per_page ');
  84. if ( $atticus_finch_num_posts > $atticus_finch_posts_per_page) {
  85. echo '<div id="posts-nav">' . get_posts_nav_link(' &bull; ','&laquo; Newer Posts','Older Posts;') . '</div>';
  86. }
  87. }
  88. // Determine whether to display the comments box
  89. function atticus_finch_comment_display() {
  90. $var = get_comments_number();
  91. if ( comments_open() || $var > 0 ) {
  92. comments_template();
  93. } else { echo '
  94. <div id="comments">
  95. <div id="respond">
  96. <p>' . __( 'Sorry, but comments are closed.', 'atticus-finch' ) . '</p>
  97. </div>
  98. </div>';
  99. }
  100. }
  101. // Display the time
  102. // Included here if we need to change it later
  103. function atticus_finch_date() {
  104. return get_the_time(get_option('date_format'));
  105. }
  106. // Display publication info as a translatable string in 'content-entry-meta.php'
  107. function atticus_finch_pub() {
  108. $atticus_finch_author_link = get_author_posts_url( get_the_author_meta( 'ID' ) );
  109. $atticus_finch_author_href = '<a href="' . $atticus_finch_author_link . '">' . get_the_author() . '</a>';
  110. echo '<a href="' . get_permalink() . '">';
  111. printf( __( 'Published on: %1$s by %2$s', 'atticus-finch' ), atticus_finch_date(), $atticus_finch_author_href );
  112. echo '</a>';
  113. }
  114. // Display category info as a translatable string in 'content-entry-meta.php'
  115. function atticus_finch_cat() {
  116. $gbcat = get_the_category_list( ', ' );
  117. printf( __( 'Categorized under: %s', 'atticus-finch'), $gbcat );
  118. }
  119. // Display tags info as a translatable string in 'content-entry-meta.php'
  120. function atticus_finch_tags() {
  121. $tags_array = has_tag();
  122. if (!empty($tags_array)) {
  123. printf( __( 'Tagged with: %s', 'atticus-finch'), get_the_tag_list('', ', ', '' ) );
  124. } else {
  125. _e( 'This post has no tags.', 'atticus-finch' );
  126. }
  127. }
  128. // Display next post link only if a newer post exists
  129. function atticus_finch_next_post_link() {
  130. $atticus_finch_npl = get_next_post_link();
  131. if ( empty ( $atticus_finch_npl ) ) {
  132. echo '<p>' . __( 'You are reading the newest post.', 'atticus-finch' ) . '</p>';
  133. } else {
  134. echo '<p>' . __( 'Read a newer post:', 'atticus-finch' ) . '</p>';
  135. next_post_link();
  136. }
  137. }
  138. // Display previous post link only if an older post exists
  139. function atticus_finch_prev_post_link() {
  140. $atticus_finch_ppl = get_previous_post_link();
  141. if ( empty ( $atticus_finch_ppl ) ) {
  142. echo '<p>>' . __( 'You are reading the oldest post.', 'atticus-finch' ) . '</p>';
  143. } else {
  144. echo '<p>' . __( 'Read an older post:', 'atticus-finch' ) . '</p>';
  145. previous_post_link();
  146. }
  147. }
  148. // Add the URL information when printing
  149. function atticus_finch_print_url() {
  150. echo '<p class="printonly printurl">';
  151. printf(__( 'Link for this article:', 'atticus-finch' ) );
  152. echo '<br /><span class="printurl-url">' . get_the_permalink() . '<span></p>';
  153. }
  154. // Add a "Read More" box on excerpts
  155. function atticus_finch_read_more() {
  156. echo '<p class="read-more"><a href="' . get_the_permalink() . '">';
  157. printf(__( 'Read the complete article&hellip;', 'atticus-finch' ) );
  158. echo '</a></p>';
  159. }
  160. // Take care of wp_link_pages
  161. function atticus_finch_link_pages() {
  162. $defaults = array(
  163. 'before' => '<div id="link-pages">' . __( 'This post has multiple pages:', 'atticus-finch' ),
  164. 'after' => '</div>',
  165. 'link_before' => '',
  166. 'link_after' => '',
  167. 'next_or_number' => 'number',
  168. 'separator' => '&ensp;',
  169. 'nextpagelink' => __( 'Next page', 'atticus-finch' ),
  170. 'previouspagelink' => __( 'Previous page', 'atticus-finch' ),
  171. 'pagelink' => '%',
  172. 'echo' => 1
  173. );
  174. wp_link_pages( $defaults );
  175. }
  176. // Print options
  177. function atticus_finch_print_options() {
  178. if ( get_theme_mod( 'atticus_finch_print_copyright' ) == '1' ) {
  179. echo '<span class="printonly printcopyright">' .
  180. get_theme_mod( 'atticus_finch_copyright', '<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" id="cc-button" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a>This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.' ) .
  181. '</span>';
  182. }
  183. if ( get_theme_mod( 'atticus_finch_print_url' ) == '1' ) {
  184. echo '<span class="printonly printurl">';
  185. printf(__( 'Permalink for this article:', 'atticus-finch' ) );
  186. echo '<br /><span class="printurl-url">' . get_the_permalink() . '<span></span>';
  187. }
  188. }
  189. // Edit post link, if user is logged in
  190. function atticus_finch_edit_post() {
  191. if ( get_theme_mod( 'atticus_finch_edit_post_link' ) == '1' && is_user_logged_in() ) : {
  192. edit_post_link('Edit this post', '<p class="edit-post">', '</p>');
  193. }
  194. endif;
  195. }
  196. // Footer options
  197. function atticus_finch_display_footer_copyright() {
  198. if ( get_theme_mod( 'atticus_finch_display_copyright' ) == '1' ) : {
  199. echo '<div id="copyright">' .
  200. get_theme_mod( 'atticus_finch_copyright', '<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" id="cc-button" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a>This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.' ) .
  201. '</div>';
  202. }
  203. endif;
  204. }
  205. function atticus_finch_display_footer_credits() {
  206. if ( get_theme_mod( 'atticus_finch_display_credits') == '1' ) : {
  207. $afwp = '<a href="http://wordpress.org/">WordPress</a>';
  208. $afaf = '<a href="http://d12webdesign.com/">Atticus Finch Theme</a>';
  209. echo '<div id="credits">';
  210. printf(__( 'Powered by %1$s and the %2$s.', 'atticus-finch' ), $afwp, $afaf );
  211. echo '</div>';
  212. }
  213. endif;
  214. }
  215. // Custom CSS Option
  216. function atticus_finch_custom_css_head() {
  217. $afcss = get_theme_mod( 'atticus_finch_ccss' );
  218. if ( !empty( $afcss ) ) {
  219. echo '<style type="text/css">/* Atticus Finch Custom CSS */' . "\n" . get_theme_mod( 'atticus_finch_ccss' ) . "\n" . '</style>';
  220. }
  221. }
  222. // Social Media
  223. function atticus_finch_social_media_display() {
  224. if ( get_theme_mod( 'atticus_finch_rss' ) == '1' ) {
  225. echo '<a href="' . site_url() . '/feed" class="sm-rss"><span class="fa fa-rss-square"></span></a>';
  226. }
  227. $aftw = get_theme_mod( 'atticus_finch_twitter' );
  228. if ( !empty( $aftw ) ) {
  229. echo '<a href="' . get_theme_mod( 'atticus_finch_twitter' ) . '" target="_blank" class="sm-twitter"><span class="fa fa-twitter-square"></span></a>';
  230. }
  231. $aft2 = get_theme_mod( 'atticus_finch_twitter2' );
  232. if ( !empty( $aft2 ) ) {
  233. echo '<a href="' . get_theme_mod( 'atticus_finch_twitter2' ) . '" target="_blank" class="sm-twitter"><span class="fa fa-twitter-square"></span></a>';
  234. }
  235. $affb = get_theme_mod( 'atticus_finch_facebook' );
  236. if ( !empty( $affb ) ) {
  237. echo '<a href="' . get_theme_mod( 'atticus_finch_facebook' ) . '" target="_blank" class="sm-facebook"><span class="fa fa-facebook-square"></span></a>';
  238. }
  239. $afig = get_theme_mod( 'atticus_finch_instagram' );
  240. if ( !empty( $afig ) ) {
  241. echo '<a href="' . get_theme_mod( 'atticus_finch_instagram' ) . '" target="_blank" class="sm-instagram"><span class="fa fa-instagram"></span></a>';
  242. }
  243. $afyt = get_theme_mod( 'atticus_finch_youtube' );
  244. if ( !empty( $afyt ) ) {
  245. echo '<a href="' . get_theme_mod( 'atticus_finch_youtube' ) . '" target="_blank" class="sm-youtube"><span class="fa fa-youtube-square"></span></a>';
  246. }
  247. $afyt = get_theme_mod( 'atticus_finch_pinterest' );
  248. if ( !empty( $afyt ) ) {
  249. echo '<a href="' . get_theme_mod( 'atticus_finch_pinterest' ) . '" target="_blank" class="sm-pinterest"><span class="fa fa-pinterest-square"></span></a>';
  250. }
  251. $afam = get_theme_mod( 'atticus_finch_amazon' );
  252. if ( !empty( $afam ) ) {
  253. echo '<a href="' . get_theme_mod( 'atticus_finch_amazon' ) . '" target="_blank" class="sm-amazon"><span class="fa fa-amazon"></span></a>';
  254. }
  255. }
  256. // Mobile Top Link Options
  257. function atticus_finch_footer_top_link() {
  258. if ( get_theme_mod( 'atticus_finch_footer_top_link' ) == 1 ) {
  259. echo '<a href="#" class="top-button">';
  260. _e( 'Return to Top', 'atticus-finch' );
  261. echo '</a>';
  262. } else {
  263. return;
  264. }
  265. }
  266. function atticus_finch_post_top_link() {
  267. if ( get_theme_mod( 'atticus_finch_post_top_link' ) == 1 ) {
  268. echo '<a href="#" class="top-button">';
  269. _e( 'Return to Top', 'atticus-finch' );
  270. echo '</a>';
  271. } else {
  272. return;
  273. }
  274. }