コード例 #1
0
 function sf_post_related_articles()
 {
     $related_articles_class = apply_filters('sf_post_related_articles_wrap_class', 'container');
     $related_articles_display_type = apply_filters('sf_related_articles_display_type', 'bold');
     $related_articles_excerpt_length = apply_filters('sf_related_articles_excerpt_length', 20);
     $list_class = 'posts-type-' . $related_articles_display_type;
     if ($related_articles_display_type == "bold") {
         $list_class .= ' no-gutters';
     } else {
         $list_class .= ' row';
     }
     global $post;
     $args = array();
     $tags = wp_get_post_tags($post->ID);
     $categories = get_the_category($post->ID);
     if (!empty($tags)) {
         $tag_ids = array();
         foreach ($tags as $individual_tag) {
             $tag_ids[] = $individual_tag->term_id;
         }
         $args = array('tag__in' => $tag_ids, 'post__not_in' => array($post->ID), 'posts_per_page' => 4, 'ignore_sticky_posts' => 1);
     } else {
         if (!empty($categories)) {
             $category_ids = array();
             foreach ($categories as $individual_category) {
                 $category_ids[] = $individual_category->term_id;
             }
             $args = array('category__in' => $category_ids, 'post__not_in' => array($post->ID), 'posts_per_page' => apply_filters('sf_related_posts_count', 4), 'orderby' => 'rand');
         }
     }
     $related_posts_query = new WP_Query($args);
     if ($related_posts_query->have_posts()) {
         echo '<div class="related-wrap">';
         echo '<div class="related-articles ' . $related_articles_class . '">';
         echo '<div class="title-wrap"><h3 class="spb-heading"><span>' . __("Related Articles", "swiftframework") . '</span></h3></div>';
         echo '<div class="related-items recent-posts ' . $list_class . ' clearfix">';
         while ($related_posts_query->have_posts()) {
             $related_posts_query->the_post();
             echo sf_get_recent_post_item($post, $related_articles_display_type, $related_articles_excerpt_length, 'col-sm-3');
         }
         echo '</div>';
         echo '</div>';
         echo '</div>';
     }
     wp_reset_query();
 }
