( BHARI_SUPPORT_FONTAWESOME ) ? '' : '',
'category' => ( BHARI_SUPPORT_FONTAWESOME ) ? '' : '',
'date' => ( BHARI_SUPPORT_FONTAWESOME ) ? '' : '',
'author' => ( BHARI_POSTMETA_SUPPORT_AUTHOR_IMAGE ) ? get_avatar( esc_url( get_the_author_meta( 'ID' ) ), 50 ) : '',
);
if ( is_tag() ) {
the_archive_title( '
' . $icons['tag'], '
' );
} elseif ( is_category() ) {
the_archive_title( ' ' . $icons['tag'], '
' );
} elseif ( is_date() ) {
the_archive_title( ' ' . $icons['tag'], '
' );
} elseif ( is_author() ) {
the_archive_title( ' ' . $icons['author'], '
' );
} else {
the_archive_title( '', '
' );
}
}
endif;
/**
* Show the post meta
*/
if ( ! function_exists( 'bhari_post_meta' ) ) :
/**
* Show the post meta
*
* @param array $meta_list List of meta data ['author', 'category', 'date' and 'tag'].
* @param string $before Wrapper html before meta markup.
* @param string $after Wrapper html after meta markup.
* @param boolean $echo Is true the print markup else return.
* @return mixed array / html
*/
function bhari_post_meta( $meta_list = array(), $before = '', $after = '', $echo = true ) {
$meta_data = array();
$meta_args = apply_filters( 'bhari_post_meta_args', array(
'meta-separator' => '/',
'meta' => array(
'author' => array(
'before' => ( BHARI_POSTMETA_SUPPORT_AUTHOR_IMAGE ) ? get_avatar( esc_url( get_the_author_meta( 'ID' ) ), 20 ) : '' . __( 'By ', 'bhari' ) . '',
'after' => '',
),
'date' => array(
'before' => ( BHARI_SUPPORT_FONTAWESOME ) ? ' ' : '' . __( 'On ', 'bhari' ) . '',
'after' => '',
),
'category' => array(
'before' => ( BHARI_SUPPORT_FONTAWESOME ) ? ' ' : '' . __( 'Categories ', 'bhari' ) . '',
'after' => '',
),
'tag' => array(
'before' => ( BHARI_SUPPORT_FONTAWESOME ) ? ' ' : '' . __( 'Tags ', 'bhari' ) . '',
'after' => '',
),
),
) );
foreach ( $meta_list as $meta_item ) {
switch ( $meta_item ) {
/**
* Date Meta
*/
case 'author':
$byline = sprintf( // WPCS: XSS OK.
esc_html_x( '%s ', 'post author', 'bhari' ),
'' . esc_html( get_the_author() ) . ''
);
$meta_author = $meta_args['meta']['author']['before'];
$meta_author .= '';
$meta_author .= $byline;
$meta_author .= '';
$meta_author .= $meta_args['meta']['author']['after'];
// Set author meta.
$meta_data['author'] = $meta_author;
break;
/**
* Publish Date Meta
*/
case 'date':
$time_string = '';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
$posted_on = sprintf( // WPCS: XSS OK.
esc_html_x( '%s ', 'post date', 'bhari' ),
'' . $time_string . ''
);
$meta_date = $meta_args['meta']['date']['before'];
$meta_date .= '';
$meta_date .= $posted_on; // WPCS: XSS OK.
$meta_date .= '';
$meta_date .= $meta_args['meta']['date']['after'];
// Set date meta.
$meta_data['date'] = $meta_date;
break;
/**
* Category meta
*
* Translators: used between list items, there is a space after the comma.
*/
case 'category':
$categories_list = get_the_category_list( esc_html__( ', ', 'bhari' ) );
if ( $categories_list && bhari_categorized_blog() ) {
$meta_category = $meta_args['meta']['category']['before'];
$meta_category .= sprintf( ' ' . esc_html__( '%1$s ', 'bhari' ) . '', $categories_list ); // WPCS: XSS OK.
$meta_category .= $meta_args['meta']['category']['after'];
// Set category meta.
$meta_data['category'] = $meta_category;
}
break;
/**
* Tags meta
*
* Translators: used between list items, there is a space after the comma.
*/
case 'tags':
$tags_list = get_the_tag_list( '', esc_html__( ', ', 'bhari' ) );
if ( $tags_list ) {
$meta_tags = $meta_args['meta']['tag']['before'];
$meta_tags .= sprintf( ' ' . esc_html__( '%1$s ', 'bhari' ) . '', $tags_list ); // WPCS: XSS OK.
$meta_tags .= $meta_args['meta']['tag']['after'];
// Set tag meta.
$meta_data['tag'] = $meta_tags;
}
break;
}
}
/**
* Echo / Return meta.
*/
if ( $echo ) {
echo $before;
echo join( $meta_args['meta-separator'], $meta_data );
/**
* Edit link
*/
$edit_icon = ( BHARI_SUPPORT_FONTAWESOME ) ? ' ' : '';
$edit_icon = $meta_args['meta-separator'] . $edit_icon;
edit_post_link(
sprintf(
/* translators: %s: Name of current post */
esc_html__( 'Edit %s', 'bhari' ),
the_title( '"', '"', false )
),
'' . $edit_icon,
''
);
echo $after;
} else {
return $meta_data;
}
}
endif;
/**
* Meta information
*/
if ( ! function_exists( 'bhari_entry_footer_contents' ) ) :
/**
* Prints HTML with meta information for the categories, tags and comments.
*/
function bhari_entry_footer_contents() {
if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
$edit_icon = ( BHARI_SUPPORT_FONTAWESOME ) ? ' ' : '';
echo '';
}
/**
* Edit link
*/
$edit_icon = ( BHARI_SUPPORT_FONTAWESOME ) ? ' ' : '';
edit_post_link(
sprintf(
/* translators: %s: Name of current post */
esc_html__( 'Edit %s', 'bhari' ),
the_title( '"', '"', false )
),
'' . $edit_icon,
''
);
}
add_action( 'bhari_entry_footer', 'bhari_entry_footer_contents' );
endif;
/**
* Category blog
*/
if ( ! function_exists( 'bhari_categorized_blog' ) ) :
/**
* Returns true if a blog has more than 1 category.
*
* @return bool
*/
function bhari_categorized_blog() {
if ( false === ( $all_the_cool_cats = get_transient( 'bhari_categories' ) ) ) {
// Create an array of all the categories that are attached to posts.
$all_the_cool_cats = get_categories( array(
'fields' => 'ids',
'hide_empty' => 1,
// We only need to know if there is more than one category.
'number' => 2,
) );
// Count the number of categories that are attached to the posts.
$all_the_cool_cats = count( $all_the_cool_cats );
set_transient( 'bhari_categories', $all_the_cool_cats );
}
if ( $all_the_cool_cats > 1 ) {
// This blog has more than 1 category so bhari_categorized_blog should return true.
return true;
} else {
// This blog has only 1 category so bhari_categorized_blog should return false.
return false;
}
}
endif;
/**
* Flush out the transients
*/
if ( ! function_exists( 'bhari_category_transient_flusher' ) ) :
/**
* Flush out the transients used in bhari_categorized_blog.
*/
function bhari_category_transient_flusher() {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// Like, beat it. Dig?
delete_transient( 'bhari_categories' );
}
add_action( 'edit_category', 'bhari_category_transient_flusher' );
add_action( 'save_post', 'bhari_category_transient_flusher' );
endif;