'',
'separator' => '',
'show_home' => false,
'show_current' => false,
);
$args = (object)wp_parse_args( $args, $defaults );
// Avoid pages with multiple entries - makes no sense.
if ( is_front_page() || is_home() || is_archive() ) return '';
// See if there is a label that should be displayed.
$label = '';
if ( !empty( $args->label ) ) $label = ''.$args->label.'';
// Prepare the crumbs in an array.
$levels = array();
// First, figure out what the visitor is looking at to determine the crumb content.
if ( function_exists( 'is_product' ) && is_product() )
{
$crumbs = ( new \WC_Breadcrumb() )->generate();
foreach ( $crumbs as $key => $crumb )
{
$name = $crumb[0];
$url = $crumb[1];
if ( !empty( $url ) )
{
$levels[] = ''.esc_html( $name ).'';
}
}
}
else if ( is_category() || is_single() || is_attachment() )
{
$levels =
array_merge(
$levels,
array_map(
function( $el )
{
return ''.esc_html( $el->name ).'';
},
get_the_category()
)
);
}
// If there is no crumb content by this point, get out of here and display nothing.
if ( empty( $levels ) ) return '';
// Then, on with the currently-viewed item.
if ( ( $args->show_current ) && ( is_single() || is_page() ) ) $levels[] = get_the_title();
// Finally, prepend the home link - this is done last so the earlier check for any crumbs could be done.
if ( $args->show_home ) array_unshift( $levels, ''.get_bloginfo( 'name' ).'' );
// Glue the elements together into a single line - the array_filter
// call automatically removes empty elements from being included.
//
// Note: The apparent-backwards
element pairing is intentional.
return
'
'.
''.
$label.
'
'.
implode( '
'.$args->separator.'
', array_filter( $levels ) ).
'
'.
''.
'
';
}
/**
* Generates the markup that displays all comments for a given page/post.
*
* @link http://themeshaper.com/2012/11/04/the-wordpress-theme-comments-template/
* @param array $args Can be any of the following arguments:
* TBD
* @return string The markup
*/
function tag_comments( $args = array() )
{
// Merge default arguments and the arguments supplied by the caller.
$defaults = array(
// TBD
);
$args = (object)wp_parse_args( $args, $defaults );
// Only show comments if there is a post or similar.
global $post;
if ( empty( $post ) ) return '';
// If comments are open or we have at least one comment, load up the comment template -
// note that products should not have comments as they already have a reviews tab.
ob_start();
if ( ( comments_open() || '0' != get_comments_number() ) && !( function_exists( 'is_product' ) && is_product() ) )
{
comments_template( '', true );
}
// Display it.
return ob_get_clean();
}
/**
* Retrieves and displays the featured image from the current
* post as a small and square thumbnail that floats around
* corresponding text (typically the excerpt).
*
* @param array $args Can be any of the following arguments:
* TBD
* @return string The desired image markup
*/
function tag_featured_image_emblem( $args = array() )
{
//DAN-HACK: Start
//
// Special case for the customizer preview template.
if ( is_viewing_preview() )
{
global $preview;
return
'
'.
$preview->post_thumbnail.
'
';
}
//
//DAN-HACK: End
// Merge default arguments and the arguments supplied by the caller.
$defaults = array(
// TBD
);
$args = (object)wp_parse_args( $args, $defaults );
// Prep the ID of the image.
$image_id = get_post_thumbnail_id();
$image_id = apply_filters( 'filter_bpq_featured_image_id', $image_id );
// Turn the ID into some markup.
$image_markup =
wp_get_attachment_image (
$image_id,
'thumbnail',
0,
array (
'alt' => get_the_title(),
'class' => 'attachment-thumbnail wp-post-image',
)
);
// Construct the markup.
if ( !empty( $image_markup ) )
{
return
'
';
}
// Making it here means that nothing was really done.
return '';
}
/**
* Retrieves and displays the featured image from the current
* post as a long horizontal and cropped image spanning the
* width of the container (typically the article).
*
* @param array $args Can be any of the following arguments:
* TBD
* @return string The desired image markup
*/
function tag_featured_image_pennant( $args = array() )
{
//DAN-HACK: Start
//
// Special case for the customizer preview template.
if ( is_viewing_preview() )
{
global $preview;
return
'
'.
'
';
}
//
//DAN-HACK: End
// Merge default arguments and the arguments supplied by the caller.
$defaults = array(
// TBD
);
$args = (object)wp_parse_args( $args, $defaults );
// Prep the ID of the image.
$image_id = get_post_thumbnail_id();
$image_id = apply_filters( 'filter_bpq_featured_image_id', $image_id );
// Try to get the main image from the featured image.
$image_src = '';
$image_meta = \ski\media::get_meta_info( $image_id );
if ( !empty( $image_meta ) )
{
$image_src = $image_meta['src'];
}
// Construct the markup.
if ( !empty( $image_src ) )
{
return
'
'.
'
';
}
// Making it here means that nothing was really done.
return '';
}
/**
* Generates a prominent highlighted area associated with
* the current post typically displays the post title
* just above the post.
*
* @param array $args Can be any of the following arguments:
* string $span_class Can be Bootstrap's 'container' or 'container-fluid'
* string $text The text to display
* string $subtext The smaller text to display below the main text
* string $align_class Can be 'ml', 'mc', or 'mr' for left, center, or right text alignment
* string $context_class An optional descriptive class that is applied to the containers
* @return string The generated markup
*/
function tag_highlight( $args = array() )
{
// Merge default arguments and the arguments supplied by the caller.
$defaults = array(
'span_class' => 'container-fluid',
'text' => '',
'subtext' => '',
'align_class' => 'mc',
'context_class' => '',
);
$args = (object)wp_parse_args( $args, $defaults );
// Filter.
$args->text = apply_filters( 'filter_bpq_highlight_text', $args->text );
$args->subtext = apply_filters( 'filter_bpq_highlight_subtext', $args->subtext );
// Text.
if ( empty( $args->text ) ) return '';
ob_start();
echo
'
';
// The markup - wrap the content in a Bootstrap row to ensure
// margins match up with the sidebar/content areas.
return
'
'.
'
'.
'
'.
'
'.
ob_get_clean().
'
'.
'
'.
'
'.
'
';
}
/**
* Puts together the full "sha-bang" of metadata for posts.
*
* @param array $args Can be any of the following arguments:
* boolean $include_author Send 'false' to omit this info
* boolean $include_categories Send 'false' to omit this info
* boolean $include_comments Send 'false' to omit this info
* boolean $include_date Send 'false' to omit this info
* boolean $include_tags Send 'false' to omit this info
* string $date_archive_type Drive which date archive is linked to; can be: 'day', 'month', or 'year'
* @return string The generated markup
*/
function tag_post_meta( $args = array() )
{
// Merge default arguments and the arguments supplied by the caller.
$defaults = array(
'include_author' => true,
'include_categories' => true,
'include_comments' => true,
'include_date' => true,
'include_tags' => true,
'date_archive_type' => 'month'
);
$args = (object)wp_parse_args( $args, $defaults );
// Prepare an array of all the pieces that make up the post metadata.
$meta = array();
if ( $args->include_author ) $meta[] = tag_post_meta_author();
if ( $args->include_categories ) $meta[] = tag_post_meta_categories();
if ( $args->include_comments ) $meta[] = tag_post_meta_comments();
if ( $args->include_date ) $meta[] = tag_post_meta_date( array( 'archive_type' => $args->date_archive_type ) );
if ( $args->include_tags ) $meta[] = tag_post_meta_tags();
// If no metadata was added to the overall array, then get
// out now before return an empty element.
if ( empty( $meta ) ) return '';
// Glue the elements together into a single line - the array_filter
// call automatically removes empty elements from being included.
return
'
';
}
/**
* Provides a link and info about the author who wrote a post.
*
* @link http://themeshaper.com/2012/11/01/the-wordpress-theme-index-template/
* @param array $args Can be any of the following arguments:
* TBD
* @return string The desired text
*/
function tag_post_meta_author( $args = array() )
{
// Merge default arguments and the arguments supplied by the caller.
$defaults = array(
// TBD
);
$args = (object)wp_parse_args( $args, $defaults );
// Write up the date.
ob_start();
echo
''.
''.
''.
esc_html( get_the_author() ).
''.
'';
// Ask the client if they want to change this up a bit (or ignore it completely).
return apply_filters( 'filter_bpq_post_meta_author', ob_get_clean() );
}
/**
* Puts together a list of categories separated by commas.
*
* @param array $args Can be any of the following arguments:
* TBD
* @return string The desired text
*/
function tag_post_meta_categories( $args = array() )
{
// Merge default arguments and the arguments supplied by the caller.
$defaults = array(
// TBD
);
$args = (object)wp_parse_args( $args, $defaults );
/* translators: used between list items, there is a space after the comma */
ob_start();
$categories_list = get_the_category_list( __( ', ', 'bpq' ) );
if ( $categories_list )
{
echo
''.
''.
sprintf( __( '%1$s', 'bpq' ), $categories_list ).
'';
}
// Ask the client if they want to change this up a bit (or ignore it completely).
return apply_filters( 'filter_bpq_post_meta_categories', ob_get_clean() );
}
/**
* Provides a link to the comments while also informing how
* many there are on the post.
*
* @param array $args Can be any of the following arguments:
* TBD
* @return string The desired text
*/
function tag_post_meta_comments( $args = array() )
{
// Merge default arguments and the arguments supplied by the caller.
$defaults = array(
// TBD
);
$args = (object)wp_parse_args( $args, $defaults );
//DAN-HACK: Start
//
// The preview template in the Customizer should always show the comment
// link - this is a hack because other post meta pieces handle the
// preview template through filter hooks; unfortunately, there is no hook
// for this post meta comment information.
$comment_link = '';
if ( is_viewing_preview() ) $comment_link = ''.__( 'Comment', 'bpq' ).'';
//
//DAN-HACK: End
// Consider a comments link - both informs and links to a place for leaving comments.
elseif ( !post_password_required() && ( comments_open() || '0' != get_comments_number() ) )
{
ob_start();
comments_popup_link( __( 'Leave a comment', 'bpq' ), __( '1 Comment', 'bpq' ), __( '% Comments', 'bpq' ) );
$comment_link = ob_get_clean();
}
// Generate the markup.
ob_start();
if ( !empty( $comment_link ) )
{
echo ''.
''.
$comment_link.
'';
}
// Ask the client if they want to change this up a bit (or ignore it completely).
return apply_filters( 'filter_bpq_post_meta_comments', ob_get_clean() );
}
/**
* Provides a link and info about the date a post was posted.
*
* @link http://themeshaper.com/2012/11/01/the-wordpress-theme-index-template/
* @param array $args Can be any of the following arguments:
* string $archive_type Drive which archive is linked to; can be: 'day', 'month', or 'year'
* @return string The desired text
*/
function tag_post_meta_date( $args = array() )
{
// Merge default arguments and the arguments supplied by the caller.
$defaults = array(
'archive_type' => 'month'
);
$args = (object)wp_parse_args( $args, $defaults );
// The date link could potentially go to
// the daily, monthly, or yearly archives.
$link = get_permalink();
switch ( $args->archive_type )
{
case 'day': $link = get_day_link( get_post_time( 'Y' ), get_post_time( 'm' ), get_post_time( 'j' ) ); break;
case 'month': $link = get_month_link( get_post_time( 'Y' ), get_post_time( 'm' ) ); break;
case 'year': $link = get_year_link( get_post_time( 'Y' ) ); break;
}
// Write up the date.
ob_start();
echo
'';
// Ask the client if they want to change this up a bit (or ignore it completely).
return apply_filters( 'filter_bpq_post_meta_date', ob_get_clean() );
}
/**
* Provides a link for any logged-in users who are permitted to edit posts.
*
* @link http://codex.wordpress.org/Template_Tags/get_edit_post_link
* @param array $args Can be any of the following arguments:
* TBD
* @return string The desired text
*/
function tag_post_meta_edit( $args = array() )
{
// Merge default arguments and the arguments supplied by the caller.
$defaults = array(
// TBD
);
$args = (object)wp_parse_args( $args, $defaults );
// Write up the date.
ob_start();
echo
''.
''.
''.
__( 'Edit', 'bpq' ).
''.
'';
// Ask the client if they want to change this up a bit (or ignore it completely).
return apply_filters( 'filter_bpq_post_meta_edit', ob_get_clean() );
}
/**
* Puts together a list of tags separated by commas.
*
* @param array $args Can be any of the following arguments:
* TBD
* @return string The desired text
*/
function tag_post_meta_tags( $args = array() )
{
// Merge default arguments and the arguments supplied by the caller.
$defaults = array(
// TBD
);
$args = (object)wp_parse_args( $args, $defaults );
/* translators: used between list items, there is a space after the comma */
ob_start();
$tags_list = get_the_tag_list( '', __( ', ', 'bpq' ) );
if ( $tags_list )
{
echo
''.
''.
sprintf( __( '%1$s', 'bpq' ), $tags_list ).
'';
}
// Ask the client if they want to change this up a bit (or ignore it completely).
return apply_filters( 'filter_bpq_post_meta_tags', ob_get_clean() );
}
/**
* Provides an icon that goes with a post layout.
*
* @param array $args Can be any of the following arguments:
* string $icon If specified, will override the default icon; use full Font Awesome of Glyphicons markup
* @return string The desired text
*/
function tag_post_icon( $args = array() )
{
// Merge default arguments and the arguments supplied by the caller.
$defaults = array(
'icon' => ''
);
$args = (object)wp_parse_args( $args, $defaults );
// Write up the icon with font-awesome.
return
'
';
}
/**
* Provides a linked version of the post title.
*
* @param array $args Can be any of the following arguments:
* string $label An optional label to prepend to the front of the title
* @return string The desired text
*/
function tag_post_title( $args = array() )
{
// Merge default arguments and the arguments supplied by the caller.
$defaults = array(
'label' => '',
);
$args = (object)wp_parse_args( $args, $defaults );
// POPT: Display article title?
$opt_display_article_title = ( \ski\post::get_opt( 'bpq_popt_leader_display_article_title', null ) == 'on' );
if ( is_singular() && !$opt_display_article_title ) return '';
// If there is a label, generate the wrapper around it.
$label = apply_filters( 'filter_bpq_post_title_label', $args->label );
if ( !empty( $label ) )
{
$label =
''.
$label.
'';
}
// Write up the title using the various specialized WP functions.
ob_start();
echo
'
';
// Return the markup.
return ob_get_clean();
}
/**
* Provides a 'read more'-type link to the current post.
*
* @link http://codex.wordpress.org/Function_Reference/the_excerpt#Make_the_.22read_more.22_link_to_the_post
* @param array $args Can be any of the following arguments:
* TBD
* @return string The desired text
*/
function tag_read_more( $args = array() )
{
// Merge default arguments and the arguments supplied by the caller.
$defaults = array(
// TBD
);
$args = (object)wp_parse_args( $args, $defaults );
// OPTION: Read more text
$opt_text = get_theme_mod( 'bpq_opt_content_read_more_text', '' );
if ( empty( $opt_text ) ) $opt_text = __( 'read more', 'bpq' );
$opt_text = apply_filters( 'filter_bpq_read_more_text', $opt_text.' ' );
// Setup the classes that get attached to this 'read more' link.
$classes = array();
$classes[] = 'read-more';
$classes[] = 'ignore';
$classes = apply_filters( 'filter_bpq_read_more_classes', $classes );
// Write up the read more link - note that the 'excerpt_more'
// WP hook is being used for familiarity.
ob_start();
echo
''.
$opt_text.
'';
// Ask the client if they want to change this up a bit (or ignore it completely).
return apply_filters( 'filter_bpq_read_more', ob_get_clean() );
}
?>