template-functions.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Additional features to allow styling of the templates
  4. *
  5. * @package Radcliffe 2
  6. */
  7. /**
  8. * Adds custom classes to the array of body classes.
  9. *
  10. * @param array $classes Classes for the body element.
  11. * @return array
  12. */
  13. function radcliffe_2_body_classes( $classes ) {
  14. // Adds a class of group-blog to blogs with more than 1 published author.
  15. if ( is_multi_author() ) {
  16. $classes[] = 'group-blog';
  17. }
  18. // Adds a class of hfeed to non-singular pages.
  19. if ( ! is_singular() ) {
  20. $classes[] = 'hfeed';
  21. }
  22. // Adds a class of no-thumbnail to posts with no featured image.
  23. if ( ( is_single() || is_page() ) && radcliffe_2_has_post_thumbnail() ) {
  24. $classes[] = 'has-featured-image';
  25. } else {
  26. $classes[] = 'no-featured-image';
  27. }
  28. if ( is_singular() && get_header_image() ) {
  29. $classes[] = 'single-thumbnail';
  30. }
  31. return $classes;
  32. }
  33. add_filter( 'body_class', 'radcliffe_2_body_classes' );
  34. /**
  35. * Replaces "[...]" (appended to automatically generated excerpts) with ... and a 'Continue reading' link.
  36. * @return string 'Continue reading' link prepended with an ellipsis.
  37. */
  38. if ( ! function_exists( 'radcliffe_2_excerpt_more' ) ) :
  39. function radcliffe_2_excerpt_more( $more ) {
  40. $link = sprintf( '<a href="%1$s" class="more-link">%2$s</a>',
  41. esc_url( get_permalink( get_the_ID() ) ),
  42. /* translators: %s: Name of current post */
  43. sprintf( esc_html__( 'Continue reading %s', 'radcliffe-2' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' )
  44. );
  45. return ' &hellip; ' . $link;
  46. }
  47. add_filter( 'excerpt_more', 'radcliffe_2_excerpt_more' );
  48. endif;
  49. /**
  50. * Add featured image as background image.
  51. */
  52. function radcliffe_2_background_image() {
  53. $image = radcliffe_2_get_attachment_image_src( get_the_ID(), get_post_thumbnail_id( get_the_ID() ), 'radcliffe-post-image' );
  54. if ( ! $image ) {
  55. return;
  56. }
  57. printf( ' style="background-image: url(\'%s\');"', esc_url( $image ) );
  58. }