コード例 #2
0
ファイル: recent-posts.php プロジェクト: arobbins/spellestate
 protected function content($atts, $content = null)
 {
     global $sf_options;
     $title = $width = $wrap_class = $title_class = $excerpt_length = $item_class = $offset = $el_class = $output = $items = $el_position = '';
     extract(shortcode_atts(array('title' => '', 'item_columns' => '3', 'display_type' => 'standard', 'carousel' => 'no', "item_count" => '4', "category" => '', "offset" => 0, "posts_order" => 'ASC', "excerpt_length" => '20', 'fullwidth' => 'no', 'gutters' => 'yes', 'button_enabled' => 'no', 'pagination' => 'no', 'post_type' => 'post', 'el_position' => '', 'width' => '1/1', 'el_class' => ''), $atts));
     $view_all_icon = apply_filters('sf_view_all_icon', '<i class="ss-layergroup"></i>');
     $pagination_view_icon = apply_filters('sf_pagination_view_icon', '<i class="sf-icon-quickview"></i>');
     /* CATEGORY SLUG MODIFICATION
        ================================================== */
     if ($category == "All") {
         $category = "all";
     }
     if ($category == "all") {
         $category = '';
     }
     $category_slug = str_replace('_', '-', $category);
     /* SIDEBAR CONFIG
        ================================================== */
     global $sf_sidebar_config;
     $sidebars = '';
     if ($sf_sidebar_config == "left-sidebar" || $sf_sidebar_config == "right-sidebar") {
         $sidebars = 'one-sidebar';
     } else {
         if ($sf_sidebar_config == "both-sidebars") {
             $sidebars = 'both-sidebars';
         } else {
             $sidebars = 'no-sidebars';
         }
     }
     /* BLOG QUERY SETUP
        ================================================== */
     global $post, $wp_query;
     if (get_query_var('paged')) {
         $paged = get_query_var('paged');
     } elseif (get_query_var('page')) {
         $paged = get_query_var('page');
     } else {
         $paged = 1;
     }
     $recent_post_args = array('post_type' => $post_type, 'post_status' => 'publish', 'category_name' => $category_slug, 'posts_per_page' => $item_count, 'offset' => $offset, 'order' => $posts_order);
     $recent_posts = new WP_Query($recent_post_args);
     $count = 0;
     $image_width = 270;
     $image_height = 270;
     if ($item_columns == "1") {
         $image_width = 720;
         $image_height = 720;
         $item_class = 'col-sm-12';
     } else {
         if ($item_columns == "2") {
             $image_width = 540;
             $image_height = 540;
             $item_class = 'col-sm-6';
         } else {
             if ($item_columns == "3") {
                 $image_width = 360;
                 $image_height = 360;
                 $item_class = 'col-sm-4';
             } else {
                 if ($item_columns == "5") {
                     $image_width = 360;
                     $image_height = 360;
                     $item_class = 'col-sm-sf-5';
                 } else {
                     $item_class = 'col-sm-3';
                 }
             }
         }
     }
     if ($display_type == "standard-row") {
         $item_class = 'col-sm-12';
     }
     $list_class = 'posts-type-' . $display_type;
     if ($display_type == "standard" || $display_type == "standard-row" && $carousel == "no") {
         $list_class .= ' row';
     }
     if ($gutters == "no") {
         $list_class .= ' no-gutters';
     }
     if ($display_type == "showcase") {
         $carousel = "yes";
         $list_class .= ' staged-carousel';
         if ($pagination == "yes") {
             $wrap_class = "has-pagination ";
         }
         $title_class = "center-title";
         if ($sidebars == "no-sidebars") {
             $fullwidth = "yes";
         }
     }
     if ($display_type == "list") {
         $carousel = "no";
     }
     if ($carousel == "yes") {
         global $sf_carouselID;
         if ($sf_carouselID == "") {
             $sf_carouselID = 1;
         } else {
             $sf_carouselID++;
         }
         $item_class = 'carousel-item';
     }
     if ($display_type == "bold") {
         $item_class .= ' vr-standard';
     }
     if ($carousel == "yes") {
         $items .= '<div class="posts-carousel carousel-wrap">';
         if ($display_type == "showcase") {
             $items .= spb_carousel_arrows(true);
         }
         $items .= '<div id="carousel-' . $sf_carouselID . '" class="recent-posts carousel-items ' . $list_class . ' clearfix" data-columns="' . $item_columns . '" data-auto="false" data-pagination="' . $pagination . '">';
     } else {
         $items .= '<div class="recent-posts ' . $list_class . ' clearfix">';
     }
     while ($recent_posts->have_posts()) {
         $recent_posts->the_post();
         $count++;
         if ($count > $item_count) {
             break;
         }
         $items .= sf_get_recent_post_item($post, $display_type, $excerpt_length, $item_class);
     }
     wp_reset_postdata();
     if ($carousel == "yes") {
         $items .= '</div></div>';
     } else {
         $items .= '</div>';
     }
     $el_class = $this->getExtraClass($el_class);
     $width = spb_translateColumnWidthToSpan($width);
     $has_button = false;
     $page_button = $title_wrap_class = $view_all = "";
     $blog_page = __($sf_options['blog_page'], 'swift-framework-plugin');
     if ($category_slug != "") {
         $has_button = true;
         $category_id = get_cat_ID($category_slug);
         $category_link = get_category_link($category_id);
         $page_button = '<a class="sf-button medium white sf-icon-stroke " href="' . esc_url($category_link) . '">' . $view_all_icon . '<span class="text">' . __("VIEW ALL ARTICLES", 'swift-framework-plugin') . '</span></a>';
         $view_all = '<a class="view-all hidden" href="' . esc_url($category_link) . '">' . $pagination_view_icon . '</a>';
     } else {
         if ($blog_page != "") {
             $has_button = true;
             $page_button = '<a class="sf-button medium white sf-icon-stroke " href="' . get_permalink($blog_page) . '">' . $view_all_icon . '<span class="text">' . __("VIEW ALL ARTICLES", 'swift-framework-plugin') . '</span></a>';
             $view_all = '<a class="view-all hidden" href="' . get_permalink($blog_page) . '">' . $pagination_view_icon . '</a>';
         }
     }
     if ($has_button && $button_enabled == "yes") {
         $title_wrap_class .= 'has-button ';
     }
     if ($fullwidth == "yes" && $sidebars == "no-sidebars") {
         $title_wrap_class .= 'container ';
     }
     $output .= "\n\t" . '<div class="spb_recent_posts_widget spb_content_element ' . $wrap_class . $width . $el_class . '">';
     if ($display_type == "showcase" && $pagination == "yes") {
         $output .= "\n\t\t" . $view_all;
     }
     $output .= "\n\t\t" . '<div class="spb-asset-content">';
     if (spb_get_theme_name() == "joyn") {
         if ($title != '') {
             $output .= "\n\t\t" . '<div class="title-wrap clearfix ' . $title_wrap_class . '">';
             $output .= '<h3 class="spb-heading ' . $title_class . '"><span>' . $title . '</span></h3>';
             $output .= '</div>';
         }
     } else {
         $output .= "\n\t\t" . '<div class="title-wrap clearfix ' . $title_wrap_class . '">';
         if ($title != '') {
             $output .= '<h3 class="spb-heading ' . $title_class . '"><span>' . $title . '</span></h3>';
         }
         if ($carousel == "yes" && $display_type != "showcase") {
             $output .= spb_carousel_arrows();
         }
         if ($has_button && $button_enabled == "yes") {
             $output .= $page_button;
         }
         $output .= '</div>';
     }
     $output .= "\n\t\t\t" . $items;
     $output .= "\n\t\t" . '</div>';
     $output .= "\n\t" . '</div> ' . $this->endBlockComment($width);
     if ($fullwidth == "yes" && $sidebars == "no-sidebars") {
         $output = $this->startRow($el_position, '', true) . $output . $this->endRow($el_position, '', true);
     } else {
         $output = $this->startRow($el_position) . $output . $this->endRow($el_position);
     }
     global $sf_include_isotope, $sf_include_carousel;
     $sf_include_isotope = true;
     if ($carousel == "yes") {
         $sf_include_carousel = true;
     }
     return $output;
 }