function widget($args, $instance) { extract($args); $instance = wp_parse_args((array) $instance, self::$widget_defaults); /* Our variables from the widget settings. */ $title = apply_filters('widget_title', $instance['title']); $terms = empty($instance['cats']) ? array(0) : (array) $instance['cats']; $html = ''; if ($terms) { $attachments_data = presscore_get_related_posts(array('exclude_current' => false, 'cats' => $terms, 'select' => $instance['select'], 'post_type' => 'post', 'taxonomy' => 'category', 'field' => 'term_id', 'args' => array('posts_per_page' => $instance['show'], 'orderby' => $instance['orderby'], 'order' => $instance['order']))); $list_args = array('show_images' => (bool) $instance['thumbnails'], 'image_dimensions' => $instance['images_dimensions']); $posts_list = presscore_get_posts_small_list($attachments_data, $list_args); if ($posts_list) { foreach ($posts_list as $p) { $html .= sprintf('<li>%s</li>', $p); } $html = '<ul class="recent-posts' . ($instance['round_images'] ? ' round-images' : '') . '">' . $html . '</ul>'; } } echo $before_widget; // title if ($title) { echo $before_title . $title . $after_title; } echo $html; echo $after_widget; }
public function shortcode($atts, $content = null) { extract(shortcode_atts(array('featured_images' => 'true', 'round_images' => '', 'images_width' => 60, 'images_height' => 60, 'category' => '', 'order' => '', 'orderby' => '', 'number' => 6, 'columns' => 1), $atts)); // sanitize attributes $featured_images = apply_filters('dt_sanitize_flag', $featured_images); $round_images = apply_filters('dt_sanitize_flag', $round_images); $order = apply_filters('dt_sanitize_order', $order); $orderby = apply_filters('dt_sanitize_orderby', $orderby); $number = apply_filters('dt_sanitize_posts_per_page', $number); $columns = absint($columns); $images_width = absint($images_width); $images_height = absint($images_height); if ($category) { $category = explode(',', $category); $category = array_map('trim', $category); } $related_posts_args = array('exclude_current' => false, 'post_type' => 'post', 'taxonomy' => 'category', 'field' => 'slug', 'args' => array('posts_per_page' => $number, 'orderby' => $orderby, 'order' => $order)); if (!empty($category)) { $related_posts_args['cats'] = $category; $related_posts_args['select'] = 'only'; } else { $related_posts_args['select'] = 'all'; } $attachments_data = presscore_get_related_posts($related_posts_args); $list_args = array('show_images' => $featured_images, 'image_dimensions' => array('w' => $images_width, 'h' => $images_height)); $posts_list = presscore_get_posts_small_list($attachments_data, $list_args); switch ($columns) { case 2: $column_class = 'wf-1-2'; break; case 3: $column_class = 'wf-1-3'; break; case 1: default: $column_class = 'wf-1'; } $output = ''; if ($posts_list) { foreach ($posts_list as $p) { $output .= sprintf('<div class="wf-cell %s"><div class="borders">%s</div></div>', $column_class, $p); } $section_class = 'items-grid wf-container'; if ($featured_images && $round_images) { $section_class .= ' round-images'; } $output = '<section class="' . $section_class . '">' . $output . '</section>'; } if (function_exists('vc_is_inline') && vc_is_inline()) { $terms_list = presscore_get_terms_list_by_slug(array('slugs' => $category, 'taxonomy' => 'category')); $output = ' <div class="dt_vc-shortcode_dummy dt_vc-mini_blog" style="height: 250px;"> <h5>Mini blog</h4> <p class="text-small"><strong>Display categories:</strong> ' . $terms_list . '</p> </div> '; } return $output; }
public function shortcode($atts, $content = null) { extract(shortcode_atts(array('featured_images' => 'true', 'category' => '', 'order' => '', 'orderby' => '', 'number' => '6', 'columns' => '1'), $atts)); // sanitize attributes $featured_images = in_array($featured_images, array('1', 'true', 'yes')); $order = apply_filters('dt_sanitize_order', $order); $orderby = apply_filters('dt_sanitize_orderby', $orderby); $number = apply_filters('dt_sanitize_posts_per_page', $number); $columns = in_array($columns, array('1', '2', '3')) ? absint($columns) : 1; if ($category) { $category = explode(',', $category); $category = array_map('trim', $category); } $related_posts_args = array('exclude_current' => false, 'post_type' => 'post', 'taxonomy' => 'category', 'field' => 'slug', 'args' => array('posts_per_page' => $number, 'orderby' => $orderby, 'order' => $order)); if (!empty($category)) { $related_posts_args['cats'] = $category; $related_posts_args['select'] = 'only'; } else { $related_posts_args['select'] = 'all'; } $attachments_data = presscore_get_related_posts($related_posts_args); // unset thumbnails if (!$featured_images) { foreach ($attachments_data as $k => $v) { $attachments_data[$k]['full'] = ''; } } $posts_list = presscore_get_posts_small_list($attachments_data); switch ($columns) { case 2: $column_class = 'wf-1-2'; break; case 3: $column_class = 'wf-1-3'; break; default: $column_class = 'wf-1'; } $output = ''; if ($posts_list) { foreach ($posts_list as $p) { $output .= sprintf('<div class="wf-cell %s"><div class="borders">%s</div></div>', $column_class, $p); } $output = '<section class="items-grid wf-container">' . $output . '</section>'; } return $output; }
/** * Display related posts. * */ function presscore_display_related_posts() { if (!of_get_option('general-show_rel_posts', false)) { return ''; } global $post; $html = ''; $terms = array(); switch (get_post_meta($post->ID, '_dt_post_options_related_mode', true)) { case 'custom': $terms = get_post_meta($post->ID, '_dt_post_options_related_categories', true); break; default: $terms = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids')); } if ($terms && !is_wp_error($terms)) { $attachments_data = presscore_get_related_posts(array('cats' => $terms, 'post_type' => 'post', 'taxonomy' => 'category', 'args' => array('posts_per_page' => intval(of_get_option('general-rel_posts_max', 12))))); $posts_list = presscore_get_posts_small_list($attachments_data, array('image_dimensions' => array('w' => 80, 'h' => 60))); if ($posts_list) { $config = Presscore_Config::get_instance(); if ('disabled' != $config->get('sidebar_position')) { $column_class = 'wf-1-2'; } else { $column_class = 'wf-1-3'; } foreach ($posts_list as $p) { $html .= sprintf('<div class="wf-cell %s"><div class="borders">%s</div></div>', $column_class, $p); } $html = '<section class="items-grid wf-container">' . $html . '</section>'; $head_title = esc_html(of_get_option('general-rel_posts_head_title', 'Related posts')); // add title if ($head_title) { $html = '<div class="dt-fancy-separator title-left fancy-posts-title"><div class="dt-fancy-title">' . $head_title . '<span class="separator-holder separator-right"></span></div></div>' . $html; } } } echo (string) apply_filters('presscore_display_related_posts', $html); }
/** * Display related posts. * */ function presscore_display_related_posts() { if (!of_get_option('general-show_rel_posts', false)) { return ''; } global $post; $html = ''; $terms = array(); switch (get_post_meta($post->ID, '_dt_post_options_related_mode', true)) { case 'custom': $terms = get_post_meta($post->ID, '_dt_post_options_related_categories', true); break; default: $terms = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids')); } if ($terms && !is_wp_error($terms)) { $attachments_data = presscore_get_related_posts(array('cats' => $terms, 'post_type' => 'post', 'taxonomy' => 'category', 'args' => array('posts_per_page' => intval(of_get_option('general-rel_posts_max', 12))))); $head_title = esc_html(of_get_option('general-rel_posts_head_title', 'Related posts')); $posts_list = presscore_get_posts_small_list($attachments_data); if ($posts_list) { foreach ($posts_list as $p) { $html .= sprintf('<div class="wf-cell wf-1-3"><div class="borders">%s</div></div>', $p); } $html = '<section class="items-grid wf-container">' . $html . '</section>'; // add title if ($head_title) { $html = '<h2 class="entry-title">' . $head_title . '</h2><div class="gap-10"></div>' . $html; } $html = '<div class="hr-thick"></div><div class="gap-30"></div>' . $html . '<div class="gap-10"></div>'; } } echo (string) apply_filters('presscore_display_related_posts', $html); }