Пример #1
0
function searchDescription($term, $description, $substring_count = 100)
{
    $search_text = array_map('trim', explode(' ', trim($term)));
    $length = strlen($description);
    $firstPosition = FALSE;
    if ($substring_count < $length) {
        foreach ($search_text as $txt) {
            if (FALSE !== stripos($description, trim($txt))) {
                if (FALSE === $firstPosition || $firstPosition > stripos($description, trim($txt))) {
                    $firstPosition = stripos($description, trim($txt));
                }
            }
        }
    } else {
        $firstPosition = 0;
    }
    if (0 != $firstPosition) {
        $remaining = $length - $firstPosition;
        if ($remaining < $substring_count) {
            $firstPosition = $firstPosition - ($substring_count / 2 - strlen($term));
        }
    }
    return (FALSE !== $firstPosition && 0 < $firstPosition ? '...' : '') . sub_string(substr($description, $firstPosition, $length), $substring_count);
}
Пример #2
0
 function newsroom($atts, $content = null)
 {
     extract(shortcode_atts(array('column' => 3, 'is_home' => "no"), $atts));
     ob_start();
     $result = '';
     $column_lg = 12 / (int) $column;
     $column_lg = "col-lg-" . $column_lg;
     $now = isset($_REQUEST['now']) ? $_REQUEST['now'] : 1;
     $query = array('post_type' => 'post', 'posts_per_page' => 6, 'orderby' => 'ID', 'order' => "DESC", 'paged' => $now, 'ignore_sticky_posts' => 0);
     if ($is_home == 'yes') {
         $query['post__in'] = get_option('sticky_posts');
         $query['ignore_sticky_posts'] = 1;
     }
     $the_query = new WP_Query($query);
     if ($the_query->have_posts()) {
         echo '<div class="news-room">';
         while ($the_query->have_posts()) {
             $the_query->the_post();
             echo '<div class="col-sm-12 ' . $column_lg . ' column">';
             echo '<header><h4><a href="' . get_permalink() . '">' . get_the_title() . '</a></h4></header>';
             if (has_post_thumbnail()) {
                 $thumbnails = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'lead-image');
                 $url = $thumbnails[0];
                 $content_summary = '<a href="' . get_permalink() . '"><img src="' . $url . '" style="width:100%;" /></a>';
             } else {
                 $content_summary = sub_string(strip_tags(get_the_content()), 0, 170) . ' <a href="' . get_permalink() . '">more</a>';
             }
             echo '<p>' . $content_summary . '</p>';
             echo '</div>';
         }
         echo '</div>';
     }
     //printr($the_query);
     if ($the_query->max_num_pages > 1) {
         echo '<div id="nav-below" class="navigation">';
         if ($now > 1) {
             echo '<div class="nav-previous"><a href="' . get_home_url() . '/newsroom?now=' . ($now - 1) . '"><i class="fa fa-chevron-left"></i> PREV</a></div>';
         }
         if ($the_query->max_num_pages > $now) {
             echo '<div class="nav-next"><a href="' . get_home_url() . '/newsroom?now=' . ($now + 1) . '">NEXT <i class="fa fa-chevron-right"></i></a></div>';
         }
         echo '</div>';
     }
     $result = ob_get_clean();
     return $result;
 }