예제 #1
0
 function ishyoboy_shortcode_recent_posts($atts, $content = null)
 {
     global $ish_options;
     $posts_per_page = get_option('posts_per_page');
     $sc_atts = shortcode_atts(array('id' => '', 'css_class' => '', 'style' => '', 'tooltip' => '', 'tooltip_color' => '', 'align' => '', 'category' => '', 'order' => 'DESC', 'columns' => '4', 'count' => '4', 'show_title_icon' => 'no', 'show_media' => 'yes', 'show_date' => 'yes', 'show_categories' => 'yes', 'show_read_more' => 'yes', 'show_author' => 'no', 'show_tags' => 'no', 'show_comments' => 'no', 'slideshow' => 'no', 'autoslide' => '', 'animation' => '', 'interval' => '', 'navigation' => '', 'skip' => '', 'order_by' => '', 'show_excerpt' => 'yes', 'post_format' => '', 'post_ids' => '', 'post_tags' => ''), $atts);
     $return = '';
     // Default type of connecting multiple taxonomy "filters". Do not change this!
     $tax_query = array('relation' => 'AND');
     // Filter by category
     if (isset($sc_atts['category']) && '' != $sc_atts['category']) {
         // Display items from a chosen category
         $cats = explode(',', $sc_atts['category']);
         $cat_ids = array();
         $neg_cat_ids = array();
         foreach ($cats as $cat_slug) {
             $cat_slug = trim($cat_slug);
             if ('-' == $cat_slug[0]) {
                 // Negative categories = exclude those
                 $cat = get_term_by('slug', $cat_slug, 'category');
                 if ($cat) {
                     $neg_cat_ids[] = $cat->term_id;
                 }
             } else {
                 // Positive categories
                 $cat = get_term_by('slug', $cat_slug, 'category');
                 if ($cat) {
                     $cat_ids[] = $cat->term_id;
                 }
             }
         }
         if (count($cat_ids) > 0 || count($neg_cat_ids) > 0) {
             if (count($cat_ids) > 0) {
                 $tax_query[] = array('taxonomy' => 'category', 'field' => 'id', 'terms' => $cat_ids);
             }
             if (count($neg_cat_ids) > 0) {
                 $tax_query[] = array('taxonomy' => 'category', 'field' => 'id', 'terms' => $neg_cat_ids, 'operator' => 'NOT IN');
             }
         } else {
             $tax_query[] = array('taxonomy' => 'category', 'field' => 'slug', 'terms' => $cats);
         }
     } else {
         // Display items from all categories
         //$tax_query = array();
     }
     // Filter by post format
     if (isset($sc_atts['post_format']) && '' != $sc_atts['post_format']) {
         // Display items from a chosen category
         if ('standard' == $sc_atts['post_format']) {
             $sc_atts['post_format'] = '-quote,-video,-audio,-link,-aside,-image,-chat,-gallery,-status';
         }
         $cats = explode(',', $sc_atts['post_format']);
         $cat_ids = array();
         $neg_cat_ids = array();
         foreach ($cats as $cat_slug) {
             $cat_slug = trim($cat_slug);
             if ('-' == $cat_slug[0]) {
                 // Negative categories = exclude those
                 $cat = get_term_by('slug', 'post-format-' . $cat_slug, 'post_format');
                 if ($cat) {
                     $neg_cat_ids[] = $cat->term_id;
                 }
             } else {
                 // Positive categories
                 $cat = get_term_by('slug', 'post-format-' . $cat_slug, 'post_format');
                 if ($cat) {
                     $cat_ids[] = $cat->term_id;
                 }
             }
         }
         if (count($cat_ids) > 0 || count($neg_cat_ids) > 0) {
             if (count($cat_ids) > 0) {
                 $tax_query[] = array('taxonomy' => 'post_format', 'field' => 'id', 'terms' => $cat_ids);
             }
             if (count($neg_cat_ids) > 0) {
                 $tax_query[] = array('taxonomy' => 'post_format', 'field' => 'id', 'terms' => $neg_cat_ids, 'operator' => 'NOT IN');
             }
         } else {
             $tax_query[] = array('taxonomy' => 'post_format', 'field' => 'slug', 'terms' => $cats);
         }
     } else {
         // Display items from all categories
         //$tax_query = array();
     }
     // Filter by tags
     if (isset($sc_atts['post_tags']) && '' != $sc_atts['post_tags']) {
         // Display items from a chosen category
         $cats = explode(',', $sc_atts['post_tags']);
         $cat_ids = array();
         $neg_cat_ids = array();
         foreach ($cats as $cat_slug) {
             $cat_slug = trim($cat_slug);
             if ('-' == $cat_slug[0]) {
                 // Negative categories = exclude those
                 $cat = get_term_by('slug', $cat_slug, 'post_tag');
                 if ($cat) {
                     $neg_cat_ids[] = $cat->term_id;
                 }
             } else {
                 // Positive categories
                 $cat = get_term_by('slug', $cat_slug, 'post_tag');
                 if ($cat) {
                     $cat_ids[] = $cat->term_id;
                 }
             }
         }
         if (count($cat_ids) > 0 || count($neg_cat_ids) > 0) {
             if (count($cat_ids) > 0) {
                 $tax_query[] = array('taxonomy' => 'post_tag', 'field' => 'id', 'terms' => $cat_ids);
             }
             if (count($neg_cat_ids) > 0) {
                 $tax_query[] = array('taxonomy' => 'post_tag', 'field' => 'id', 'terms' => $neg_cat_ids, 'operator' => 'NOT IN');
             }
         } else {
             $tax_query[] = array('taxonomy' => 'post_tag', 'field' => 'slug', 'terms' => $cats);
         }
     } else {
         // Display items from all categories
         //$tax_query = array();
     }
     $positive_ids = array();
     $negative_ids = array();
     // Filter by Post IDs
     if (isset($sc_atts['post_ids']) && '' != $sc_atts['post_ids']) {
         // Display items from a chosen category
         $cats = explode(',', $sc_atts['post_ids']);
         foreach ($cats as $cat_slug) {
             $cat_slug = trim($cat_slug);
             if ('-' == $cat_slug[0]) {
                 // Negative ids = exclude those
                 $negative_ids[] = $cat_slug;
                 //substr( $cat_slug, 1);
             } else {
                 // Positive ids
                 $positive_ids[] = $cat_slug;
             }
         }
     }
     $thumb_size = 'theme-large';
     if (is_numeric($sc_atts['columns'])) {
         switch ($sc_atts['columns']) {
             case '4':
                 $grid = 'grid3';
                 $thumb_size = 'theme-fourth';
                 break;
             case '3':
                 $grid = 'grid4';
                 $thumb_size = 'theme-third';
                 break;
             case '2':
                 $grid = 'grid6';
                 $thumb_size = 'theme-half';
                 break;
             case '1':
                 $grid = 'grid12';
                 $thumb_size = 'theme-full';
                 break;
             case '5':
                 $grid = 'grid2';
                 $thumb_size = 'theme-fourth';
                 break;
             case '6':
                 $grid = 'grid2';
                 $thumb_size = 'theme-fourth';
                 break;
             default:
                 $grid = 'grid3';
                 $thumb_size = 'theme-fourth';
         }
     }
     $order = 'ASC' == strtoupper($sc_atts['order']) ? 'ASC' : 'DESC';
     // ASC OR DESC
     $orderby = isset($sc_atts['order_by']) && '' != $sc_atts['order_by'] ? $sc_atts['order_by'] : 'date';
     $offset = isset($sc_atts['skip']) && is_numeric($sc_atts['skip']) ? $sc_atts['skip'] : '0';
     // Get all Portfolio posts
     $wpbp = new WP_Query(array('post_type' => 'post', 'posts_per_page' => $sc_atts['count'], 'order' => $order, 'orderby' => $orderby, 'offset' => $offset, 'post__in' => $positive_ids, 'post__not_in' => $negative_ids, 'post_status' => 'publish', 'tax_query' => $tax_query));
     if ($wpbp->have_posts()) {
         if ('yes' == $sc_atts['slideshow']) {
             wp_enqueue_script('imagesloaded');
             wp_enqueue_script('flexslider');
             //wp_enqueue_script( 'isotope' );
             $return .= '[slidable';
             $return .= '' != $sc_atts['id'] ? ' id="' . esc_attr($sc_atts['id']) . '"' : '';
             $return .= '' != $sc_atts['css_class'] ? ' class="recent_posts recent_posts_slideshow ' . esc_attr($sc_atts['css_class']) . '"' : ' class="recent_posts recent_posts_slideshow"';
             $return .= '' != $sc_atts['style'] ? ' style="' . esc_attr($sc_atts['style']) . '"' : '';
             $return .= '' != $sc_atts['tooltip'] ? ' tooltip="' . esc_attr($sc_atts['tooltip']) . '"' : '';
             $return .= '' != $sc_atts['tooltip_color'] ? ' tooltip_color="' . esc_attr($sc_atts['tooltip_color']) . '"' : '';
             $return .= '' != $sc_atts['align'] ? ' align="' . esc_attr($sc_atts['align']) . '"' : '';
             $return .= '' != $sc_atts['autoslide'] ? ' autoslide="' . esc_attr($sc_atts['autoslide']) . '"' : '';
             $return .= '' != $sc_atts['animation'] ? ' animation="' . esc_attr($sc_atts['animation']) . '"' : '';
             $return .= '' != $sc_atts['interval'] ? ' interval="' . esc_attr($sc_atts['interval']) . '"' : '';
             $return .= '' != $sc_atts['navigation'] ? ' navigation="' . esc_attr($sc_atts['navigation']) . '"' : '';
             //$return .= ('' != $sc_atts['sameheight']) ? ' sameheight="' . esc_attr($sc_atts['sameheight']) .'"' : '' ;
             $return .= ']';
             $return .= '[slide class="recent_posts_slide"]';
         } else {
             $return .= '<div class="row">';
         }
         $count = 0;
         while ($wpbp->have_posts()) {
             $wpbp->the_post();
             $count++;
             $terms = get_the_terms(get_the_ID(), 'category');
             $return .= '<div class="recent_posts_post ' . $grid . '">';
             $format = get_post_format();
             switch ($format) {
                 case 'video':
                     $post_icon = 'icon-video';
                     break;
                 case 'audio':
                     $post_icon = 'icon-music-1';
                     break;
                 case 'link':
                     $post_icon = 'icon-link';
                     break;
                 case 'quote':
                     $post_icon = 'icon-quote';
                     break;
                 default:
                     $post_icon = 'icon-align-center';
             }
             $return .= '<div class="recent_posts_post_content">';
             // Blog title
             if ('yes' == $sc_atts['show_title_icon']) {
                 $return .= '<h3 class="' . $post_icon . ' color2">' . '<a href="' . get_permalink() . '">' . get_the_title() . '</a>' . '</h3>';
             } else {
                 $return .= '<h3 class="color2">' . '<a href="' . get_permalink() . '">' . get_the_title() . '</a>' . '</h3>';
             }
             // Blog post media
             switch ($format) {
                 case 'video':
                     if ('yes' == $sc_atts['show_media']) {
                         ob_start();
                         ishyoboy_the_post_video(get_the_ID());
                         $doc = ob_get_clean();
                         $return .= str_replace(array("\r\n", "\n", "\r"), '', $doc);
                     }
                     break;
                 case 'audio':
                     if ('yes' == $sc_atts['show_media']) {
                         ob_start();
                         ishyoboy_the_post_audio(get_the_ID());
                         $doc = ob_get_clean();
                         $return .= str_replace(array("\r\n", "\n", "\r"), '', $doc);
                     }
                     break;
                 case 'link':
                     if ('yes' == $sc_atts['show_excerpt']) {
                         $return .= '<a href="' . esc_attr(ishyoboy_get_post_format_url()) . '" target="_blank" class="ish-button-big color3 pt-link">' . get_the_content() . '</a>';
                     }
                     break;
                 case 'quote':
                     if ('yes' == $sc_atts['show_excerpt']) {
                         ob_start();
                         $quote = ishyoboy_get_post_format_quote();
                         if ('' != $quote) {
                             echo '<blockquote class="color2 post-quote-content">';
                             echo $quote;
                             // Get Quote source
                             $quote_source = ishyoboy_get_post_format_quote_source();
                             if ('' != $quote_source) {
                                 // Get Quote URL
                                 $quote_url = ishyoboy_get_post_format_url();
                                 if ('' != $quote_url) {
                                     echo '<cite><a href="', $quote_url, '" target="_blank">', $quote_source, '</a></cite>';
                                 } else {
                                     echo '<cite>', $quote_source, '</cite>';
                                 }
                             }
                             echo '</blockquote>';
                         }
                         $return .= ob_get_clean();
                     }
                     break;
                 default:
                     if ('yes' == $sc_atts['show_media']) {
                         if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
                             $return .= '<div class="main-post-image"><a href="' . get_permalink() . '">' . get_the_post_thumbnail(get_the_ID(), $thumb_size) . '</a></div>';
                         }
                     }
             }
             // Excerpt
             if ('yes' == $sc_atts['show_excerpt']) {
                 if ('link' != $format) {
                     $post = get_post();
                     $excerpt = '';
                     $excerpt = ishyoboy_custom_excerpt($post->post_content, 30);
                     if ('' != $excerpt) {
                         $return .= "\n\n" . '<div class="excerpt"><p>' . $excerpt . '</p></div>' . "\n\n";
                     }
                 }
             }
             // Blog post details
             $return .= '<div class="blog-post-details">';
             if ('yes' == $sc_atts['show_date']) {
                 $return .= '<span class="icon-calendar">' . get_the_date() . '</span>';
             }
             if ('yes' == $sc_atts['show_author']) {
                 $return .= '<span class="icon-pencil-1">' . get_the_author() . '</span>';
             }
             if ('yes' == $sc_atts['show_categories']) {
                 if (has_category()) {
                     $return .= '<span class="icon-folder">';
                     if (isset($terms) && '' != $terms) {
                         $i = 0;
                         foreach ($terms as $term) {
                             $i++;
                             $return .= '<a href="' . esc_attr(get_term_link($term)) . '">' . $term->name . '</a>' . " ";
                             if (3 == $i) {
                                 if (count($terms) > $i) {
                                     $return .= '...';
                                 }
                                 break;
                             }
                         }
                     }
                     $return .= '</span>';
                 }
             }
             if ('yes' == $sc_atts['show_tags']) {
                 if (has_tag()) {
                     $terms = get_the_tags();
                     $return .= '<span class="icon-tags">';
                     if (isset($terms) && '' != $terms) {
                         $i = 0;
                         foreach ($terms as $term) {
                             $i++;
                             $return .= '<a href="' . esc_attr(get_term_link($term)) . '">' . $term->name . '</a>' . " ";
                             if (3 == $i) {
                                 if (count($terms) > $i) {
                                     $return .= '...';
                                 }
                                 break;
                             }
                         }
                     }
                     $return .= '</span>';
                 }
             }
             if ('yes' == $sc_atts['show_comments']) {
                 $num_comments = get_comments_number();
                 // get_comments_number returns only a numeric value
                 if (comments_open()) {
                     $return .= '<span class="icon-chat-1">';
                     if ($num_comments == 0) {
                         //$comments = __('0 comments', 'ishyoboy');
                         $comments = 0;
                     } elseif ($num_comments > 1) {
                         //$comments = $num_comments . __(' comments', 'ishyoboy');
                         $comments = $num_comments;
                     } else {
                         //$comments = __('1 comment', 'ishyoboy');
                         $comments = 1;
                     }
                     $return .= '<a href="' . get_comments_link() . '">' . $comments . '</a>';
                     $return .= '</a></span>';
                 } else {
                     //$return .=   __('Comments are off for this post.');
                 }
             }
             $return .= '</div>';
             // Read more link
             if ('yes' == $sc_atts['show_read_more']) {
                 $return .= '<a class="color1 right" href="' . get_permalink() . '">' . __('Read more', 'ishyoboy') . '</a>';
             }
             $return .= '</div></div>';
             if ($count % $sc_atts['columns'] == 0 && $count != $sc_atts['count'] && $count != $wpbp->post_count) {
                 if ('yes' == $sc_atts['slideshow']) {
                     $return .= '[/slide]
                 [slide class="recent_posts_slide"]';
                 } else {
                     $return .= '</div><div class="space"></div><div class="row">';
                 }
             }
         }
         // Endwhile
         if ('yes' == $sc_atts['slideshow']) {
             $return .= '[/slide][/slidable]';
         } else {
             $return .= '</div>';
         }
     }
     wp_reset_query();
     return do_shortcode($return);
 }
예제 #2
0
파일: search.php 프로젝트: baden03/access48
        ?>
                                <?php 
        if (has_tag()) {
            ?>
                                    <span class="icon-tags"><?php 
            _e('and', 'ishyoboy');
            ?>
 <?php 
            the_tags(null, ', ');
            ?>
</span>
                                <?php 
        }
        ?>
                                <?php 
        echo ishyoboy_custom_excerpt(get_the_content(), 40, get_search_query());
        ?>
                            </div>
                        </div>
                        <div class="divider"></div>

                    <?php 
    }
    echo '</div>';
    global $wp_query;
    if (empty($paged) || 0 == $paged) {
        $paged = 1;
    }
    $pg = ishyoboy_get_pagination('', 3, $wp_query->max_num_pages, $paged);
    if ('' != $pg) {
        echo $pg, '<div class="space"></div>';