hp-templates.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**********************************
  3. ######### WordPress Menus #########
  4. ***********************************/
  5. function hp_donate_nav_item( $items, $args ) {
  6. if( $args->theme_location == 'primary' ) {
  7. $items = $items .'<li id="donate-button" class="menu-item nav-item ps-lg-3">'."\n".'<a class="btn btn-outline-light" href="'.home_url().'/donate" role="button">Donate</a></li>';
  8. }
  9. return $items;
  10. }
  11. add_filter('wp_nav_menu_items','hp_donate_nav_item',10,2);
  12. function hp_list_child_pages() {
  13. global $post;
  14. $children = get_pages( array( 'child_of' => $post->ID ) );
  15. $hasChild = (count( $children ) > 0 );
  16. $page_id = ($hasChild) ? $post->ID : wp_get_post_parent_id( $post->ID );
  17. wp_list_pages( array(
  18. 'title_li' => '',
  19. 'sort_column' => 'post_title',
  20. 'child_of' => $page_id,
  21. ));
  22. }
  23. add_shortcode('hp_childpages', 'hp_list_child_pages');
  24. function wp_list_pages_filter($output) {
  25. $output = str_replace('page_item', 'nav-item list-group-item py-1 p-0', $output);
  26. return $output;
  27. }
  28. add_filter('wp_list_pages', 'wp_list_pages_filter');
  29. /**********************************
  30. ######### WordPress Posts #########
  31. ***********************************/
  32. if ( ! function_exists( 'hp_posted_on' ) ) :
  33. function hp_posted_on() {
  34. $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
  35. if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
  36. $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
  37. }
  38. $time_string = sprintf( $time_string,
  39. esc_attr( get_the_date( 'c' ) ),
  40. esc_html( get_the_date() )
  41. );
  42. $posted_on = sprintf(
  43. esc_html_x( 'Posted on %s', 'post date', 'wp-bootstrap-starter' ),
  44. '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
  45. );
  46. $byline = sprintf(
  47. esc_html_x( 'by %s', 'post author', 'wp-bootstrap-starter' ),
  48. '<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>'
  49. );
  50. echo '<span class="posted-on">' . $posted_on . '</span> | <span class="byline"> ' . $byline . '</span>'; //
  51. if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
  52. echo ' | <span class="comments-link"><i class="fa fa-comments" aria-hidden="true"></i> ';
  53. comments_popup_link( sprintf( wp_kses( __( 'Leave a Comment<span class="screen-reader-text"> on %s</span>', 'wp-bootstrap-starter' ), array( 'span' => array( 'class' => array() ) ) ), get_the_title() ) );
  54. echo '</span>';
  55. }
  56. }
  57. endif;
  58. if ( ! function_exists( 'hp_entry_footer' ) ) :
  59. function hp_entry_footer() {
  60. if ( 'post' === get_post_type() ) {
  61. $categories_list = get_the_category_list( esc_html__( ', ' ) );
  62. if ( $categories_list && wp_bootstrap_starter_categorized_blog() ) {
  63. printf( '<span class="cat-links">' . esc_html__( 'Posted in %1$s') . '</span>', $categories_list );
  64. }
  65. $tags_list = get_the_tag_list( '', esc_html__( ', ') );
  66. if ( $tags_list ) {
  67. printf( ' | <span class="tags-links">' . esc_html__( 'Tagged %1$s' ) . '</span>', $tags_list );
  68. }
  69. }
  70. edit_post_link(
  71. sprintf(
  72. esc_html__( 'Edit %s', 'wp-bootstrap-starter' ),
  73. the_title( '<span class="screen-reader-text">"', '"</span>', false )
  74. ),
  75. ' | <span class="edit-link">',
  76. '</span>'
  77. );
  78. }
  79. endif;