* Created on: 27/08/2018 * * @package Neve\Views */ namespace Neve\Views; /** * Class Template_Parts * * @package Neve\Views */ class Template_Parts extends Base_View { /** * Function that is run after instantiation. * * @return void */ public function init() { add_action( 'neve_blog_post_template_part_content', array( $this, 'render_post' ) ); add_filter( 'excerpt_more', array( $this, 'link_excerpt_more' ) ); add_filter( 'the_content_more_link', array( $this, 'link_excerpt_more' ) ); } /** * Render the post. */ public function render_post() { $args = array( 'post_id' => 'post-' . get_the_ID(), 'post_class' => $this->post_class(), 'content' => $this->get_article_inner_content(), ); $this->get_view( 'archive-post', $args ); } /** * Echo the post class. */ private function post_class() { $class = join( ' ', get_post_class() ); $class .= ' col-12 layout-' . $this->get_layout(); if ( $this->get_layout() === 'grid' ) { $class .= ' ' . $this->get_grid_columns_class(); } else { $class .= ' nv-non-grid-article'; } return $class; } /** * Render inner content for
* * @return string */ private function get_article_inner_content() { $markup = ''; if ( $this->get_layout() !== 'grid' ) { $markup .= $this->get_post_thumbnail(); $markup .= '
'; $markup .= $this->get_title(); $markup .= $this->get_meta(); $markup .= $this->get_excerpt(); $markup .= '
'; return $markup; } $default_order = array( 'thumbnail', 'title-meta', 'excerpt', ); $order = get_theme_mod( 'neve_post_content_ordering', json_encode( $default_order ) ); $order = json_decode( $order, true ); foreach ( $order as $content_bit ) { switch ( $content_bit ) { case 'thumbnail': $markup .= $this->get_post_thumbnail(); break; case 'title': $markup .= $this->get_title(); break; case 'meta': $markup .= $this->get_meta(); break; case 'title-meta': $markup .= $this->get_title(); $markup .= $this->get_meta(); break; case 'excerpt': $markup .= $this->get_excerpt(); break; default: break; } } return $markup; } /** * Render the post thumbnail. * * @return string */ private function get_post_thumbnail() { if ( ! has_post_thumbnail() ) { return ''; } $markup = '
'; $markup .= ''; $markup .= get_the_post_thumbnail( get_the_ID(), 'neve-blog' ); $markup .= ''; $markup .= '
'; return $markup; } /** * Get the posts layout. * * @return string */ private function get_layout() { return get_theme_mod( 'neve_blog_archive_layout', 'grid' ); } /** * Render title. * * @return string */ private function get_title() { $markup = ''; $markup .= '

'; $markup .= ''; $markup .= get_the_title(); $markup .= ''; $markup .= '

'; return $markup; } /** * Render meta. * * @return string */ private function get_meta() { $default_meta_order = json_encode( array( 'author', 'date', 'comments', ) ); $meta_order = get_theme_mod( 'neve_post_meta_ordering', $default_meta_order ); $meta_order = json_decode( $meta_order ); ob_start(); do_action( 'neve_post_meta_archive', $meta_order ); $meta = ob_get_clean(); return $meta; } /** * Render excerpt. * * @return string */ private function get_excerpt() { ob_start(); do_action( 'neve_excerpt_archive', 'index' ); $excerpt = ob_get_clean(); return $excerpt; } /** * Get grid columns class. * * @return string */ private function get_grid_columns_class() { $column_numbers = get_theme_mod( 'neve_grid_layout', 1 ); if ( $column_numbers === 0 ) { $column_numbers = 1; } return 'col-sm-' . ( 12 / absint( $column_numbers ) ); } /** * Change link excerpt more. * * @param string $moretag read more tag. * * @return string */ public function link_excerpt_more( $moretag ) { $new_moretag = '… '; if ( isset( $moretag ) && ( $moretag !== ' […]' ) ) { $new_moretag = ''; } $read_more_args = apply_filters( 'neve_read_more_args', array( 'text' => esc_html__( 'Read More', 'neve' ) . ' »', 'classes' => '', ) ); $markup = ''; $markup .= ''; if ( ! empty( $read_more_args['classes'] ) ) { $markup = '
' . $markup . '
'; } $new_moretag .= $markup; return $new_moretag; } }