*/ class Advanced_Related_Posts_Under_Posts_GRID_Layout extends Advanced_Related_Posts_Public{ /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; private $html_class_prefix = 'ays-arp-'; private $html_name_prefix = 'ays-arp-'; private $name_prefix = 'arp_'; private $unique_id; private $unique_id_in_class; private $options; protected $layout_name; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of the plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $plugin_version, $options, $layout_name, $layout_options ) { $this->plugin_name = $plugin_name; $this->version = $plugin_version; $this->options = $options; $this->layout_name = $layout_name; $this->unique_id = $layout_options['unique_id']; $this->unique_id_in_class = $layout_options['unique_id_in_class']; } protected function layout_enqueue_styles(){ /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Advanced_Related_Posts_Loader as all of the hooks are defined * in that particular class. * * The Advanced_Related_Posts_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ $id_prefix = $this->plugin_name . '-under-posts-' . $this->layout_name; wp_enqueue_style( $id_prefix, ADVANCED_RELATED_POSTS_PUBLIC_URL . '/css/layouts/advanced-related-posts-under-posts-'. $this->layout_name .'-layout.css', array(), $this->version, 'all' ); } protected function layout_enqueue_scripts(){ /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Advanced_Related_Posts_Loader as all of the hooks are defined * in that particular class. * * The Advanced_Related_Posts_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ $id_prefix = $this->plugin_name . '-under-posts-' . $this->layout_name; } public function ays_arp_generate_layout_content( $posts ){ /*******************************************************************************************************/ $this->layout_enqueue_styles(); $this->layout_enqueue_scripts(); /*******************************************************************************************************/ $content = array(); $content[] = '
'; foreach ( $posts as $post_id => $post ) { $content[] = $this->layout_create_post( $post ); } $content[] = '
'; $content = implode( '', $content ); return $content; } public function layout_create_post( $post ){ /*******************************************************************************************************/ $content = array(); $post_title = $post->post_title; $post_content = $post->post_content; $first_part_of_post_title = ''; $post_excerpt = ''; $post_date = ''; $post_time = ''; $post_author_name = ''; $enable_new_blank = ''; $thumbnail_size = ''; $author_posts_url = ''; $img_alt = ''; /*******************************************************************************************************/ // Image URL $post_image_url = $this->options[ $this->name_prefix . 'under_posts_default_thumbnail' ]; $post_image_url_mobile = $post_image_url; $img_alt_mobile = ''; // Thumbnail size $thumbnail_size = $this->options[ $this->name_prefix . 'under_posts_thumbnail_size' ]; // Check post thumbnail if ( has_post_thumbnail( $post->ID ) ){ $image_arr = get_the_post_thumbnail_url( $post->ID, $thumbnail_size ); $img_id = get_post_thumbnail_id( $post->ID ); $post_image_url = ( isset($image_arr) && ! empty($image_arr) ) ? $image_arr : ''; $post_image_url_mobile = ( isset($image_arr) && ! empty($image_arr) ) ? $image_arr : ''; $img_alt = get_post_meta( $img_id,'_wp_attachment_image_alt', true ); $img_alt_mobile = get_post_meta( $img_id,'_wp_attachment_image_alt', true ); }else { // Get first image if ( $this->options[ $this->name_prefix . 'under_posts_first_image' ] ) { $post_image_url = Advanced_Related_Posts_Data::ays_arp_get_content_first_image( $post->ID, $post_image_url ); $img_alt = Advanced_Related_Posts_Data::ays_arp_get_content_first_image_alt( $post->ID, $post_image_url ); } // Get first image mobile if ( $this->options[ $this->name_prefix . 'under_posts_first_image_mobile' ] ) { $post_image_url_mobile = Advanced_Related_Posts_Data::ays_arp_get_content_first_image( $post->ID, $post_image_url_mobile ); $img_alt_mobile = Advanced_Related_Posts_Data::ays_arp_get_content_first_image_alt( $post->ID, $post_image_url_mobile ); } } // Limit post title length if ( $this->options[ $this->name_prefix . 'under_posts_enable_post_title_length' ] ) { // Limit post title length count $under_posts_post_title_length = $this->options[ $this->name_prefix . 'under_posts_post_title_length' ]; // Limit post title length type $under_posts_post_title_type = $this->options[ $this->name_prefix . 'under_posts_post_title_type' ]; $first_part_of_post_title = Advanced_Related_Posts_Data::ays_arp_get_part_of_string( $post_title , $under_posts_post_title_type, $under_posts_post_title_length); } // Show date if ( $this->options[ $this->name_prefix . 'under_posts_show_date' ] ) { $post_date = get_the_date( '', $post->ID ); $post_time = get_the_modified_time( '', $post->ID ); } // Show Author if ( $this->options[ $this->name_prefix . 'under_posts_show_author' ] ) { $post_author_id = ( isset( $post->post_author ) && $post->post_author != null ) ? absint( sanitize_text_field( $post->post_author ) ) : null; if (! is_null( $post_author_id ) ) { $post_user_data = get_user_by( 'id', $post_author_id ); if ( $post_user_data ) { $post_author_name = ( isset( $post_user_data->display_name ) && sanitize_text_field( $post_user_data->display_name ) != '' ) ? sanitize_text_field( $post_user_data->display_name ) : ''; $post_author_nicename = ( isset( $post_user_data->nicename ) && sanitize_text_field( $post_user_data->nicename ) != '' ) ? sanitize_text_field( $post_user_data->nicename ) : ''; $author_posts_url = get_author_posts_url( $post_author_id , $post_author_nicename ); }else { $post_author_name = ''; } } } // Open links in new window if ( $this->options[ $this->name_prefix . 'under_posts_links_on_new_window' ] ) { $enable_new_blank = 'target="_blank"'; } // Show post excerpt if ( $this->options[ $this->name_prefix . 'under_posts_enable_post_excerpt' ] ) { // Show post excerpt length $under_posts_post_excerpt_length = $this->options[ $this->name_prefix . 'under_posts_post_excerpt_length' ]; // Show post excerpt type $under_posts_post_excerpt_type = $this->options[ $this->name_prefix . 'under_posts_post_excerpt_type' ]; $post_excerpt = Advanced_Related_Posts_Data::ays_arp_get_part_of_string( $post_content , $under_posts_post_excerpt_type, $under_posts_post_excerpt_length); } $content[] = '
'; $content[] = '
'; $content[] = '
'; if( $post_image_url != '' ){ $content[] = ''; $content[] = '' . $img_alt . ''; $content[] = '' . $img_alt_mobile . ''; $content[] = ''; }else { $content[] = '

'. __( 'Post does not have featured image' , 'advanced-related-posts' ) .'

'; } $content[] = '
'; $content[] = '
'; $content[] = '
'; // Post title | + LINK $content[] = '
'; $content[] = '
'; $content[] = ''; if ( $this->options[ $this->name_prefix . 'under_posts_enable_post_title_length' ] ) { $content[] = $first_part_of_post_title; }else{ $content[] = $post_title; } $content[] = ''; $content[] = '
'; $content[] = '
'; // Post excerpt if ( $this->options[ $this->name_prefix . 'under_posts_enable_post_excerpt' ] ) { $content[] = '
'; $content[] = '' . $post_excerpt . ''; $content[] = '
'; } // // Post Date | Post Author // if ( $this->options[ $this->name_prefix . 'under_posts_show_date' ] || $this->options[ $this->name_prefix . 'under_posts_show_author' ] ) { // $content[] = ''; // } $content[] = '
'; $content[] = '
'; // Post Date | Post Author if ( $this->options[ $this->name_prefix . 'under_posts_show_date' ] || $this->options[ $this->name_prefix . 'under_posts_show_author' ] ) { $content[] = ''; } $content[] = '
'; $content[] = '
'; $content = implode( '', $content ); return $content; } public function get_leyout_styles(){ $content = array(); $content[] = ' /* Layout CSS */ #' . $this->html_class_prefix . 'under-posts-container-' . $this->unique_id_in_class . '.' . $this->html_class_prefix . $this->layout_name . '-layout .' . $this->html_class_prefix . 'under-post-date-author-row { } '; $content = implode( '', $content ); return $content; } } ?>