functions.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. function popper_child_setup(){
  3. // preparar o tema para a traducao
  4. load_child_theme_textdomain( 'popper-child', get_stylesheet_directory() . '/languages' );
  5. // registrar outro menu no rodape
  6. register_nav_menus( array(
  7. 'rodape' => esc_html__( 'Menu do Rodape', 'popper-child' ),
  8. ) );
  9. /**
  10. * Register 2 widget area.
  11. *
  12. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  13. */
  14. function popper_child_widgets_init_footer() {
  15. register_sidebar( array(
  16. 'name' => esc_html__( 'Widget Area no Footer', 'popper-child' ),
  17. 'id' => 'sidebar-foooter',
  18. 'description' => '',
  19. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  20. 'after_widget' => '</aside>',
  21. 'before_title' => '<h2 class="widget-title">',
  22. 'after_title' => '</h2>',
  23. ) );
  24. }
  25. add_action( 'widgets_init', 'popper_child_widgets_init_footer' );
  26. }
  27. add_action('after_setup_theme', 'popper_child_setup');
  28. /**
  29. * Enqueue scripts and styles.
  30. */
  31. function popper_child_scripts() {
  32. // Fonts: Fira Sans and Merriweather, https://www.google.com/fonts
  33. wp_enqueue_style( 'popper-child-google-fonts', '//fonts.googleapis.com/css?family=Alegreya+Sans+SC:400,400i,500,500i,800,800i|Anonymous+Pro:400,400i,700,700i' );
  34. // des-enfilirar styles do tema pai
  35. wp_dequeue_style('popper-google-fonts');
  36. }
  37. add_action( 'wp_enqueue_scripts', 'popper_child_scripts', 11);
  38. // 11 para ser executado depois do popper_script do pai. o padrao é 10
  39. // https://developer.wordpress.org/reference/functions/add_action/
  40. function popper_posted_on() {
  41. $author_id = get_the_author_meta( 'ID' );
  42. $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
  43. if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
  44. $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
  45. }
  46. $time_string = sprintf( $time_string,
  47. esc_attr( get_the_date( 'c' ) ),
  48. esc_html( get_the_date() ),
  49. esc_attr( get_the_modified_date( 'c' ) ),
  50. esc_html( get_the_modified_date() )
  51. );
  52. $posted_on = sprintf(
  53. esc_html_x( ' on %s', 'post date', 'popper-child' ),
  54. '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
  55. );
  56. $byline = sprintf(
  57. esc_html_x( 'by %s', 'post author', 'popper-child' ),
  58. '<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>'
  59. );
  60. // Display author avatar if author has a Gravatar
  61. if ( validate_gravatar( $author_id ) ) {
  62. echo '<div class="meta-content has-avatar">';
  63. echo '<div class="author-avatar">' . get_avatar( $author_id ) . '</div>';
  64. } else {
  65. echo '<div class="meta-content">';
  66. }
  67. echo '<span class="byline">' . $byline . ' </span><span class="posted-on">' . $posted_on . ' </span>'; // WPCS: XSS OK.
  68. $categories_list = get_the_category_list( esc_html__( ', ', 'popper-child' ) );
  69. if ( $categories_list && popper_categorized_blog() ) {
  70. printf( '<span class="cat-links">' . esc_html__( 'Posted in %1$s', 'popper-child' ) . '</span>', $categories_list ); // WPCS: XSS OK.
  71. }
  72. if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
  73. echo '<span class="comments-link">';
  74. comments_popup_link( esc_html__( 'Leave a comment', 'popper-child' ), esc_html__( '1 Comment', 'popper-child' ), esc_html__( '% Comments', 'popper-child' ) );
  75. echo '</span>';
  76. }
  77. echo '</div><!-- .meta-content -->';
  78. }
  79. function popper_index_posted_on() {
  80. $author_id = get_the_author_meta( 'ID' );
  81. $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
  82. if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
  83. $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
  84. }
  85. $time_string = sprintf( $time_string,
  86. esc_attr( get_the_date( 'c' ) ),
  87. esc_html( get_the_date() ),
  88. esc_attr( get_the_modified_date( 'c' ) ),
  89. esc_html( get_the_modified_date() )
  90. );
  91. $posted_on = sprintf(
  92. esc_html_x( 'Published %s', 'post date', 'popper' ),
  93. '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
  94. );
  95. $byline = sprintf(
  96. esc_html_x( 'by %s', 'post author', 'popper' ),
  97. '<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>'
  98. );
  99. echo '<div class="meta-content">';
  100. echo '<span class="byline">' . $byline . ' </span><span class="posted-on">' . $posted_on . ' </span>'; // WPCS: XSS OK.
  101. $categories_list = get_the_category_list( esc_html__( ', ', 'popper-child' ) );
  102. if ( $categories_list && popper_categorized_blog() ) {
  103. printf( '<span class="cat-links">' . esc_html__( 'Posted in %1$s', 'popper-child' ) . '</span>', $categories_list ); // WPCS: XSS OK.
  104. }
  105. if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
  106. echo '<span class="comments-link">';
  107. comments_popup_link( esc_html__( 'Leave a comment', 'popper' ), esc_html__( '1 Comment', 'popper' ), esc_html__( '% Comments', 'popper' ) );
  108. echo '</span>';
  109. }
  110. echo '</div><!-- .meta-content -->';
  111. }
  112. ?>