Tagged: x
-
AuthorPosts
-
April 7, 2016 at 12:08 am #870579
germanpulseParticipantI am looking to add a link to the author’s email on blog posts at the top where the the author’s name and the post’s date already is. I know I will need to modify this in the function.php file in my child theme, but am having a difficult time getting this meta field to show up. I am using the integrity theme if that helps.
So, to be clear, my vision is to have the following displayed at the top of the blog post, under the headline…
By (author name) on (date) / Email Author (clickable email link)April 7, 2016 at 5:24 am #870904
Nabeel AModeratorHi there,
Thanks for writing in! To assist you with this issue, we’ll first need you to provide us with your URL. This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.
April 7, 2016 at 2:56 pm #871792
germanpulseParticipantThe site is being run on my local computer as it is still in development.
April 8, 2016 at 3:25 am #872488
Paul RModeratorHi,
To achieve that, you can add this in your child theme’s functions.php file.
function x_integrity_entry_meta() { // // Author. // $author = sprintf( 'By %s on ', get_the_author() ); $authoremail = sprintf( '<span><a href="mailto:%1$s"> %2$s </a></span>', get_the_author_meta( 'user_email' ), get_the_author_meta( 'user_email' ) ); // // Date. // $date = sprintf( '<span><time class="entry-date" datetime="%1$s"> %2$s</time></span>', esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() ) ); // // Categories. // if ( get_post_type() == 'x-portfolio' ) { if ( has_term( '', 'portfolio-category', NULL ) ) { $categories = get_the_terms( get_the_ID(), 'portfolio-category' ); $separator = ', '; $categories_output = ''; foreach ( $categories as $category ) { $categories_output .= '<a href="' . get_term_link( $category->slug, 'portfolio-category' ) . '" title="' . esc_attr( sprintf( __( "View all posts in: “%s”", '__x__' ), $category->name ) ) . '"><i class="x-icon-bookmark" data-x-icon=""></i> ' . $category->name . '</a>' . $separator; } $categories_list = sprintf( '<span>%s</span>', trim( $categories_output, $separator ) ); } else { $categories_list = ''; } } else { $categories = get_the_category(); $separator = ', '; $categories_output = ''; foreach ( $categories as $category ) { $categories_output .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in: “%s”", '__x__' ), $category->name ) ) . '"><i class="x-icon-bookmark" data-x-icon=""></i> ' . $category->name . '</a>' . $separator; } $categories_list = sprintf( '<span>%s</span>', trim( $categories_output, $separator ) ); } // // Comments link. // if ( comments_open() ) { $title = apply_filters( 'x_entry_meta_comments_title', get_the_title() ); $link = apply_filters( 'x_entry_meta_comments_link', get_comments_link() ); $number = apply_filters( 'x_entry_meta_comments_number', get_comments_number() ); if ( $number == 0 ) { $text = __( 'Leave a Comment' , '__x__' ); } else if ( $number == 1 ) { $text = $number . ' ' . __( 'Comment' , '__x__' ); } else { $text = $number . ' ' . __( 'Comments' , '__x__' ); } $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments"><i class="x-icon-comments" data-x-icon=""></i> %3$s</a></span>', esc_url( $link ), esc_attr( sprintf( __( 'Leave a comment on: “%s”', '__x__' ), $title ) ), $text ); } else { $comments = ''; } // // Output. // if ( x_does_not_need_entry_meta() ) { return; } else { printf( '<p class="p-meta">%1$s%2$s%3$s</p>', $author, $date, $authoremail ); } }Hope that helps.
April 8, 2016 at 8:29 pm #873555
germanpulseParticipantThat code works, but there are some extra modifications I would like to make that seems to break the code. Let me explain the best I can…
I would like the final output on the post to display be as follows:
By [author (this would be a link that would direct to listing of posts by the author)] on [date] / [email (ideally with the email/envelop icon displayed to the left)]April 8, 2016 at 8:33 pm #873561
germanpulseParticipantOne extra note… I want the email link to say Email instead of having the actual email address written out
April 9, 2016 at 6:08 am #874000
ChristopherModeratorHi there,
Please update your code to :
function x_integrity_entry_meta() { // // Author. // $author = sprintf( '<span><a href="%1$s">%2$s</a></span>', get_author_posts_url( get_the_author_meta( 'ID' ) ), get_the_author() ); $authoremail = sprintf( '<span><a href="mailto:%1$s">Email <i class="x-icon-envelope" data-x-icon=""></i> </a></span>', get_the_author_meta( 'user_email' ), get_the_author_meta( 'user_email' ) ); // // Date. // $date = sprintf( '<span><time class="entry-date" datetime="%1$s"> %2$s</time></span>', esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() ) ); // // Categories. // if ( get_post_type() == 'x-portfolio' ) { if ( has_term( '', 'portfolio-category', NULL ) ) { $categories = get_the_terms( get_the_ID(), 'portfolio-category' ); $separator = ', '; $categories_output = ''; foreach ( $categories as $category ) { $categories_output .= '<a href="' . get_term_link( $category->slug, 'portfolio-category' ) . '" title="' . esc_attr( sprintf( __( "View all posts in: “%s”", '__x__' ), $category->name ) ) . '"><i class="x-icon-bookmark" data-x-icon=""></i> ' . $category->name . '</a>' . $separator; } $categories_list = sprintf( '<span>%s</span>', trim( $categories_output, $separator ) ); } else { $categories_list = ''; } } else { $categories = get_the_category(); $separator = ', '; $categories_output = ''; foreach ( $categories as $category ) { $categories_output .= '<a href="' . get_category_link( $category->term_id ) . '" title="' . esc_attr( sprintf( __( "View all posts in: “%s”", '__x__' ), $category->name ) ) . '"><i class="x-icon-bookmark" data-x-icon=""></i> ' . $category->name . '</a>' . $separator; } $categories_list = sprintf( '<span>%s</span>', trim( $categories_output, $separator ) ); } // // Comments link. // if ( comments_open() ) { $title = apply_filters( 'x_entry_meta_comments_title', get_the_title() ); $link = apply_filters( 'x_entry_meta_comments_link', get_comments_link() ); $number = apply_filters( 'x_entry_meta_comments_number', get_comments_number() ); if ( $number == 0 ) { $text = __( 'Leave a Comment' , '__x__' ); } else if ( $number == 1 ) { $text = $number . ' ' . __( 'Comment' , '__x__' ); } else { $text = $number . ' ' . __( 'Comments' , '__x__' ); } $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments"><i class="x-icon-comments" data-x-icon=""></i> %3$s</a></span>', esc_url( $link ), esc_attr( sprintf( __( 'Leave a comment on: “%s”', '__x__' ), $title ) ), $text ); } else { $comments = ''; } // // Output. // if ( x_does_not_need_entry_meta() ) { return; } else { printf( '<p class="p-meta">%1$s%2$s%3$s</p>', $authoremail, $author, $date ); } }Please add the following code in Customize -> Custom -> CSS :
p.p-meta span:nth-child(2):before { content: "By "; } p.p-meta span:nth-child(3):before { content: "On "; } .p-meta>span:after{ content:" "; }Hope that helps.
May 5, 2016 at 9:46 am #914344
germanpulseParticipantFollowup question regarding this… I am using this technique to also show Twitter usernames for authors, but as not everyone that publishes on my site has a Twitter account, is there a way to change the code to only display if the field in their profile includes one?
May 5, 2016 at 3:27 pm #941469
DarshanaModeratorPlease provide us with the link to your site and also post the code that you have tried, so that we can assist you accordingly.
Thanks!
May 5, 2016 at 3:45 pm #944597
germanpulseParticipantThis reply has been marked as private.May 6, 2016 at 12:46 am #978205
Rue NelModeratorHello There,
Thanks for providing the login credentials. I went ahead and changed the code. I have removed this block:
$authortwitter = sprintf( '<span class="p-meta-social"><a href="http://twitter.com/%1$s"> <i class="x-icon-twitter" data-x-icon=""></i> %2$s </a></span>', get_the_author_meta( 'twitter' ), get_the_author_meta( 'twitter' ) );and I have replace it with this block:
$twitter = get_the_author_meta( 'twitter' ); if ( $twitter ) { $authortwitter = sprintf( '<span class="p-meta-social"><a href="http://twitter.com/%1$s"> <i class="x-icon-twitter" data-x-icon=""></i> %2$s </a></span>', get_the_author_meta( 'twitter' ), get_the_author_meta( 'twitter' ) ); }The result is the this:
May 6, 2016 at 9:06 am #978603
germanpulseParticipantAwesome! Thanks so much!!!
May 6, 2016 at 12:16 pm #978831
Prasant RaiModeratorYou are most welcome. 🙂
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-870579 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
