%2$s';
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() )
);
$meta = sprintf( __( '%1$s – by %2$s', 'delivery' ),
sprintf( '%2$s',
esc_url( get_permalink() ),
$time_string
),
sprintf( '%2$s',
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_html( get_the_author() )
)
);
return $meta;
}
endif;
/**
* Prints HTML with meta information for the current post-date/time and author.
*
* @since 1.0.0
*/
function delivery_posted_on() {
echo delivery_get_posted_on();
}
/**
* Site branding for the site.
*
* Display site title by default, but user can change it with their custom logo.
* They can upload it on Customizer page.
*
* @since 1.0.0
*/
function delivery_site_branding() {
$logo = get_theme_mod( 'delivery_logo' );
// Check if logo available, then display it.
if ( $logo ) {
echo '
' . "\n";
// If not, then display the Site Title and Site Description.
} else {
echo '';
echo '' . esc_attr( get_bloginfo( 'description' ) ) . '
';
}
}
/**
* Returns true if a blog has more than 1 category.
*
* @since 1.0.0
* @return bool
*/
function delivery_categorized_blog() {
if ( false === ( $all_the_cool_cats = get_transient( 'delivery_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( 'delivery_categories', $all_the_cool_cats );
}
if ( $all_the_cool_cats > 1 ) {
// This blog has more than 1 category so delivery_categorized_blog should return true.
return true;
} else {
// This blog has only 1 category so delivery_categorized_blog should return false.
return false;
}
}
/**
* Flush out the transients used in delivery_categorized_blog.
*
* @since 1.0.0
*/
function delivery_category_transient_flusher() {
// Like, beat it. Dig?
delete_transient( 'delivery_categories' );
}
add_action( 'edit_category', 'delivery_category_transient_flusher' );
add_action( 'save_post', 'delivery_category_transient_flusher' );
/**
* Sets up different post thumbnail size.
*
* @since 1.0.0
*/
function delivery_post_thumbnail() {
if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
return;
}
// Sets up empty variable.
$size = '';
// Check if on archive or search page.
if ( is_archive() || is_search() ) :
$size = 'delivery-archive';
else :
$size = 'delivery-post';
endif;
?>
'post-thumbnail', 'alt' => esc_attr( get_the_title() ) ) ); ?>
'post',
'posts_per_page' => 4,
'tag' => $tag
);
// The post query
$featured = get_posts( $args );
// Store the transient.
set_transient( 'delivery_featured_posts', $featured );
}
// Check if the post(s) exist.
if ( $featured ) :
$html = '';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
$html .= '
';
foreach ( $featured as $post ) :
setup_postdata( $post );
$html .= '- ';
$html .= '
';
if ( has_post_thumbnail( $post->ID ) ) {
$html .= get_the_post_thumbnail( $post->ID, 'delivery-thumb', array( 'alt' => esc_attr( get_the_title( $post->ID ) ) ) );
}
$html .= '
' . esc_attr( get_the_title( $post->ID ) ) . '
';
$html .= '
';
$html .= ' ';
endforeach;
// Restore original post data.
wp_reset_postdata();
$html .= '
';
$html .= '
';
$html .= '
';
// End check.
endif;
// Display the featured content.
if ( ! empty( $html ) ) {
echo $html;
}
}
/**
* Flush out the transients used in delivery_featured_content.
*
* @since 1.0.0
*/
function delivery_featured_content_transient_flusher() {
delete_transient( 'delivery_featured_posts' );
}
add_action( 'save_post' , 'delivery_featured_content_transient_flusher' );
add_action( 'customize_save', 'delivery_featured_content_transient_flusher' );
/**
* Exclude featured posts from the home page blog query.
*
* @since 1.0.0
*/
function delivery_pre_get_posts( $query ) {
// Bail if not home or not main query.
if ( ! $query->is_home() || ! $query->is_main_query() ) {
return;
}
$page_on_front = get_option( 'page_on_front' );
// Bail if the blog page is not the front page.
if ( ! empty( $page_on_front ) ) {
return;
}
// Get the tag.
$featured = get_theme_mod( 'delivery_featured_posts' );
// Bail if no featured posts.
if ( ! $featured ) {
return;
}
// Get the tag name.
$exclude = get_term_by( 'name', $featured, 'post_tag' );
// Exclude the main query.
$query->set( 'tag__not_in', $exclude->term_id );
}
add_action( 'pre_get_posts', 'delivery_pre_get_posts' );