| Current Path : /home/x/b/o/xbodynamge/namtation/wp-content/ |
| Current File : /home/x/b/o/xbodynamge/namtation/wp-content/blog.tar |
class-hestia-header-layout-manager.php 0000666 00000030736 15113170145 0014021 0 ustar 00 <?php
/**
* Hestia Header Layout Manager.
*
* @package Hestia
*/
/**
* Class Hestia_Header_Layout_Manager
*/
class Hestia_Header_Layout_Manager extends Hestia_Abstract_Main {
/**
* Init layout manager.
*/
public function init() {
add_filter( 'get_the_archive_title', array( $this, 'filter_archive_title' ) );
// Single Post
add_action( 'hestia_before_single_post_wrapper', array( $this, 'post_header' ) );
add_action( 'hestia_before_single_post_content', array( $this, 'post_before_content' ) );
// Page
add_action( 'hestia_before_single_page_wrapper', array( $this, 'page_header' ) );
add_action( 'hestia_before_page_content', array( $this, 'page_before_content' ) );
// Index
add_action( 'hestia_before_index_wrapper', array( $this, 'generic_header' ) );
// Search
add_action( 'hestia_before_search_wrapper', array( $this, 'generic_header' ) );
// Attachment
add_action( 'hestia_before_attachment_wrapper', array( $this, 'generic_header' ) );
// Archive
add_action( 'hestia_before_archive_content', array( $this, 'generic_header' ) );
add_action( 'hestia_before_woocommerce_wrapper', array( $this, 'generic_header' ) );
}
/**
* Remove "Category:", "Tag:", "Author:" from the archive title.
*
* @param string $title Archive title.
*/
public function filter_archive_title( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = '<span class="vcard">' . get_the_author() . '</span>';
} elseif ( is_year() ) {
$title = get_the_date( 'Y' );
} elseif ( is_month() ) {
$title = get_the_date( 'F Y' );
} elseif ( is_day() ) {
$title = get_the_date( 'F j, Y' );
} elseif ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
} elseif ( is_tax() ) {
$title = single_term_title( '', false );
}
return $title;
}
/**
* The single post header.
*/
public function post_header() {
$layout = get_theme_mod( 'hestia_header_layout', 'default' );
if ( $layout === 'classic-blog' ) {
return;
}
$this->display_header( $layout, 'post' );
}
/**
* The single page header.
*/
public function page_header() {
$layout = get_theme_mod( 'hestia_header_layout', 'default' );
if ( class_exists( 'WooCommerce' ) && ( is_cart() || is_checkout() || is_shop() ) ) {
$layout = 'default';
}
if ( $layout === 'classic-blog' ) {
return;
}
$this->display_header( $layout, 'page' );
}
/**
* Display page header on single page and on full width page template.
*
* @param string $layout header layout.
* @param string $type post / page / other.
*/
private function display_header( $layout, $type ) {
echo '<div id="primary" class="' . esc_attr( $this->boxed_page_layout_class() ) . ' page-header header-small"
' . $this->parallax_attribute() . '>';
if ( $type === 'post' && $layout !== 'no-content' ) {
$this->render_header();
}
if ( $type === 'page' && $layout === 'default' ) {
$this->render_header();
}
if ( $type === 'generic' ) {
$this->render_header();
}
$this->render_header_background();
echo '</div>';
}
/**
* Determine whether or not to add parallax attribute on header.
*/
private function parallax_attribute() {
if ( class_exists( 'WooCommerce' ) && is_product() ) {
return '';
}
return 'data-parallax="active"';
}
/**
* Display header content based on layout.
*/
private function render_header() {
$layout = get_theme_mod( 'hestia_header_layout', 'default' );
if ( ! is_single() && ! is_page() ) {
$layout = 'default';
}
if ( is_attachment() ) {
$layout = 'default';
}
if ( $this->is_shop_without_header_content() ) {
$layout = 'default';
}
if ( $layout === 'default' && ! $this->is_shop_without_header_content() ) {
?>
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1 text-center">
<?php
}
$this->header_content( $layout );
$this->maybe_render_post_meta( $layout );
if ( $layout === 'classic-blog' ) {
the_post_thumbnail();
}
if ( $layout === 'default' && ! $this->is_shop_without_header_content() ) {
?>
</div>
</div>
</div>
<?php
}
}
/**
* Header content display.
*
* @param string $header_layout the header layout.
*/
private function header_content( $header_layout ) {
$title_class = 'hestia-title';
if ( $header_layout !== 'default' ) {
$title_class .= ' title-in-content';
}
if ( class_exists( 'WooCommerce' ) ) {
if ( is_shop() ) {
echo '<h1 class="' . esc_attr( $title_class ) . '">';
woocommerce_page_title();
echo '</h1>';
return;
}
if ( is_product() || is_cart() || is_checkout() ) {
return;
}
}
if ( is_archive() ) {
the_archive_title( '<h1 class="hestia-title">', '</h1>' );
the_archive_description( '<h5 class="description">', '</h5>' );
return;
}
if ( is_search() ) {
echo '<h1 class="' . esc_attr( $title_class ) . '">';
/* translators: search result */
printf( esc_html__( 'Search Results for: %s', 'hestia' ), get_search_query() );
echo '</h1>';
return;
}
if ( is_front_page() && ( get_option( 'show_on_front' ) === 'posts' ) ) {
echo '<h1 class="' . esc_attr( $title_class ) . '">';
echo get_bloginfo( 'description' );
echo '</h1>';
return;
}
if ( is_page() ) {
echo '<h1 class="' . esc_attr( $title_class ) . '">';
single_post_title();
echo '</h1>';
return;
}
echo '<h1 class="' . esc_attr( $title_class ) . ' entry-title">';
single_post_title();
echo '</h1>';
return;
}
/**
* Check if post meta should be displayed.
*
* @param string $header_layout the header layout.
*/
private function maybe_render_post_meta( $header_layout ) {
if ( ! is_single() ) {
return;
}
if ( class_exists( 'WooCommerce' ) ) {
if ( is_product() ) {
return;
}
}
global $post;
$author_id = $post->post_author;
$author_name = get_the_author_meta( 'display_name', $author_id );
$author_posts_url = get_author_posts_url( get_the_author_meta( 'ID', $author_id ) );
if ( $header_layout === 'default' ) {
echo '<h4 class="author">';
} else {
echo '<p class="author meta-in-content">';
}
echo apply_filters(
'hestia_single_post_meta', sprintf(
/* translators: %1$s is Author name wrapped, %2$s is Date*/
esc_html__( 'Published by %1$s on %2$s', 'hestia' ),
/* translators: %1$s is Author name, %2$s is Author link*/
sprintf(
'<a href="%2$s" class="vcard author"><strong class="fn">%1$s</strong></a>',
esc_html( $author_name ),
esc_url( $author_posts_url )
),
/* translators: %s is Date */
sprintf(
'<time class="date updated published" datetime="%2$s">%1$s</time>',
esc_html( get_the_time( get_option( 'date_format' ) ) ), esc_html( get_the_date( DATE_W3C ) )
)
)
);
if ( $header_layout === 'default' ) {
echo '</h4>';
} else {
echo '</p>';
}
}
/**
* Get the sidebar layout.
*
* @return mixed|string
*/
public function get_page_sidebar_layout() {
$sidebar_layout = get_theme_mod( 'hestia_blog_sidebar_layout', 'sidebar-right' );
$individual_layout = get_post_meta( get_the_ID(), 'hestia_layout_select', true );
if ( ! empty( $individual_layout ) && $individual_layout !== 'default' ) {
$sidebar_layout = $individual_layout;
}
return $sidebar_layout;
}
/**
* Get the sidebar layout.
*
* @return mixed|string
*/
public function get_blog_sidebar_layout() {
$sidebar_layout = get_theme_mod( 'hestia_page_sidebar_layout', 'full-width' );
$individual_layout = get_post_meta( get_the_ID(), 'hestia_layout_select', true );
if ( ! empty( $individual_layout ) && $individual_layout !== 'default' ) {
$sidebar_layout = $individual_layout;
}
return $sidebar_layout;
}
/**
* Add the class to account for boxed page layout.
*
* @return string
*/
private function boxed_page_layout_class() {
$layout = get_theme_mod( 'hestia_general_layout', 1 );
if ( isset( $layout ) && $layout == 1 ) {
return 'boxed-layout-header';
}
return '';
}
/**
* Render the header background div.
*/
private function render_header_background() {
$background_image = $this->get_page_background();
$customizer_background_image = get_background_image();
$header_filter_div = '<div class="header-filter';
/* Header Image */
if ( ! empty( $background_image ) ) {
$header_filter_div .= '" style="background-image: url(' . esc_url( $background_image ) . ');"';
/* Gradient Color */
} elseif ( empty( $customizer_background_image ) ) {
$header_filter_div .= ' header-filter-gradient"';
/* Background Image */
} else {
$header_filter_div .= '"';
}
$header_filter_div .= '></div>';
echo apply_filters( 'hestia_header_wrapper_background_filter', $header_filter_div );
}
/**
* Handle Pages and Posts Header image.
* Single Product: Product Category Image > Header Image > Gradient
* Product Category: Product Category Image > Header Image > Gradient
* Shop Page: Shop Page Featured Image > Header Image > Gradient
* Blog Page: Page Featured Image > Header Image > Gradient
* Single Post: Featured Image > Gradient
*/
private function get_page_background() {
// Default header image
$thumbnail = get_header_image();
$use_header_image_sitewide = get_theme_mod( 'hestia_header_image_sitewide', false );
// If the option to use Header Image Sitewide is enabled, return header image and exit function.
if ( (bool) $use_header_image_sitewide === true ) {
return esc_url( apply_filters( 'hestia_header_image_filter', $thumbnail ) );
}
$shop_id = get_option( 'woocommerce_shop_page_id' );
if ( class_exists( 'WooCommerce' ) && is_woocommerce() ) {
// Single product page
if ( is_product() ) {
$terms = get_the_terms( get_queried_object_id(), 'product_cat' );
// If product has categories
if ( ! empty( $terms ) ) {
foreach ( $terms as $term ) {
if ( ! empty( $term->term_id ) ) {
$category_thumbnail = get_woocommerce_term_meta( $term->term_id, 'thumbnail_id', true );
}
// Get product category's image
if ( ! empty( $category_thumbnail ) ) {
$thumb_tmp = wp_get_attachment_url( $category_thumbnail );
} // End if().
}
}
} elseif ( is_product_category() ) {
global $wp_query;
$category = $wp_query->get_queried_object();
if ( ! empty( $category->term_id ) ) {
$thumbnail_id = get_woocommerce_term_meta( $category->term_id, 'thumbnail_id', true );
}
if ( ! empty( $thumbnail_id ) ) {
// Get category featured image
$thumb_tmp = wp_get_attachment_url( $thumbnail_id );
} else {
if ( ! empty( $shop_id ) ) {
// Get shop page featured image
$thumb_tmp = get_the_post_thumbnail_url( $shop_id );
if ( ! empty( $thumb_tmp ) ) {
$thumbnail = $thumb_tmp;
}
}
}
} else {
// Shop page
if ( ! empty( $shop_id ) ) {
// Get shop page featured image
$thumb_tmp = get_the_post_thumbnail_url( $shop_id );
}
}// End if().
} else {
// Get featured image
if ( is_home() ) {
$page_for_posts_id = get_option( 'page_for_posts' );
if ( ! empty( $page_for_posts_id ) ) {
$thumb_tmp = get_the_post_thumbnail_url( $page_for_posts_id );
}
} else {
$thumb_tmp = get_the_post_thumbnail_url();
}
}// End if().
if ( ! empty( $thumb_tmp ) ) {
$thumbnail = $thumb_tmp;
}
return esc_url( apply_filters( 'hestia_header_image_filter', $thumbnail ) );
}
/**
* Single page before content.
*/
public function page_before_content() {
$layout = get_theme_mod( 'hestia_header_layout', 'default' );
if ( $layout === 'default' ) {
return;
}
if ( class_exists( 'WooCommerce' ) && ( is_product() || is_cart() || is_checkout() ) ) {
return;
}
$this->render_header();
}
/**
* Single post before content.
*/
public function post_before_content() {
$layout = get_theme_mod( 'hestia_header_layout', 'default' );
if ( $layout === 'default' ) {
return;
}
$this->render_header();
}
/**
* Generic header used for index | search | attachment | WooCommerce.
*/
public function generic_header() {
$this->display_header( 'default', 'generic' );
}
/**
* Check if page is WooCommerce without header content [cart/checkout/shop]
*
* @return bool
*/
private function is_shop_without_header_content() {
if ( ! class_exists( 'WooCommerce' ) ) {
return false;
}
if ( is_cart() || is_checkout() ) {
return true;
}
return false;
}
}
class-hestia-additional-views.php 0000666 00000016022 15113170145 0013101 0 ustar 00 <?php
/**
* Hestia Header Layout Manager.
*
* @package Hestia
*/
/**
* Class Hestia_Header_Layout_Manager
*/
class Hestia_Additional_Views extends Hestia_Abstract_Main {
/**
* Init layout manager.
*/
public function init() {
add_action( 'hestia_after_single_post_article', array( $this, 'post_after_article' ) );
add_action( 'hestia_blog_social_icons', array( $this, 'social_icons' ) );
add_action( 'wp_footer', array( $this, 'scroll_to_top' ) );
add_action( 'hestia_blog_related_posts', array( $this, 'related_posts' ) );
}
/**
* Social sharing icons for single view.
*
* @since Hestia 1.0
*/
public function social_icons() {
$enabled_socials = get_theme_mod( 'hestia_enable_sharing_icons', true );
if ( (bool) $enabled_socials !== true ) {
return;
}
$post_link = get_the_permalink();
$post_title = get_the_title();
$allowed_tags = array(
'div' => array(
'class' => array(),
),
'a' => array(
'href' => array(),
'target' => array(),
'title' => array(),
'rel' => array(),
'class' => array(),
'data-original-title' => array(),
),
'i' => array(
'class' => array(),
),
);
$facebook_url =
esc_url(
add_query_arg(
array( 'u' => $post_link ),
'https://www.facebook.com/sharer/sharer.php'
)
);
$twitter_url =
esc_url(
add_query_arg(
array( 'status' => wp_strip_all_tags( $post_title ) . ' - ' . esc_url( $post_link ) ),
'https://twitter.com/home'
)
);
$google_url =
esc_url(
add_query_arg(
array( 'url' => $post_link ),
'https://plus.google.com/share'
)
);
$social_links = '
<div class="col-md-6">
<div class="entry-social">
<a target="_blank" rel="tooltip"
data-original-title="' . esc_attr__( 'Share on Facebook', 'hestia' ) . '"
class="btn btn-just-icon btn-round btn-facebook"
href="' . $facebook_url . '">
<i class="fa fa-facebook"></i>
</a>
<a target="_blank" rel="tooltip"
data-original-title="' . esc_attr__( 'Share on Twitter', 'hestia' ) . '"
class="btn btn-just-icon btn-round btn-twitter"
href="' . $twitter_url . '">
<i class="fa fa-twitter"></i>
</a>
<a target="_blank" rel="tooltip"
data-original-title=" ' . esc_attr__( 'Share on Google+', 'hestia' ) . '"
class="btn btn-just-icon btn-round btn-google"
href="' . $google_url . '">
<i class="fa fa-google"></i>
</a>
</div>
</div>';
echo apply_filters( 'hestia_filter_blog_social_icons', $social_links );
}
/**
* Single post after article.
*/
public function post_after_article() {
global $post;
$categories = get_the_category( $post->ID );
?>
<div class="section section-blog-info">
<div class="row">
<div class="col-md-6">
<div class="entry-categories"><?php esc_html_e( 'Categories:', 'hestia' ); ?>
<?php
foreach ( $categories as $category ) {
echo '<span class="label label-primary"><a href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . esc_html( $category->name ) . '</a></span>';
}
?>
</div>
<?php the_tags( '<div class="entry-tags">' . esc_html__( 'Tags: ', 'hestia' ) . '<span class="entry-tag">', '</span><span class="entry-tag">', '</span></div>' ); ?>
</div>
<?php do_action( 'hestia_blog_social_icons' ); ?>
</div>
<hr>
<?php
$this->maybe_render_author_box();
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
?>
</div>
<?php
}
/**
* Render the author box.
*/
private function maybe_render_author_box() {
$author_description = get_the_author_meta( 'description' );
if ( empty( $author_description ) ) {
return;
}
?>
<div class="card card-profile card-plain">
<div class="row">
<div class="col-md-2">
<div class="card-avatar">
<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"
title="<?php echo esc_attr( get_the_author() ); ?>"><?php echo get_avatar( get_the_author_meta( 'ID' ), 100 ); ?></a>
</div>
</div>
<div class="col-md-10">
<h4 class="card-title"><?php the_author(); ?></h4>
<p class="description"><?php the_author_meta( 'description' ); ?></p>
</div>
</div>
</div>
<?php
}
/**
* Display scroll to top button.
*
* @since 1.1.54
*/
public function scroll_to_top() {
$hestia_enable_scroll_to_top = get_theme_mod( 'hestia_enable_scroll_to_top' );
if ( (bool) $hestia_enable_scroll_to_top === false ) {
return;
}
?>
<button class="hestia-scroll-to-top">
<i class="fa fa-angle-double-up" aria-hidden="true"></i>
</button>
<?php
}
/**
* Related posts for single view.
*
* @since Hestia 1.0
*/
public function related_posts() {
global $post;
$cats = wp_get_object_terms(
$post->ID, 'category', array(
'fields' => 'ids',
)
);
$args = array(
'posts_per_page' => 3,
'cat' => $cats,
'orderby' => 'date',
'ignore_sticky_posts' => true,
'post__not_in' => array( $post->ID ),
);
$allowed_html = array(
'br' => array(),
'em' => array(),
'strong' => array(),
'i' => array(
'class' => array(),
),
'span' => array(),
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) :
?>
<div class="section related-posts">
<div class="container">
<div class="row">
<div class="col-md-12">
<h2 class="hestia-title text-center"><?php esc_html_e( 'Related Posts', 'hestia' ); ?></h2>
<div class="row">
<?php
while ( $loop->have_posts() ) :
$loop->the_post();
?>
<div class="col-md-4">
<div class="card card-blog">
<?php if ( has_post_thumbnail() ) : ?>
<div class="card-image">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail( 'hestia-blog' ); ?>
</a>
</div>
<?php endif; ?>
<div class="content">
<h6 class="category text-info"><?php hestia_category(); ?></h6>
<h4 class="card-title">
<a class="blog-item-title-link" href="<?php echo esc_url( get_permalink() ); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark">
<?php echo wp_kses( force_balance_tags( get_the_title() ), $allowed_html ); ?>
</a>
</h4>
<p class="card-description"><?php echo wp_kses_post( get_the_excerpt() ); ?></p>
</div>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
</div>
</div>
</div>
</div>
</div>
<?php
endif;
}
}
class-hestia-individual-single-layout.php 0000666 00000007436 15113170145 0014571 0 ustar 00 <?php
/**
* Feature to control layout on individual posts and pages.
*
* @package hestia
* @since 1.1.58
*/
/**
* Class Hestia_Individual_Single_Layout
*/
class Hestia_Individual_Single_Layout extends Hestia_Abstract_Main {
/**
* Hestia_Single_Layout constructor.
*/
public function init() {
add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
add_action( 'save_post', array( $this, 'save_meta_box' ) );
add_filter( 'theme_mod_hestia_page_sidebar_layout', array( $this, 'get_individual_layout' ) );
add_filter( 'theme_mod_hestia_blog_sidebar_layout', array( $this, 'get_individual_layout' ) );
}
/**
* Register meta box to control layout on pages and posts.
*
* @since 1.1.58
*/
public function add_meta_box() {
global $post;
if ( empty( $post ) ) {
return;
}
$page_template = get_post_meta( $post->ID, '_wp_page_template', true );
// Register the metabox only for the default and page with sidebar templates.
$allowed_templates = array(
'default',
'page-templates/template-page-sidebar.php',
);
if ( ! in_array( $page_template, $allowed_templates ) && ! empty( $page_template ) ) {
return;
}
add_meta_box(
'hestia-individual-layout', esc_html__( 'Layout', 'hestia' ), array(
$this,
'meta_box_content',
), array(
'post',
'page',
), 'side', 'low'
);
}
/**
* The metabox content.
*
* @since 1.1.58
*/
public function meta_box_content() {
// $post is already set, and contains an object: the WordPress post
global $post;
$values = get_post_custom( $post->ID );
$selected = isset( $values['hestia_layout_select'] ) ? esc_attr( $values['hestia_layout_select'][0] ) : '';
// We'll use this nonce field later on when saving.
wp_nonce_field( 'hestia_individual_layout_nonce', 'individual_layout_nonce' );
?>
<p>
<select name="hestia_layout_select" id="hestia_layout_select">
<option value="default" <?php selected( $selected, 'default' ); ?>><?php echo esc_html__( 'Default', 'hestia' ); ?></option>
<option value="full-width" <?php selected( $selected, 'full-width' ); ?>><?php echo esc_html__( 'Full Width', 'hestia' ); ?></option>
<option value="sidebar-left" <?php selected( $selected, 'sidebar-left' ); ?>><?php echo esc_html__( 'Left Sidebar', 'hestia' ); ?></option>
<option value="sidebar-right" <?php selected( $selected, 'sidebar-right' ); ?>><?php echo esc_html__( 'Right Sidebar', 'hestia' ); ?></option>
</select>
</p>
<?php
}
/**
* Save metabox data.
*
* @param string $post_id Post id.
*
* @since 1.1.58
*/
public function save_meta_box( $post_id ) {
// Bail if we're doing an auto save
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
// if our nonce isn't there, or we can't verify it, bail
if ( ! isset( $_POST['individual_layout_nonce'] ) || ! wp_verify_nonce( $_POST['individual_layout_nonce'], 'hestia_individual_layout_nonce' ) ) {
return;
}
// if our current user can't edit this post, bail
if ( ! current_user_can( 'edit_post' ) ) {
return;
}
if ( isset( $_POST['hestia_layout_select'] ) ) {
$valid = array(
'default',
'full-width',
'sidebar-left',
'sidebar-right',
);
$value = wp_unslash( $_POST['hestia_layout_select'] );
update_post_meta( $post_id, 'hestia_layout_select', in_array( $value, $valid ) ? $value : 'default' );
}
}
/**
* Hook into the theme mod to change it as we see fit.
*
* @param string $layout the single post / page layout.
*
* @return string $layout
*/
public function get_individual_layout( $layout ) {
$individual_layout = get_post_meta( get_the_ID(), 'hestia_layout_select', true );
if ( empty( $individual_layout ) ) {
return $layout;
}
if ( $individual_layout === 'default' ) {
return $layout;
}
return $individual_layout;
}
}
class-hestia-featured-posts.php 0000666 00000012336 15113170145 0012607 0 ustar 00 <?php
/**
* Featured posts on blog index.
*
* @package Hestia
*/
/**
* Class Hestia_Featured_Posts
*/
class Hestia_Featured_Posts extends Hestia_Abstract_Main {
/**
* Posts that will be skipped.
*
* @var array
*/
private $posts_to_skip = array();
/**
* Initialize Featured Posts
*/
public function init() {
add_action( 'hestia_before_index_posts_loop', array( $this, 'render_featured_posts' ) );
add_filter( 'hestia_filter_skipped_posts_in_main_loop', array( $this, 'remove_featured_posts_in_main_loop' ), 0 );
}
/**
* Display the latest 3 posts on top of the blog page.
*
* @return array|void
*/
public function render_featured_posts() {
if ( is_404() ) {
return;
}
/**
* Check if section is enabled. If it isn't, exit.
*/
$featured_posts_category = get_theme_mod( 'hestia_featured_posts_category', apply_filters( 'hestia_featured_posts_category_default', 0 ) );
if ( empty( $featured_posts_category ) ) {
return;
}
if ( count( $featured_posts_category ) === 1 && empty( $featured_posts_category[0] ) ) {
return;
}
/**
* By default, we will show only the last 3 posts but the number of posts can be changed in a child theme.
*/
$number_of_posts = apply_filters( 'hestia_blog_featured_posts_number', 3 );
$post = new WP_Query(
array(
'post_type' => 'post',
'posts_per_page' => ! empty( $number_of_posts ) ? absint( $number_of_posts ) : 3,
'order' => 'DESC',
'ignore_sticky_posts' => true,
'category__in' => $featured_posts_category,
)
);
if ( ! $post->have_posts() ) {
return;
}
/**
* Index of the current post that is showed in loop.
*/
$item_index = 0;
/**
* The total number of posts.
*/
$category = get_category( $featured_posts_category[0] );
$total_posts = $category->category_count;
echo '<div class="hestia-blog-featured-posts ' . esc_attr( $this->wrapper_class() ) . '"><div class="row">';
while ( $post->have_posts() ) {
$post->the_post();
$item_index ++;
/**
* Based on the post index, decide if the post should display full width or just 50% of the page. If it's
* the only post, display it as full width.
*/
$card_class = $this->get_card_class( $item_index, $total_posts );
$card_inner_class = 'card card-raised';
/**
* If the post has a thumbnail, we add the class card-background which adds overlay on the image, center
* the content and change the color of the text.
*/
$thumb_style = '';
if ( has_post_thumbnail() ) {
$card_inner_class .= ' card-background';
$thumb_url = get_the_post_thumbnail_url();
$thumb_style = 'style="background-image:url(' . esc_url( $thumb_url ) . ')"';
}
// Get the data (title, category, content) and display the post.
$pid = get_the_ID();
array_push( $this->posts_to_skip, $pid );
$categories = get_the_category( $pid );
$cat_name = $categories[0]->name;
$cat_id = $categories[0]->term_id;
$cat_link = get_category_link( $cat_id );
$post_url = get_permalink();
$title = get_the_title();
$content = get_the_excerpt();
$content = preg_replace( '/<a class="moretag" (.*?)>(.*?)<\/a>/i', '...', $content );
echo '<article class="hestia-blog-featured-card ' . esc_attr( $card_class ) . '">';
echo '<div class="' . esc_attr( $card_inner_class ) . '" ' . $thumb_style . '>';
echo '<div class="card-body">';
echo '<h6 class="category text-info"><a href="' . esc_url( $cat_link ) . '">' . wp_kses_post( $cat_name ) . '</a></h6>';
if ( ! empty( $title ) ) {
echo '<a href="' . esc_url( $post_url ) . '">';
echo '<h2 class="card-title">' . wp_kses_post( $title ) . '</h2>';
echo '</a>';
}
if ( ! empty( $content ) ) {
echo '<p class="card-description">';
echo wp_kses_post( $content );
echo '</p>';
}
echo '<a href="' . esc_url( $post_url ) . '" class="btn btn-round">';
echo apply_filters( 'hestia_features_blog_posts_button_text', esc_html__( 'Read more', 'hestia' ) );
echo '</a>';
echo '</div>';
echo '</div>';
echo '</article>';
}
wp_reset_postdata();
echo '</div></div>';
}
/**
* Filter main loop posts for featured area exclusion.
*
* @param array $posts the posts array.
*
* @return array
*/
public function remove_featured_posts_in_main_loop( $posts ) {
return array_merge( $posts, $this->posts_to_skip );
}
/**
* Based on the post index, decide if the post should display full width or just 50% of the page.
*
* @param int $index Post index.
* @param int $total_posts Number of posts in category.
*
* @return string
*/
private function get_card_class( $index, $total_posts ) {
if ( $total_posts > 1 ) {
if ( $index % 3 === 1 ) {
return 'col-md-6';
}
if ( $index % 3 === 2 ) {
return 'col-md-6';
}
return 'col-md-12';
}
}
/**
* Featured posts wrapper class.
*
* @return string
*/
private function wrapper_class() {
$blog_sidebar_layout = get_theme_mod( 'hestia_blog_sidebar_layout', 'sidebar-right' );
if ( $blog_sidebar_layout === 'full-width' || ( ! is_active_sidebar( 'sidebar-1' ) && ! is_customize_preview() ) ) {
return ' col-md-10 col-md-offset-1 ';
} else {
return ' col-md-12 ';
}
}
}
class-hestia-sidebar-layout-manager.php 0000666 00000013770 15113170145 0014201 0 ustar 00 <?php
/**
* Hestia Sidebar Layout Manager.
*
* @package Hestia
*/
/**
* Class Hestia_Sidebar_Layout_Manager
*/
class Hestia_Sidebar_Layout_Manager extends Hestia_Abstract_Main {
/**
* Init layout manager.
*/
public function init() {
// Single Post
add_filter( 'hestia_filter_single_post_content_classes', array( $this, 'post_content_classes' ) );
// Page
add_filter( 'hestia_filter_page_content_classes', array( $this, 'page_content_classes' ) );
add_action( 'hestia_page_sidebar', array( $this, 'render_page_sidebar' ) );
// Index and search
add_filter( 'hestia_filter_index_search_content_classes', array( $this, 'index_search_content_classes' ) );
// Archive
add_filter( 'hestia_filter_archive_content_classes', array( $this, 'archive_content_classes' ) );
// Blog Sidebar
add_filter( 'hestia_filter_blog_sidebar_classes', array( $this, 'blog_sidebar_classes' ) );
// Shop Sidebar.
add_filter( 'hestia_filter_woocommerce_content_classes', array( $this, 'content_classes' ) );
}
/**
* Page content classes.
*
* @param string $classes page content classes.
*
* @return string
*/
public function page_content_classes( $classes ) {
$sidebar_layout = get_theme_mod( 'hestia_page_sidebar_layout', 'full-width' );
if ( class_exists( 'WooCommerce' ) ) {
if ( is_cart() || is_checkout() ) {
return 'col-md-12';
}
}
if ( $sidebar_layout === 'full-width' ) {
return $classes . ' col-md-offset-2';
}
if ( $sidebar_layout === 'sidebar-left' ) {
return is_customize_preview() ?
$classes . 'col-md-offset-1' :
is_active_sidebar( 'sidebar-1' ) ?
$classes . 'col-md-offset-1' :
$classes . ' col-md-offset-2';
}
if ( $sidebar_layout === 'sidebar-right' ) {
return is_customize_preview() ?
$classes :
is_active_sidebar( 'sidebar-1' ) ?
$classes :
$classes . ' col-md-offset-2';
}
return $classes;
}
/**
* Post content classes.
*
* @param string $classes post content classes.
*
* @return string
*/
public function post_content_classes( $classes ) {
$sidebar_layout = get_theme_mod( 'hestia_blog_sidebar_layout', 'full-width' );
if ( $sidebar_layout === 'full-width' ) {
return $classes . ' col-md-offset-2';
}
if ( $sidebar_layout === 'sidebar-left' ) {
return is_customize_preview() ?
$classes . ' col-md-offset-1' :
is_active_sidebar( 'sidebar-1' ) ?
$classes . ' col-md-offset-1' :
$classes . ' col-md-offset-2';
}
if ( $sidebar_layout === 'sidebar-right' ) {
return is_customize_preview() ?
$classes :
is_active_sidebar( 'sidebar-1' ) ?
$classes :
$classes . ' col-md-offset-2';
}
return $classes;
}
/**
* Index content classes.
*
* @param string $classes index classes.
*
* @return string
*/
public function index_search_content_classes( $classes ) {
$sidebar_layout = get_theme_mod( 'hestia_blog_sidebar_layout', 'sidebar-right' );
if ( $sidebar_layout === 'full-width' ) {
return 'col-md-10 col-md-offset-1 blog-posts-wrap';
}
if ( $sidebar_layout === 'sidebar-left' ) {
return is_customize_preview() ?
$classes . ' col-md-offset-1' :
is_active_sidebar( 'sidebar-1' ) ?
$classes . ' col-md-offset-1' :
'col-md-10 col-md-offset-1 blog-posts-wrap';
}
if ( $sidebar_layout === 'sidebar-right' ) {
return is_customize_preview() ?
$classes :
is_active_sidebar( 'sidebar-1' ) ?
$classes :
'col-md-10 col-md-offset-1 blog-posts-wrap';
}
return $classes;
}
/**
* Archive content classes.
*
* @param string $classes archive content classes.
*
* @return string
*/
public function archive_content_classes( $classes ) {
$sidebar_layout = get_theme_mod( 'hestia_blog_sidebar_layout', 'sidebar-right' );
if ( $sidebar_layout === 'full-width' ) {
return 'col-md-10 col-md-offset-1 archive-post-wrap';
}
if ( $sidebar_layout === 'sidebar-left' ) {
$classes .= 'col-md-offset-1';
}
return $classes;
}
/**
* Adjust blog sidebar classes.
*
* @param string $classes the classes for blog sidebar.
*
* @return string
*/
public function blog_sidebar_classes( $classes ) {
if ( is_page() ) {
return $classes;
}
$sidebar_layout = get_theme_mod( 'hestia_blog_sidebar_layout', 'sidebar-right' );
if ( $sidebar_layout === 'sidebar-left' ) {
return $classes;
}
if ( function_exists( 'is_bbpress' ) && is_bbpress() ) {
return $classes;
}
if ( function_exists( 'is_buddypress' ) && is_buddypress() ) {
return $classes;
}
$classes .= ' col-md-offset-1';
return $classes;
}
/**
* Render the page sidebar.
*/
public function render_page_sidebar() {
if ( class_exists( 'WooCommerce' ) ) {
if ( is_cart() || is_checkout() || is_account_page() ) {
return;
}
if ( is_shop() ) {
get_sidebar( 'woocommerce' );
return;
}
}
get_sidebar();
return;
}
/**
* Post content classes.
*
* @param string $classes post content classes.
*
* @return string
*/
public function content_classes( $classes ) {
if ( ! class_exists( 'WooCommerce' ) ) {
return $classes;
}
$sidebar_layout = $this->get_page_sidebar_layout();
if ( is_product() ) {
return 'col-md-12';
}
if ( $this->should_have_sidebar() ) {
$classes = 'content-' . $sidebar_layout . ' col-md-9';
}
return $classes;
}
/**
* Change shop columns when we have a shop sidebar.
*/
public function sidebar_columns() {
return apply_filters( 'hestia_shop_loop_columns', 3 ); // 3 products per row
}
/**
* Utility to check if should have sidebar.
*
* @return bool
*/
private function should_have_sidebar() {
if ( is_customize_preview() && $this->get_page_sidebar_layout() !== 'full-width' ) {
return true;
}
if ( is_active_sidebar( 'sidebar-woocommerce' ) && $this->get_page_sidebar_layout() !== 'full-width' ) {
return true;
}
return false;
}
/**
* Get the sidebar layout.
*
* @return mixed|string
*/
public function get_page_sidebar_layout() {
return get_theme_mod( 'hestia_page_sidebar_layout', 'full-width' );
}
}
class-hestia-authors-section.php 0000666 00000012234 15113170145 0012766 0 ustar 00 <?php
/**
* Authors section on blog
*
* @package hestia
*/
/**
* Class Hestia_Authors_Section
*/
class Hestia_Authors_Section extends Hestia_Abstract_Main {
/**
* Members to display.
*
* @var array
*/
private $members_to_display = array();
/**
* Initialization function for authors section on blog.
*
* @return void
*/
public function init() {
add_action( 'hestia_after_archive_content', array( $this, 'render_authors_section' ), 10 );
}
/**
* Render function.
*
* @access public
* @return void
*/
public function render_authors_section() {
$this->initialize_members_list();
if ( empty( $this->members_to_display ) ) {
return;
}
$hestia_authors_on_blog_background = get_theme_mod( 'hestia_authors_on_blog_background' );
$background_inline = ! empty( $hestia_authors_on_blog_background ) ? 'style="background-image: url(' . esc_url( $hestia_authors_on_blog_background ) . ');"' : '';
$section_class = ! empty( $hestia_authors_on_blog_background ) ? 'authors-on-blog section-image' : 'authors-on-blog';
echo '<section id="authors-on-blog" class="' . esc_attr( $section_class ) . '" ' . $background_inline . '>';
echo '<div class="container"><div class="row">';
foreach ( $this->members_to_display as $team_item ) {
$image = ! empty( $team_item['image_url'] ) ? apply_filters( 'hestia_translate_single_string', $team_item['image_url'], 'Team section', 'Image' ) : '';
$title = ! empty( $team_item['title'] ) ? apply_filters( 'hestia_translate_single_string', $team_item['title'], 'Team section', 'Title' ) : '';
$subtitle = ! empty( $team_item['subtitle'] ) ? apply_filters( 'hestia_translate_single_string', $team_item['subtitle'], 'Team section', 'Subtitle' ) : '';
$text = ! empty( $team_item['text'] ) ? apply_filters( 'hestia_translate_single_string', $team_item['text'], 'Team section', 'Text' ) : '';
$link = ! empty( $team_item['link'] ) ? apply_filters( 'hestia_translate_single_string', $team_item['link'], 'Team section', 'Link' ) : '';
$icons = ! empty( $team_item['social_repeater'] ) ? $team_item['social_repeater'] : '';
echo '<div class="col-xs-12 col-ms-6 col-sm-6"><div class="card card-profile card-plain">';
echo '<div class="col-md-5"><div class="card-image">';
if ( ! empty( $image ) ) {
if ( ! empty( $link ) ) {
echo '<a href="' . esc_url( $link ) . '">';
}
echo '<img class="img" src="' . esc_url( $image ) . '">';
if ( ! empty( $link ) ) {
echo '</a>';
}
}
echo '</div></div>';
echo '<div class="col-md-7"><div class="content">';
if ( ! empty( $title ) ) {
echo '<h4 class="card-title">' . wp_kses_post( html_entity_decode( $title ) ) . '</h4>';
}
if ( ! empty( $subtitle ) ) {
echo '<h6 class="category text-muted">' . wp_kses_post( html_entity_decode( $subtitle ) ) . '</h6>';
}
if ( ! empty( $text ) ) {
echo '<p class="card-description">' . wp_kses_post( html_entity_decode( $text ) ) . '</p>';
}
if ( ! empty( $icons ) ) {
$icons = html_entity_decode( $icons );
$icons_decoded = json_decode( $icons, true );
if ( ! empty( $icons_decoded ) ) {
echo '<div class="footer">';
foreach ( $icons_decoded as $value ) {
$icon = ! empty( $value['icon'] ) ? apply_filters( 'hestia_translate_single_string', $value['icon'], 'Team section' ) : '';
$link = ! empty( $value['link'] ) ? apply_filters( 'hestia_translate_single_string', $value['link'], 'Team section' ) : '';
if ( ! empty( $icon ) ) {
$icon_class = ! empty( $hestia_authors_on_blog_background ) ? 'btn btn-just-icon btn-simple btn-white' : 'btn btn-just-icon btn-simple';
echo '<a href="' . esc_url( $link ) . '" class="' . esc_attr( $icon_class ) . '" >';
echo '<i class="fa ' . esc_attr( $icon ) . '"></i>';
echo '</a>';
}
}
echo '</div>';
}
}
echo '</div></div>';
echo '</div></div>';
}
echo '</div></div>';
echo '</section>';
}
/**
* Select from team members just those members that were selected in hestia_authors_on_blog control
*
* @access private
* @return void
*/
private function initialize_members_list() {
$hestia_authors_on_blog = get_theme_mod( 'hestia_authors_on_blog' );
if ( empty( $hestia_authors_on_blog ) || ( sizeof( $hestia_authors_on_blog ) === 1 && empty( $hestia_authors_on_blog[0] ) ) ) {
return;
}
$default_content = Hestia_Defaults_Models::instance()->get_team_default();
$hestia_team_content = get_theme_mod( 'hestia_team_content', $default_content );
if ( empty( $hestia_team_content ) ) {
return;
}
$hestia_team_content = json_decode( $hestia_team_content, true );
if ( ! empty( $hestia_team_content ) ) {
$this->members_to_display = array_filter( $hestia_team_content, array( $this, 'selected_authors' ) );
}
}
/**
* Filter function to check if the id is in team members.
*
* @access private
* @return bool
*/
private function selected_authors( $arr ) {
$hestia_authors_on_blog = (array) get_theme_mod( 'hestia_authors_on_blog' );
if ( empty( $hestia_authors_on_blog ) ) {
return false;
}
return in_array( $arr['id'], $hestia_authors_on_blog );
}
}
functions-posts-layout.php 0000666 00000006347 15114373072 0011767 0 ustar 00 <?php
/**
* Alias of class Customify_Post_Entry
*
* @return Customify_Post_Entry
*/
function Customify_Post_Entry() {
return Customify_Post_Entry::get_instance();
}
/**
* Filter to search results
*
* @TOTO: do not apply for WooCommerce results page.
*
* @param array $classes
*
* @return array
*/
function customify_post_classes( $classes ) {
if ( is_search() && get_query_var( 'post_type' ) != 'product' ) {
return array( 'entry', 'hentry', 'search-article' );
}
return $classes;
}
add_filter( 'post_class', 'customify_post_classes', 999 );
if ( ! function_exists( 'customify_blog_posts_heading' ) ) {
function customify_blog_posts_heading() {
if ( customify_is_post_title_display() ) {
if ( is_search() ) {
?>
<header class="blog-posts-heading">
<h1 class="page-title">
<?php
printf( // WPCS: XSS ok.
__( 'Search Results for: %s', 'customify' ),
'<span>' . get_search_query() . '</span>'
);
?>
</h1>
</header>
<?php
} elseif ( is_archive() ) {
?>
<header class="page-header blog-posts-heading">
<?php
the_archive_title( '<h1 class="page-title h3">', '</h1>' );
the_archive_description( '<div class="archive-description">', '</div>' );
?>
</header><!-- .page-header -->
<?php
} elseif ( customify_is_post_title_display() && ! ( is_front_page() && is_home() ) ) {
?>
<header class="blog-posts-heading">
<h1 class="page-title"><?php echo get_the_title( customify_get_support_meta_id() ); ?></h1>
</header>
<?php
}
}
}
}
if ( ! function_exists( 'customify_blog_posts' ) ) {
/**
* Display blog posts layout
*
* @param array $args
*/
function customify_blog_posts( $args = array() ) {
$args = wp_parse_args(
$args,
array(
'el_id' => 'blog-posts',
'prefix' => 'blog_post',
)
);
$render_class = apply_filters( 'customify/blog/render_callback', 'Customify_Posts_Layout' );
echo '<div id="' . esc_attr( $args['el_id'] ) . '">';
if ( have_posts() ) {
if ( class_exists( $render_class ) ) {
$l = new $render_class();
if ( method_exists( $l, 'render' ) ) {
call_user_func_array( array( $l, 'render' ), array( $args ) );
}
}
} else {
get_template_part( 'template-parts/content', 'none' );
};
echo '</div>';
}
}
if ( ! function_exists( 'customify_single_post' ) ) {
function customify_single_post() {
the_post();
$fields = Customify()->get_setting( 'single_blog_post_items' );
$args = array(
'meta_sep' => Customify()->get_setting( 'single_blog_post_meta_sep' ),
'meta_config' => Customify()->get_setting( 'single_blog_post_meta_config' ),
'author_avatar' => Customify()->get_setting( 'single_blog_post_author_avatar' ),
'avatar_size' => 32,
'thumbnail_size' => Customify()->get_setting( 'single_blog_post_thumbnail_size' ),
);
$size = Customify()->get_setting( 'single_blog_post_avatar_size' );
if ( is_array( $size ) && isset( $size['value'] ) ) {
$args['avatar_size'] = absint( $size['value'] );
}
Customify_Post_Entry()->set_config( $args );
?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'entry entry-single' ); ?>>
<?php Customify_Post_Entry()->build_fields( $fields ); ?>
</article>
<?php
}
}
class-post-entry.php 0000666 00000050467 15114373072 0010527 0 ustar 00 <?php
class Customify_Post_Entry {
public $post;
static $_instance;
public $config = array();
public $post_type = 'post';
function __construct( $_post = null ) {
$this->set_post( $_post );
$this->set_config();
}
function get_config_default() {
$args = array(
'excerpt_type' => 'custom',
'excerpt_length' => Customify()->get_setting( 'blog_post_excerpt_length' ),
'excerpt_more' => null,
'thumbnail_size' => Customify()->get_setting( 'blog_post_thumb_size' ),
'meta_config' => Customify()->get_setting( 'blog_post_meta' ),
'meta_sep' => _x( '-', 'post meta separator', 'customify' ),
'more_text' => null,
'more_display' => 1,
'term_sep' => _x( ',', 'post term separator', 'customify' ),
'term_count' => 1,
'tax' => 'category',
'title_tag' => 'h2',
'title_link' => 1,
'author_avatar' => Customify()->get_setting( 'blog_post_author_avatar' ),
'avatar_size' => 32,
);
$size = Customify()->get_setting( 'blog_post_avatar_size' );
if ( is_array( $size ) && isset( $size['value'] ) ) {
$args['avatar_size'] = absint( $size['value'] );
}
return $args;
}
/**
* Set config
*
* @param null $config
*/
function set_config( $config = null ) {
if ( ! is_array( $config ) ) {
$config = array();
}
$config = wp_parse_args( $config, $this->get_config_default() );
$this->config = $config;
}
/**
* Reset config
*/
function reset_config() {
$this->config = $this->get_config_default();
}
/**
* Set post data
*
* @param null $_post
*/
function set_post( $_post = null ) {
if ( ! $_post ) {
global $post;
$_post = get_post();
}
if ( is_array( $_post ) ) {
$_post = (object) $_post;
}
$this->post = $_post;
}
/**
* Main instance
*
* @return Customify_Post_Entry
*/
static function get_instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Trim the excerpt with custom length
*
* @see wp_trim_excerpt
*
* @param string $text
* @param int|bool $excerpt_length
* @return string
*/
function trim_excerpt( $text, $excerpt_length = null ) {
$text = strip_shortcodes( $text );
/** This filter is documented in wp-includes/post-template.php */
$text = apply_filters( 'the_content', $text );
$text = str_replace( ']]>', ']]>', $text );
if ( ! $excerpt_length ) {
/**
* Filters the number of words in an excerpt.
*
* @since 2.7.0
*
* @param int $number The number of words. Default 55.
*/
$excerpt_length = apply_filters( 'excerpt_length', 55 );
}
/**
* Filters the string in the "more" link displayed after a trimmed excerpt.
*
* @since 2.9.0
*
* @param string $more_string The string shown within the more link.
*/
if ( ! $this->config['excerpt_more'] ) {
$excerpt_more = apply_filters( 'excerpt_more', ' ' . '…' );
} else {
$excerpt_more = $this->config['excerpt_more'];
}
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
return $text;
}
/**
* Get meta date markup
*
* @return string
*/
function meta_date() {
$icon = '<i class="fa fa-clock-o" aria-hidden="true"></i> ';
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
}
$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 = '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $icon . $time_string . '</a>';
return '<span class="meta-item posted-on">' . $posted_on . '</span>';
}
/**
* Get terms array
*
* @param string $id Post ID.
* @param string $taxonomy Name of taxonomy.
* @param bool $icon_first
* @return array|bool|WP_Error
*/
function get_terms_list( $id, $taxonomy, $icon_first = false ) {
$terms = get_the_terms( $id, $taxonomy );
if ( is_wp_error( $terms ) ) {
return $terms;
}
if ( empty( $terms ) ) {
return false;
}
if ( class_exists( 'WPSEO_Primary_Term' ) ) {
$prm_term_id = $this->get_primary_term_id( $id, $taxonomy );
$prm_term = get_term( $prm_term_id, $taxonomy );
$prm_term_arr[] = $prm_term;
// Make the primary term be the first term in the terms array.
foreach ( $terms as $index => $term ) {
if ( $prm_term_id == $term->term_id ) {
unset( $terms[ $index ] );
break;
}
}
$terms = array_merge( $prm_term_arr, $terms );
}
$links = array();
$icon = '<i class="fa fa-folder-open-o" aria-hidden="true"></i> ';
foreach ( $terms as $index => $term ) {
$link = get_term_link( $term, $taxonomy );
if ( is_wp_error( $link ) ) {
return $link;
}
if ( $icon_first && 0 == $index ) { // phpcs:ignore
} else {
$icon = '';
}
$links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $icon . esc_html( $term->name ) . '</a>';
}
return $links;
}
/**
* Get primary term ID.
*
* The primary term is either the first term or the primary term set via YOAST SEO Plugin.
*
* @param int $post_id Post ID.
* @param string $taxonomy Name of taxonomy.
* @return int|false Primary or first term ID. False if no term is set.
*/
function get_primary_term_id( $post_id, $taxonomy ) {
$prm_term = '';
if ( class_exists( 'WPSEO_Primary_Term' ) ) {
$wpseo_primary_term = new WPSEO_Primary_Term( $taxonomy, $post_id );
$prm_term = $wpseo_primary_term->get_primary_term();
}
if ( ! is_object( $wpseo_primary_term ) || empty( $prm_term ) ) {
$term = wp_get_post_terms( $post_id, $taxonomy );
if ( isset( $term ) && ! empty( $term ) ) {
return $term[0]->term_id;
} else {
return '';
}
}
return $wpseo_primary_term->get_primary_term();
}
/**
* Get first category markup
*
* @return string
*/
function meta_categories() {
$html = '';
if ( get_post_type() === $this->post_type ) {
/* translators: used between list items, there is a space after the comma */
$categories_list = $this->get_terms_list( $this->get_post_id(), $this->config['tax'], true );
if ( is_array( $categories_list ) && $this->config['term_count'] > 0 ) {
$categories_list = array_slice( $categories_list, 0, $this->config['term_count'] );
}
$html .= sprintf( '<span class="meta-item meta-cat">%1$s</span>', join( $this->config['term_sep'], $categories_list ) ); // WPCS: XSS OK.
}
return $html;
}
/**
* Get Tags list markup
*
* @return string
*/
function meta_tags() {
$html = '';
if ( 'post' === get_post_type() ) {
/* translators: used between list items, there is a space after the comma */
$tags_list = get_the_tag_list( '', esc_html_x( ', ', 'list item separator', 'customify' ) );
if ( $tags_list ) {
$html .= sprintf( '<span class="meta-item tags-links">%1$s</span>', $tags_list ); // WPCS: XSS OK.
}
}
return $html;
}
/**
* Get tags list markup
*/
function post_tags() {
$html = '';
if ( 'post' === get_post_type() ) {
/* translators: used between list items, there is a space after the comma */
$tags_list = get_the_tag_list( '', esc_html_x( ', ', 'list item separator', 'customify' ) );
if ( $tags_list ) {
$html .= sprintf( '<div class="entry--item entry-tags tags-links">' . esc_html__( 'Tagged ', 'customify' ) . '%1$s</div>', $tags_list ); // WPCS: XSS OK.
}
}
echo $html;
}
/**
* Get categories list markup
*/
function post_categories() {
$html = '';
if ( 'post' === get_post_type() ) {
/* translators: used between list items, there is a space after the comma */
$list = get_the_category_list( esc_html_x( ', ', 'list item separator', 'customify' ) );
if ( $list ) {
$html .= sprintf( '<div class="entry--item entry-categories cats-links">' . esc_html__( 'Posted in ', 'customify' ) . '%1$s</div>', $list ); // WPCS: XSS OK.
}
}
echo $html;
}
/**
* Get comment number markup
*
* @return string
*/
function meta_comment() {
$html = '';
if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
$icon = '<i class="fa fa-comments-o"></i> ';
$comment_count = get_comments_number();
$html .= '<span class="meta-item comments-link">';
$html .= '<a href="' . esc_url( get_comments_link() ) . '">' . $icon;
if ( 1 === $comment_count ) {
$html .= sprintf(
/* translators: 1: title. */
esc_html__( '1 Comment', 'customify' ),
$comment_count
);
} else {
$html .= sprintf( // WPCS: XSS OK.
/* translators: 1: comment count number, 2: title. */
esc_html( _nx( '%1$s Comment', '%1$s Comments', $comment_count, 'comments number', 'customify' ) ),
number_format_i18n( $comment_count )
);
}
$html .= '</a>';
$html .= '</span>';
}
return $html;
}
/**
* Get author markup
*
* @return string
*/
function meta_author() {
if ( $this->config['author_avatar'] ) {
$avatar = get_avatar( get_the_author_meta( 'ID' ), $this->config['avatar_size'] );
} else {
$avatar = '<i class="fa fa-user-circle-o"></i> ';
}
$byline = '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . $avatar . esc_html( get_the_author() ) . '</a></span>';
return '<span class="meta-item byline"> ' . $byline . '</span>'; // WPCS: XSS OK.
}
/**
* Check if show post meta for this post
*
* @param object|integer $post
*
* @return boolean
*/
private function show_post_meta( $post ) {
return apply_filters( 'customify/show/post_meta', get_post_type( $post ) == 'post' && ! is_search() );
}
/**
* Get post meta markup
*
* @param object|integer $post
* @param array $meta_fields
* @param array $args
*/
function post_meta( $post = null, $meta_fields = array(), $args = array() ) {
if ( ! $this->show_post_meta( $post ) ) {
return;
}
if ( empty( $meta_fields ) ) {
$meta_fields = $this->config['meta_config'];
}
$metas = array();
foreach ( (array) $meta_fields as $item ) {
$item = wp_parse_args(
$item,
array(
'_key' => '',
'_visibility' => '',
)
);
if ( 'hidden' !== $item['_visibility'] ) {
if ( method_exists( $this, 'meta_' . $item['_key'] ) ) {
$s = call_user_func_array( array( $this, 'meta_' . $item['_key'] ), array( $this->post, $args ) );
if ( $s ) {
$metas[ $item['_key'] ] = $s;
}
}
}
}
if ( ! empty( $metas ) ) {
?>
<div class="entry-meta entry--item text-uppercase text-xsmall link-meta">
<?php
// WPCS: XSS OK.
echo join( '<span class="sep">' . $this->config['meta_sep'] . '</span>', $metas );
?>
</div><!-- .entry-meta -->
<?php
}
}
/**
* Post title markup
*
* @param null|WP_Post|int $post
* @param bool $force_link
*/
function post_title( $post = null, $force_link = false ) {
if ( is_singular() && ! $force_link ) {
if ( customify_is_post_title_display() ) {
the_title( '<h1 class="entry-title entry--item h2">', '</h1>' );
}
} else {
if ( $this->config['title_link'] ) {
the_title( '<' . $this->config['title_tag'] . ' class="entry-title entry--item"><a href="' . esc_url( get_permalink( $post ) ) . '" title="' . the_title_attribute( array( 'echo' => false ) ) . '" rel="bookmark" class="plain_color">', '</a></' . $this->config['title_tag'] . '>' );
} else {
the_title( '<' . $this->config['title_tag'] . ' class="entry-title entry--item">', '</' . $this->config['title_tag'] . '>' );
}
}
}
function get_post_id( $post = null ) {
if ( is_object( $post ) ) {
return $post->ID;
} elseif ( is_array( $post ) ) {
return $post['ID'];
} elseif ( is_numeric( $post ) ) {
return $post;
} else {
return get_the_ID();
}
}
/**
* Get first category markup
*
* @param null|WP_Post|int $post
*/
function post_category( $post = null ) {
$html = '';
if ( get_post_type() === $this->post_type ) {
/* translators: used between list items, there is a space after the comma */
$categories_list = get_the_term_list( $this->get_post_id( $post ), $this->config['tax'], '', '__cate_sep__' );
if ( $categories_list && ! is_wp_error( $categories_list ) ) {
$categories_list = explode( '__cate_sep__', $categories_list );
if ( $this->config['term_count'] > 0 ) {
$categories_list = array_slice( $categories_list, 0, $this->config['term_count'] );
}
$html .= sprintf( '<span class="entry-cat entry--item">%1$s</span>', join( $this->config['term_sep'], $categories_list ) ); // WPCS: XSS OK.
}
}
echo $html;
}
/**
* Post thumbnail markup
*
* @param null|WP_Post|int $post
*/
function post_thumbnail( $post = null ) {
if ( is_single() && ! is_front_page() && ! is_home() ) {
if ( has_post_thumbnail() ) {
?>
<div class="entry-thumbnail <?php echo ( has_post_thumbnail() ) ? 'has-thumb' : 'no-thumb'; ?>">
<?php the_post_thumbnail( $this->config['thumbnail_size'] ); ?>
</div>
<?php
}
} else {
?>
<div class="entry-thumbnail <?php echo ( has_post_thumbnail() ) ? 'has-thumb' : 'no-thumb'; ?>">
<?php the_post_thumbnail( $this->config['thumbnail_size'] ); ?>
</div>
<?php
}
}
/**
* Post excerpt markup
*
* @param null|WP_Post|int $post
* @param string $type
* @param int|bool $length
*/
function post_excerpt( $post = null, $type = '', $length = false ) {
if ( ! $type ) {
$type = $this->config['excerpt_type'];
}
if ( ! $length ) {
$length = $this->config['excerpt_length'];
}
echo '<div class="entry-excerpt entry--item">';
if ( 'excerpt' == $type ) {
the_excerpt();
} elseif ( 'more_tag' == $type ) {
the_content( '', true );
} elseif ( 'content' == $type ) {
the_content( '', false );
} else {
$text = '';
if ( $this->post ) {
if ( '' != get_the_excerpt() ) {
$text = get_the_excerpt();
} elseif ( $this->post->post_excerpt ) {
$text = $this->post->post_excerpt;
} else {
$text = $this->post->post_content;
}
}
$excerpt = $this->trim_excerpt( $text, $length );
if ( $excerpt ) {
// WPCS: XSS OK.
echo apply_filters( 'the_excerpt', $excerpt );
} else {
the_excerpt();
}
}
echo '</div>';
}
/**
* Post content markup
*/
function post_content() {
?>
<div class="entry-content entry--item">
<?php
the_content();
$this->post_pagination();
?>
</div><!-- .entry-content -->
<?php
}
/**
* Post readmore
*/
function post_readmore() {
if ( ! $this->config['more_display'] ) {
return;
}
$more = $this->config['more_text'];
if ( ! $more ) {
if ( ! is_rtl() ) {
$more = __( 'Read more →', 'customify' );
} else {
$more = __( 'Read more ←', 'customify' );
}
}
?>
<div class="entry-readmore entry--item">
<a class="readmore-button" href="<?php the_permalink(); ?>" title="<?php esc_attr( sprintf( __( 'Continue reading %s', 'customify' ), get_the_title() ) ); ?>"><?php echo wp_kses_post( $more ); ?></a>
</div><!-- .entry-content -->
<?php
}
function post_comment_form() {
if ( is_single() ) {
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
echo '<div class="entry-comment-form entry--item">';
comments_template();
echo '</div>';
endif;
}
}
function post_author_bio() {
if ( ! is_singular( 'post' ) ) {
return;
}
if ( is_single() ) {
global $post;
// Detect if it is a single post with a post author.
if ( is_single() && isset( $post->post_author ) ) {
$user = get_user_by( 'ID', $post->post_author );
if ( ! $user ) {
return;
}
$display_name = $user->display_name ? $user->display_name : $user->user_login;
// Get author's biographical information or description.
$user_description = get_the_author_meta( 'user_description', $user->ID );
// Get author's website URL.
$user_website = get_the_author_meta( 'url', $user->ID );
// Get link to the author archive page.
$user_posts = get_author_posts_url( get_the_author_meta( 'ID', $user->ID ) );
if ( ! empty( $display_name ) ) {
$author_details = '<h4 class="author-bio-heading">' . sprintf( __( 'About the Author: <span>%s</span>', 'customify' ), $display_name ) . '</h4>';
}
$user_description = wptexturize( $user_description );
$user_description = wpautop( $user_description );
$user_description = convert_smilies( $user_description );
$author_links = '<p class="author_links text-uppercase text-xsmall link-meta"><a href="' . $user_posts . '">' . sprintf( 'View all post by %s', $display_name ) . '</a>';
// Check if author has a website in their profile.
if ( ! empty( $user_website ) ) {
// Display author website link.
$author_links .= ' | <a href="' . $user_website . '" target="_blank" rel="nofollow">Website</a></p>';
} else {
// if there is no author website then just close the paragraph.
$author_links .= '</p>';
}
$author_details .= '<div class="author-bio"><div class="author-bio-avatar">' . get_avatar( get_the_author_meta( 'user_email' ), 80 ) . '</div><div class="author-bio-details"><div class="author-bio-desc">' . $user_description . '</div>' . $author_links . '</div></div>';
// Pass all this info to post content.
$content = '<div class="entry-author-bio entry--item" >' . $author_details . '</div>';
}
echo $content;
}
}
function post_navigation() {
if ( ! is_single() ) {
return '';
}
if ( get_post_type() != 'post' ) {
return '';
}
echo '<div class="entry-post-navigation entry--item">';
the_post_navigation(
array(
'next_text' => '<span class="meta-nav text-uppercase text-xsmall color-meta" aria-hidden="true">'
. __( 'Next', 'customify' ) . '</span> '
. '<span class="screen-reader-text">' . __( 'Next post:', 'customify' ) . '</span> '
. '<span class="post-title text-large">%title</span>',
'prev_text' => '<span class="meta-nav text-uppercase text-xsmall color-meta" aria-hidden="true">'
. __( 'Previous', 'customify' ) . '</span> '
. '<span class="screen-reader-text">' . __( 'Previous post:', 'customify' ) . '</span> '
. '<span class="post-title text-large">%title</span>',
)
);
echo '</div>';
}
/**
* Post pagination markup
*/
function post_pagination() {
if ( ! is_single() ) {
return '';
}
wp_link_pages(
array(
'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'customify' ),
'after' => '</div>',
)
);
}
/**
* Display related post
*/
function post_related() {
if ( ! is_single() ) {
return '';
}
if ( get_post_type() != 'post' ) {
return '';
}
Customify_Related_Posts::get_instance()->display();
}
/**
* Build item markup width field config
*
* @param string $field Field settings.
* @param WP_Post|null|int $post
* @param array $fields
* @param array $args
*/
function build( $field, $post = null, $fields = null, $args = array() ) {
// Allowed 3rd party hook to this.
$cb = apply_filters( 'customify/single/build_field_callback', false, $field );
if ( ! is_callable( $cb ) ) {
if ( method_exists( $this, 'post_' . $field ) ) {
$cb = array( $this, 'post_' . $field );
}
}
$type = is_single() ? 'single' : 'loop';
/**
* Hook before post item part
*
* @since 0.2.2
*/
do_action( "customify/{$type}/field_{$field}/before", $post, $fields, $args, $this );
if ( is_callable( $cb ) ) {
call_user_func_array( $cb, array( $post, $fields, $args ) );
}
/**
* Hook after post item part
*
* @since 0.2.2
*/
do_action( "customify/{$type}/field_{$field}/after", $post, $fields, $args, $this );
}
/**
* Build item markup width fields config
*
* @param array $fields
* @param WP_Post|null|int $post
* @param array $args
*/
function build_fields( $fields, $post = null, $args = array() ) {
foreach ( (array) $fields as $item ) {
$item = wp_parse_args(
$item,
array(
'_key' => '',
'_visibility' => '',
'fields' => null,
)
);
if ( 'hidden' !== $item['_visibility'] ) {
$this->build( $item['_key'], $post, $item['fields'], $args );
}
}
}
}
class-related-posts.php 0000666 00000012007 15114373072 0011155 0 ustar 00 <?php
/**
* Class Customify_Related_Posts
*
* @since 0.2.4
*/
class Customify_Related_Posts {
static private $_instance = null;
/**
* Get instance
*
* @return Customify_Related_Posts
*/
static function get_instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Get related posts
*
* @param WP_Post|null|int $post
* @param string $by
* @param int $number
* @param string $orderby
* @param string $order
*
* @return WP_Query|bool
*/
function get_related_post( $post = null, $by = 'cat', $number = 3, $orderby = 'date', $order = 'desc' ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}
$current_post_type = get_post_type( $post );
$query_args = array(
'post_type' => $current_post_type,
'post__not_in' => array( $post->ID ),
'posts_per_page' => $number,
'orderby' => $orderby,
'order' => $order,
);
if ( 'tag' == $by ) {
$terms = get_the_tags( $post->ID );
$term_ids = array();
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$term_ids = wp_list_pluck( $terms, 'term_id' );
}
$query_args['tag__in'] = $term_ids;
} else {
$terms = get_the_category( $post->ID );
$term_ids = array();
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$term_ids = wp_list_pluck( $terms, 'term_id' );
}
$query_args['category__in'] = $term_ids;
}
// Try get related by hand pick.
$post__in = get_post_meta( $post->ID, '_customify_related_posts' );
if ( ! empty( $post__in ) && is_array( $post__in ) ) {
unset( $query_args['category__in'] );
unset( $query_args['tag__in'] );
$query_args['post__in'] = $post__in;
}
$query_args = apply_filters( 'customify/single_post/related_args', $query_args );
$related_cats_post = new WP_Query( $query_args );
return $related_cats_post;
}
/**
* Display related post
*
* @return bool
*/
function display() {
if ( ! is_single() ) {
return false;
}
$number = Customify()->get_setting( 'single_blog_post_related_number' );
$number = absint( $number );
if ( $number <= 0 ) {
return false;
}
$layout = 'grid';
$title = Customify()->get_setting( 'single_blog_post_related_title' );
$cols = Customify()->get_setting( 'single_blog_post_related_col', 'all' );
$by = Customify()->get_setting( 'single_blog_post_related_by' );
$orderby = Customify()->get_setting( 'single_blog_post_related_orderby' );
$order = Customify()->get_setting( 'single_blog_post_related_order' );
// Get related posts.
$query_posts = $this->get_related_post( null, $by, $number, $orderby, $order );
if ( $query_posts ) {
$image_position = Customify()->get_setting( 'single_blog_post_related_img_pos' );
$thumbnail_size = Customify()->get_setting( 'single_blog_post_related_thumbnail_size' );
$excerpt_length = Customify()->get_setting( 'single_blog_post_related_excerpt_length' );
$meta_config = Customify()->get_setting( 'single_blog_post_related_meta' );
$meta_args = array();
$wrapper_classes = array(
'entry--item entry-related',
'related-' . esc_attr( $layout ),
'img-pos-' . esc_attr( $image_position ),
);
if ( ! is_array( $cols ) ) {
$cols = array();
}
$cols = wp_parse_args(
$cols,
array(
'desktop' => 2,
'tablet' => 2,
'mobile' => 2,
)
);
$cols = array_map( 'absint', $cols );
if ( ! $cols['desktop'] ) {
$cols['desktop'] = 2;
}
if ( ! $cols['tablet'] ) {
$cols['tablet'] = 1;
}
if ( ! $cols['mobile'] ) {
$cols['mobile'] = 1;
}
$layout_class = "customify-grid-{$cols['desktop']}_sm-{$cols['tablet']}}_xs-{$cols['mobile']}}";
if ( ! $query_posts->have_posts() ) {
return '';
}
global $post;
echo '<div class="' . esc_attr( join( ' ', $wrapper_classes ) ) . ' ">';
echo '<h4 class="related-post-title">' . wp_kses_post( $title ) . '</h4>';
echo '<div class="related-posts ' . esc_attr( $layout_class ) . '">';
while ( $query_posts->have_posts() ) {
$query_posts->the_post();
$link = '<a href="' . esc_url( get_permalink( $post ) ) . '" title="' . the_title_attribute( array( 'echo' => false ) ) . '" rel="bookmark" class="plain_color">';
?>
<article <?php post_class( 'related-post customify-col' ); ?>>
<div class="related-thumbnail <?php echo ( has_post_thumbnail() ) ? 'has-thumb' : 'no-thumb'; ?>">
<?php echo $link; ?>
<?php the_post_thumbnail( $thumbnail_size ); ?>
</a>
</div>
<div class="related-body">
<?php
the_title( '<h2 class="entry-title entry--item">' . $link, '</a></h2>' );
Customify_Post_Entry::get_instance()->post_meta( $post, $meta_config, $meta_args );
if ( $excerpt_length > 0 ) {
Customify_Post_Entry::get_instance()->post_excerpt( $post, 'custom', $excerpt_length );
}
?>
</div>
<?php
echo '</article>';
}
wp_reset_postdata();
echo '</div>';
echo '</div>';
}
}
}
class-posts-layout.php 0000666 00000027720 15114373072 0011062 0 ustar 00 <?php
class Customify_Posts_Layout {
public $args = array();
public $customizer_args = array();
public $entry_class = '';
function set_args( $customizer_args = array() ) {
$args = array(
'layout' => Customify()->get_setting( $customizer_args['prefix'] . '_layout' ),
'excerpt_type' => Customify()->get_setting( $customizer_args['prefix'] . '_excerpt_type' ),
'excerpt_length' => Customify()->get_setting( $customizer_args['prefix'] . '_excerpt_length' ),
'excerpt_more' => Customify()->get_setting( $customizer_args['prefix'] . '_excerpt_more' ),
'more_text' => Customify()->get_setting( $customizer_args['prefix'] . '_more_text' ),
'more_display' => Customify()->get_setting( $customizer_args['prefix'] . '_more_display' ),
'thumbnail_size' => Customify()->get_setting( $customizer_args['prefix'] . '_thumbnail_size' ),
'hide_thumb_if_empty' => Customify()->get_setting( $customizer_args['prefix'] . '_hide_thumb_if_empty' ),
'meta_config' => Customify()->get_setting( $customizer_args['prefix'] . '_meta_config' ),
'meta_sep' => Customify()->get_setting( $customizer_args['prefix'] . '_meta_sep' ),
'author_avatar' => Customify()->get_setting( $customizer_args['prefix'] . '_author_avatar' ),
'media_hide' => Customify()->get_setting( $customizer_args['prefix'] . '_media_hide' ),
);
$size = Customify()->get_setting( $customizer_args['prefix'] . '_avatar_size' );
if ( is_array( $size ) && isset( $size['value'] ) ) {
$args['avatar_size'] = absint( $size['value'] );
}
$pagination = array(
'show_paging' => Customify()->get_setting( $customizer_args['prefix'] . '_pg_show_paging' ),
'show_nav' => Customify()->get_setting( $customizer_args['prefix'] . '_pg_show_nav' ),
'mid_size' => Customify()->get_setting( $customizer_args['prefix'] . '_pg_mid_size' ),
'prev_text' => Customify()->get_setting( $customizer_args['prefix'] . '_pg_prev_text' ),
'next_text' => Customify()->get_setting( $customizer_args['prefix'] . '_pg_next_text' ),
);
$args['pagination'] = is_array( $pagination ) ? $pagination : array();
$this->customizer_args = $customizer_args;
$_args = wp_parse_args(
$args,
array(
'layout' => '',
'columns' => '',
'excerpt_length' => '',
'excerpt_more' => '',
'more_text' => '',
'more_display' => 1,
'thumbnail_size' => '',
'hide_thumb_if_empty' => 1,
'pagination' => array(),
'meta_config' => array(),
'meta_sep' => null,
)
);
if ( ! $_args['layout'] || is_array( $_args['layout'] ) ) {
$_args['layout'] = 'blog_classic';
}
$_args['pagination'] = wp_parse_args(
$_args['pagination'],
array(
'show_paging' => 1,
'show_number' => 1,
'show_nav' => 1,
'prev_text' => '',
'next_text' => '',
'mid_size' => 3,
)
);
if ( ! $_args['columns'] ) {
$c = $this->get_predefined( $_args['layout'] );
if ( $c ) {
$_args['columns'] = $c['columns'];
}
}
$_args['columns'] = absint( $_args['columns'] );
if ( $_args['columns'] < 1 ) {
$_args['columns'] = 1;
}
if ( ( ! isset( $args['columns'] ) || ! $args['columns'] ) && 'blog_masonry' == $_args['layout'] ) {
$_args['columns'] = 3;
}
if ( in_array( $_args['layout'], array( 'blog_lateral', 'blog_classic' ) ) ) { // phpcs:ignore
$_args['columns'] = 1;
}
$_args['pagination']['mid_size'] = absint( $_args['pagination']['mid_size'] );
if ( empty( $_args['meta_config'] ) ) {
$_args['meta_config'] = array(
array(
'_key' => 'author',
),
array(
'_key' => 'date',
),
array(
'_key' => 'categories',
),
array(
'_key' => 'comment',
),
);
}
$this->args = $_args;
$this->args['header_fields'] = array(
array(
'_visibility' => '',
'_key' => 'title',
),
array(
'_key' => 'meta',
'_visibility' => '',
),
);
$this->args['body_fields'] = array(
array(
'_key' => 'excerpt',
'_visibility' => '',
),
);
$this->args['footer_fields'] = array(
array(
'_key' => 'readmore',
'_visibility' => '',
),
);
$this->args['media_fields'] = array();
if ( isset( $this->customizer_args['_overwrite'] ) ) {
$this->args = array_merge( $this->args, $this->customizer_args['_overwrite'] );
}
Customify_Post_Entry()->set_config( $this->args );
}
function has_only_field( $fields, $field = 'category' ) {
$check = false;
$n = 0;
$c = false;
foreach ( (array) $fields as $item ) {
$item = wp_parse_args(
$item,
array(
'_key' => '',
'_visibility' => '',
)
);
if ( 'hidden' !== $item['_visibility'] ) {
$n ++;
if ( $item['_key'] == $field ) {
$c = true;
}
}
}
if ( $c && $n < 2 ) {
$check = true;
} else {
$check = false;
}
return $check;
}
function count_item_visibility( $fields ) {
$n = 0;
foreach ( (array) $fields as $item ) {
$item = wp_parse_args(
$item,
array(
'_key' => '',
'_visibility' => '',
)
);
if ( 'hidden' !== $item['_visibility'] ) {
$n ++;
}
}
return $n;
}
function item_part( $part = '', $post = null, $inner_class = '' ) {
$n = $this->count_item_visibility( $this->args[ $part . '_fields' ] );
if ( isset( $this->args[ $part . '_fields' ] ) && $n > 0 ) {
if ( 'media' == $part && $this->has_only_field( $this->args[ $part . '_fields' ] ) ) {
Customify_Post_Entry()->build_fields( $this->args[ $part . '_fields' ], $post );
} else {
$only_more = $this->has_only_field( $this->args[ $part . '_fields' ], 'readmore' );
$classes = array();
$classes[] = 'entry-article-part entry-article-' . $part;
if ( $only_more ) {
$classes[] = 'only-more';
}
echo '<div class="' . esc_attr( join( ' ', $classes ) ) . '">';
if ( $inner_class ) {
echo '<div class="' . esc_attr( $inner_class ) . '">';
}
Customify_Post_Entry()->build_fields( $this->args[ $part . '_fields' ], $post );
if ( $inner_class ) {
echo '</div>';
}
echo '</div>';
}
}
}
function layout( $post = null ) {
$media_fields = array(
array(
'_key' => 'thumbnail',
),
);
if ( $this->args['media_hide'] ) {
$show_media = false;
} else {
$show_media = true;
if ( ! has_post_thumbnail( $post ) ) {
if ( $this->args['hide_thumb_if_empty'] ) {
$show_media = false;
}
}
}
switch ( $this->args['layout'] ) {
case 'blog_column':
$this->item_part( 'header', $post );
if ( $show_media && $this->count_item_visibility( $this->args['header_fields'] ) ) {
?>
<div class="entry-article-part entry-media">
<a class="entry-media-link " href="<?php echo esc_url( get_permalink( $post ) ); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"></a>
<?php
Customify_Post_Entry()->build_fields( $media_fields, $post );
$this->item_part( 'media', $post, 'media-content-inner' );
?>
</div>
<?php } ?>
<div class="entry-content-data">
<?php
$this->item_part( 'body', $post );
$this->item_part( 'footer', $post );
?>
</div>
<?php
break;
default:
if ( $show_media && $this->count_item_visibility( $this->args['header_fields'] ) ) {
?>
<div class="entry-media">
<a class="entry-media-link " href="<?php echo esc_url( get_permalink( $post ) ); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"></a>
<?php
Customify_Post_Entry()->build_fields( $media_fields, $post );
$this->item_part( 'media', $post, 'media-content-inner' );
?>
</div>
<?php } ?>
<div class="entry-content-data">
<?php
$this->item_part( 'header', $post );
$this->item_part( 'body', $post );
$this->item_part( 'footer', $post );
?>
</div>
<?php
}
}
function blog_item( $post = null, $class = null ) {
$entry_class = array( 'entry' );
if ( is_numeric( $this->args['columns'] ) && $this->args['columns'] > 1 ) {
$entry_class[] = 'customify-col';
} elseif ( is_array( $this->args['columns'] ) ) {
$entry_class[] = 'customify-col';
}
if ( $class ) {
$entry_class[] = $class;
}
if ( $this->entry_class ) {
$entry_class[] = $this->entry_class;
}
$key = 'loop';
if ( is_single() ) {
$key = 'single';
}
Customify_Post_Entry()->set_post( $post );
/**
* Hook before each post
*
* @since 0.2.0
*/
do_action( "customify/before-post/{$key}" );
?>
<article <?php post_class( join( ' ', $entry_class ), $post ); ?>>
<div class="entry-inner">
<?php
$this->layout( $post );
?>
</div>
</article><!-- /.entry post -->
<?php
/**
* Hook after each post
*
* @since 0.2.0
*/
do_action( "customify/after-post/{$key}" );
}
function get_predefined( $layout ) {
if ( ! is_string( $layout ) ) {
return false;
}
$presets = array(
'blog_classic' => array(
'columns' => 1,
'pagination' => array(),
),
'blog_lateral' => array(
'columns' => 1,
'pagination' => array(),
),
'blog_boxed' => array(
'columns' => 2,
'pagination' => array(),
),
);
if ( ! empty( $layout ) ) {
if ( isset( $presets[ $layout ] ) && $presets[ $layout ] ) {
return $presets[ $layout ];
}
}
return false;
}
function render( $customizer_args = array() ) {
$this->set_args( $customizer_args );
$classes = array();
$atts = array();
if ( is_numeric( $this->args['columns'] ) && $this->args['columns'] > 1 ) {
$classes['grid'] = 'customify-grid-' . $this->args['columns'];
$atts['data-col'] = $this->args['columns'];
} elseif ( is_array( $this->args['columns'] ) ) {
$this->args['columns'] = wp_parse_args(
$this->args['columns'],
array(
'desktop' => 1,
'tablet' => 1,
'mobile' => 1,
)
);
foreach ( $this->args['columns'] as $d => $v ) {
$v = absint( $v );
if ( $v < 1 ) {
$v = 1;
} elseif ( $v > 12 ) {
$v = 12;
}
$this->args['columns'][ $d ] = $v;
$atts[ 'data-col-' . $d ] = $v;
}
$classes['grid'] = sprintf( 'customify-grid-%1$s_sm-%2$s_xs-%3$s', $this->args['columns']['desktop'], $this->args['columns']['tablet'], $this->args['columns']['mobile'] );
}
$classes[] = 'posts-layout';
$classes[] = 'layout--' . $this->args['layout'];
$s_atts = '';
foreach ( $atts as $k => $v ) {
$s_atts .= " {$k}='" . esc_attr( $v ) . "' ";
}
do_action( 'customify/blog/before-render', $this );
?>
<div class="posts-layout-wrapper">
<div class="<?php echo esc_attr( join( ' ', $classes ) ); ?>"<?php echo $s_atts; // WPCS: XSS OK. ?>>
<?php
if ( 'blog_timeline' == $this->args['layout'] ) {
echo '<div class="time-line"></div>';
}
?>
<?php
if ( have_posts() ) {
global $post;
/* Start the Loop */
$i = 1;
while ( have_posts() ) {
the_post();
$this->blog_item( $post, ( 0 == $i % 2 ) ? 'even' : 'odd' );
$i ++;
}
} else {
get_template_part( 'template-parts/content', 'none' );
}
?>
</div>
<?php
$this->render_pagination();
?>
</div>
<?php
do_action( 'customify/blog/after-render', $this );
}
function render_pagination() {
if ( ! $this->args['pagination']['show_paging'] ) {
return;
}
$prev_next = true;
if ( $this->args['pagination']['show_nav'] ) {
$prev_text = $this->args['pagination']['prev_text'];
$next_text = $this->args['pagination']['next_text'];
if ( ! $prev_text ) {
$prev_text = _x( 'Previous', 'previous set of posts', 'customify' );
}
if ( ! $next_text ) {
$next_text = _x( 'Next', 'next set of posts', 'customify' );
}
} else {
$prev_text = false;
$next_text = false;
$prev_next = false;
}
the_posts_pagination(
array(
'mid_size' => ( $this->args['pagination']['mid_size'] ) ? 3 : 0,
'prev_text' => $prev_text,
'next_text' => $next_text,
'prev_next' => $prev_next,
)
);
}
}