', esc_url( get_bloginfo( 'pingback_url' ) ) );
}
}
add_action( 'wp_head', 'blogic_pingback_header' );
/**
* Get an array of post id and title.
*/
function blogic_get_post_choices() {
$choices = array( '' => esc_html__( '--Select--', 'blogic' ) );
$args = array( 'numberposts' => -1 );
$posts = get_posts( $args );
foreach ( $posts as $post ) {
$id = $post->ID;
$title = $post->post_title;
$choices[ $id ] = $title;
}
return $choices;
wp_reset_postdata();
}
/**
* Get all pages for customizer Page content type.
*/
function blogic_get_page_choices() {
$pages = get_pages();
$choices = array();
$choices[0] = esc_html__( '--Select--', 'blogic' );
foreach ( $pages as $page ) {
$choices[ $page->ID ] = $page->post_title;
}
return $choices;
}
/**
* Get an array of cat id and title.
*/
function blogic_get_post_cat_choices() {
$choices = array( '' => esc_html__( '--Select--', 'blogic' ) );
$cats = get_categories();
foreach ( $cats as $cat ) {
$id = $cat->term_id;
$title = $cat->name;
$choices[ $id ] = $title;
}
return $choices;
}
/**
* Checks to see if we're on the homepage or not.
*/
function blogic_is_frontpage() {
return ( is_front_page() && ! is_home() );
}
/**
* Checks to see if Static Front Page is set to "Your latest posts".
*/
function blogic_is_latest_posts() {
return ( is_front_page() && is_home() );
}
/**
* Checks to see if Static Front Page is set to "Posts page".
*/
function blogic_is_frontpage_blog() {
return ( is_home() && ! is_front_page() );
}
/**
* Shows a breadcrumb for all types of pages. This is a wrapper function for the Breadcrumb_Trail class,
* which should be used in theme templates.
*
* @since 1.0.0
* @access public
* @param array $args Arguments to pass to Breadcrumb_Trail.
* @return void
*/
function blogic_breadcrumb( $args = array() ) {
$breadcrumb = apply_filters( 'breadcrumb_trail_object', null, $args );
if ( ! is_object( $breadcrumb ) ) {
$breadcrumb = new Breadcrumb_Trail( $args );
}
return $breadcrumb->trail();
}
/**
* Add separator for breadcrumb trail.
*/
function blogic_breadcrumb_trail_print_styles() {
$breadcrumb_separator = get_theme_mod( 'blogic_breadcrumb_separator', '/' );
$style = '
.trail-items li:not(:last-child):after {
content: "' . $breadcrumb_separator . '";
}';
$style = apply_filters( 'blogic_breadcrumb_trail_inline_style', trim( str_replace( array( "\r", "\n", "\t", ' ' ), '', $style ) ) );
if ( $style ) {
echo "\n" . '' . "\n";
}
}
add_action( 'wp_head', 'blogic_breadcrumb_trail_print_styles' );
if ( ! function_exists( 'blogic_sidebar_layout' ) ) {
/**
* Get sidebar layout.
*/
function blogic_sidebar_layout() {
$sidebar_position = get_theme_mod( 'blogic_sidebar_position', 'right-sidebar' );
$sidebar_position_post = get_theme_mod( 'blogic_post_sidebar_position', 'right-sidebar' );
$sidebar_position_page = get_theme_mod( 'blogic_page_sidebar_position', 'right-sidebar' );
if ( is_single() ) {
$sidebar_position = $sidebar_position_post;
} elseif ( is_page() ) {
$sidebar_position = $sidebar_position_page;
}
return $sidebar_position;
}
}
if ( ! function_exists( 'blogic_is_sidebar_enabled' ) ) {
/**
* Check if sidebar is enabled.
*/
function blogic_is_sidebar_enabled() {
$sidebar_position = get_theme_mod( 'blogic_sidebar_position', 'right-sidebar' );
$sidebar_position_post = get_theme_mod( 'blogic_post_sidebar_position', 'right-sidebar' );
$sidebar_position_page = get_theme_mod( 'blogic_page_sidebar_position', 'right-sidebar' );
$sidebar_enabled = true;
if ( is_home() || is_archive() || is_search() ) {
if ( 'no-sidebar' === $sidebar_position ) {
$sidebar_enabled = false;
}
} elseif ( is_single() ) {
if ( 'no-sidebar' === $sidebar_position || 'no-sidebar' === $sidebar_position_post ) {
$sidebar_enabled = false;
}
} elseif ( is_page() ) {
if ( 'no-sidebar' === $sidebar_position || 'no-sidebar' === $sidebar_position_page ) {
$sidebar_enabled = false;
}
}
return $sidebar_enabled;
}
}
/**
* Pagination for archive.
*/
function blogic_render_posts_pagination() {
$is_pagination_enabled = get_theme_mod( 'blogic_pagination_enable', true );
if ( $is_pagination_enabled ) {
$pagination_type = get_theme_mod( 'blogic_pagination_type', 'default' );
if ( 'default' === $pagination_type ) :
the_posts_navigation();
else :
the_posts_pagination();
endif;
}
}
add_action( 'blogic_posts_pagination', 'blogic_render_posts_pagination', 10 );
/**
* Pagination for single post.
*/
function blogic_render_post_navigation() {
the_post_navigation(
array(
'prev_text' => '⟵ %title',
'next_text' => '%title ⟶',
)
);
}
add_action( 'blogic_post_navigation', 'blogic_render_post_navigation' );
if ( ! function_exists( 'blogic_excerpt_length' ) ) :
/**
* Excerpt length.
*/
function blogic_excerpt_length( $length ) {
if ( is_admin() ) {
return $length;
}
$length = get_theme_mod( 'blogic_excerpt_length', 15 );
return $length;
}
endif;
add_filter( 'excerpt_length', 'blogic_excerpt_length', 999 );
if ( ! function_exists( 'blogic_the_excerpt' ) ) :
/**
* Generate excerpt.
* @since 1.0.0
* @param int $length Excerpt length in words.
* @param WP_Post $post_obj WP_Post instance (Optional).
* @return string Excerpt.
*/
function blogic_the_excerpt( $length = 0, $post_obj = null ) {
global $post;
if ( is_null( $post_obj ) ) {
$post_obj = $post;
}
$length = absint( $length );
if ( 0 === $length ) {
return;
}
$source_content = $post_obj->post_content;
if ( ! empty( $post_obj->post_excerpt ) ) {
$source_content = $post_obj->post_excerpt;
}
$source_content = preg_replace( '`\[[^\]]*\]`', '', $source_content );
$trimmed_content = wp_trim_words( $source_content, $length, '…' );
return $trimmed_content;
}
endif;
// Add auto p to the palces where get_the_excerpt is being called.
add_filter( 'get_the_excerpt', 'wpautop' );