content-card.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Template part for displaying posts.
  4. *
  5. * @link https://codex.wordpress.org/Template_Hierarchy
  6. *
  7. * @package TextBook
  8. */
  9. ?>
  10. <article id="post-<?php the_ID(); ?>" tabindex="0" <?php post_class( 'card' ); ?>>
  11. <header class="entry-header">
  12. <?php // Hide category text for everything but posts
  13. if ( 'post' === get_post_type() ) { ?>
  14. <div class="entry-meta">
  15. <?php $category = get_the_category();
  16. $category_count = is_countable( $category ) ? count( $category ) : 0;
  17. if ( $category && $category_count >= 2 ) {
  18. $cat_links = '<a href="' . esc_url( get_permalink() ) . '">' . $category[0]->name.'&hellip;</a>';
  19. } elseif ( $category ) {
  20. $cat_links = '<a href="' . esc_url( get_permalink() ) . '">' . $category[0]->name.'</a>';
  21. }
  22. echo '<span class="cat-links">' . $cat_links . '</span>'; ?>
  23. </div>
  24. <?php } ?>
  25. <?php the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' ); ?>
  26. <?php if ( '' != get_the_post_thumbnail() ) :
  27. $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'textbook-featured-content-image' ); ?>
  28. <div class="post-thumbnail" style="background-image:url(<?php echo esc_url( $large_image_url[0] ); ?>);"></div>
  29. <?php endif; ?>
  30. </header>
  31. <div class="entry-content">
  32. <?php // Hide category text for everything but posts
  33. if ( 'post' === get_post_type() ) { ?>
  34. <div class="entry-meta">
  35. <?php // Date
  36. $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
  37. if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
  38. $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
  39. }
  40. if ( get_option( 'date_format' ) != 'F j, Y' ) {
  41. $date_format = esc_html( get_the_date() );
  42. } else {
  43. $date_format = '<span class="day">' . esc_html( get_the_date( 'j' ) ) . '</span> <span class="month-year">' . esc_html( get_the_date( 'M Y' ) ) . '</span>';
  44. }
  45. $time_string = sprintf( $time_string,
  46. esc_attr( get_the_date( 'c' ) ),
  47. $date_format,
  48. esc_attr( get_the_modified_date( 'c' ) ),
  49. esc_html( get_the_modified_date() )
  50. );
  51. $posted_on = '<a href="' . esc_url( get_permalink() ) . '" tabindex="-1" rel="bookmark">' . $time_string . '</a>';
  52. echo '<span class="posted-on">' . $posted_on . '</span>'; ?>
  53. </div>
  54. <?php } ?>
  55. <?php
  56. // Custom excerpt and read more link
  57. $content = get_the_content();
  58. $content = strip_shortcodes( $content );
  59. $content = wp_trim_words( $content, '30' );
  60. echo '<a href="' . esc_url( get_permalink() ) . '" tabindex="-1" rel="bookmark"><span>' . $content . '</span></a>';
  61. ?>
  62. <?php edit_post_link( esc_html__( 'Edit', 'textbook' ), '<span class="edit-link">', '</span>'); ?>
  63. </div>
  64. <?php // A star to sticky posts
  65. if ( is_sticky() ) {?>
  66. <svg class="star" x="0px" y="0px" width="16px" height="16px" viewBox="0 0 16 16" xml:space="preserve">
  67. <g id="Polygon_1_3_"><g>
  68. <polygon points="14,7.01 9.41,7.018 8,2.833 6.59,7.018 2,7.01 5.718,9.588 4.292,13.768 8,11.175 11.708,13.768 10.282,9.588"/>
  69. </g></g>
  70. </svg>
  71. <?php } ?>
  72. </article><!-- #post-## -->