- This topic has 22 replies, 5 voices, and was last updated 3 years, 2 months ago by
Tom.
-
AuthorPosts
-
December 7, 2018 at 11:01 pm #751206
Kemo
I would like to move my breadcrumbs NavXT which I’m displaying above the post title, to inside the entry-meta – at the end of it.
So that it would say December 5th by Jane Summers filed in Health > Fitness > Yoga
Is there a hook for that?
thanks a lot!
December 8, 2018 at 8:46 am #751523Leo
StaffCustomer SupportHi there,
How are you adding the breadcrumbs?
With a shortcode?
December 8, 2018 at 4:53 pm #751721Kemo
I’m using elements(hook):
<?php if ( function_exists( 'bcn_display' ) && ! is_front_page() ) : ?> <div class="breadcrumbs"> <?php bcn_display(); ?> </div> <?php endif; ?>
hook:before_entry_title
thanks
December 8, 2018 at 6:48 pm #751748Leo
StaffCustomer SupportCan you try this snippet here?
add_filter( 'generate_post_author_output', 'lh_breadcrumb_to_author' ); function lh_breadcrumb_to_author( $output ) { echo $output . ' - '; if ( function_exists( 'bcn_display' ) && ! is_front_page() ) { echo '<div class="breadcrumbs">'; bcn_display(); echo '</div>'; } }
Adding PHP: https://docs.generatepress.com/article/adding-php/
December 8, 2018 at 9:30 pm #751799Kemo
it works. thanks a lot, Leo!!
December 9, 2018 at 10:29 am #752205Leo
StaffCustomer SupportNo problem ๐
December 23, 2018 at 1:45 am #764037Junior Gong
I would like to add the number of comments at the end of the the entry-meta div. How can I achieve that?
Currently I am using an element to display content with the hook
after_entry_title
An actual hook at the end of entry-meta div would be great long term since it seems like an often customized piece of information
December 23, 2018 at 8:35 am #764273Kemo
There’s no hook for that but similar to what Leo did:
to add “something” at the end of meta:
add_filter( 'generate_post_author_output', 'add_to_end_of_meta' ); function add_to_end_of_meta( $output ) { echo $output . ' something'; }
add this to your functions.php of your child theme
or number of comments:
add_filter( 'generate_post_author_output', 'add_to_end_of_meta' ); function add_to_end_of_meta( $output ) { echo $output . comments_number( 'no responses', 'one response', '% responses' ); }
source: https://codex.wordpress.org/Function_Reference/comments_number
let me know if it works. cheers
December 23, 2018 at 8:46 am #764275Tom
Lead DeveloperLead DeveloperNice solution, Jacob! Thanks! ๐
December 23, 2018 at 7:12 pm #764488Junior Gong
That’s a great solution!
Two things:
1. Now it reads ‘x comments by author’ since it is appended the comment count before the author’s name. My original goal was to add it after the author’s name though.
Is there any way to put the number of comments after the author’s name?
2. How can I add a comment icon
<i class="fa fa-comments-o"></i>
before the comment count?December 24, 2018 at 10:06 am #764830Tom
Lead DeveloperLead DeveloperTry this instead:
add_filter( 'generate_post_author_output', function( $output ) { $comment_text = '<span class="comments-number">' . get_comments_number_text( 'No comments', '1 comment', '% comments' ) . '</span>'; echo $output . $comment_text; } );
To add an icon, you’d need to add Font Awesome to the site: https://wordpress.org/plugins/font-awesome/
Then you could replace this:
<span class="comments-number">
With this:
<span class="comments-number"><i class="far fa-comments"></i>
December 26, 2018 at 9:55 pm #766341Junior Gong
hey Tom
thx for the input. From the old hooks guide I still have this code:
add_shortcode( 'comment_number', 'tu_comment_number_sc' ); function tu_comment_number_sc() { ob_start(); comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) ); return ob_get_clean(); }
How can I combine the snippet you mentioned above with the
comments_popup_link
function?December 27, 2018 at 9:26 am #766812Tom
Lead DeveloperLead DeveloperYou could try this:
add_filter( 'generate_post_author_output', function( $output ) { echo $output; comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) ); } );
December 27, 2018 at 6:50 pm #767190Junior Gong
Thx Tom, that works. Now I only want to add the FA comments icon and add a
|
in front of it so it looks like:[date] by [author] | <i class="fa fa-comments-o"></i> 100 Comments
December 28, 2018 at 10:12 am #767891Tom
Lead DeveloperLead DeveloperIn that case, you would do this:
add_filter( 'generate_post_author_output', function( $output ) { echo $output . ' | <i class="fa fa-comments-o"></i>'; comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) ); } );
-
AuthorPosts
- You must be logged in to reply to this topic.