Skip to content

Instantly share code, notes, and snippets.

@congthien
Created January 19, 2018 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save congthien/d8f3e1c3f86030873bb69849688b5d50 to your computer and use it in GitHub Desktop.
Save congthien/d8f3e1c3f86030873bb69849688b5d50 to your computer and use it in GitHub Desktop.
if ( ! function_exists( 'boston_pro_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function boston_pro_posted_on() {
$posted_on = boston_pro_posted_date();
$byline = '<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>';
$category = get_the_category();
$useCatLink = true;
$cate = '';
// If post has a category assigned.
if ($category){
$category_display = '';
$category_link = '';
if ( class_exists('WPSEO_Primary_Term') )
{
// Show the post's 'Primary' category, if this Yoast feature is available, & one is set
$wpseo_primary_term = new WPSEO_Primary_Term( 'category', get_the_id() );
$wpseo_primary_term = $wpseo_primary_term->get_primary_term();
$term = get_term( $wpseo_primary_term );
if (is_wp_error($term)) {
// Default to first category (not Yoast) if an error is returned
$category_display = $category[0]->name;
$category_link = get_category_link( $category[0]->term_id );
} else {
// Yoast Primary category
$category_display = $term->name;
$category_link = get_category_link( $term->term_id );
}
}
else {
// Default, display the first category in WP's list of assigned categories
$category_display = $category[0]->name;
$category_link = get_category_link( $category[0]->term_id );
}
// Display category
if ( !empty($category_display) ){
if ( $useCatLink == true && !empty($category_link) ){
$cate = '<span class="entry-cate"><a class="entry-category" href="'.esc_url( $category_link ).'">'.htmlspecialchars($category_display).'</a></span>';
} else {
echo '<span class="entry-cate">'.htmlspecialchars($category_display).'</span>';
}
}
}
echo $cate.$byline.$posted_on;
if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
echo '<span class="comments-link">';
echo '<i class="genericon genericon-comment"></i>';
comments_popup_link( '0', '1', '%' );
echo '</span>';
}
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment