2012-10-11 33 views
2

我一直在閱讀很多如何在WordPress中定製摘錄功能,但我不知道如何繼續這個。定製主題摘錄

我正在使用的主題已經有4個預先定製的摘錄功能,我將在這裏展示的主題最接近我的期望,但仍需要改進。

我的問題是如何停止從我的內容中刪除HTML格式(換行符,段落,字體變體等)?

add_shortcode('display_news_s5', 'be_display_posts_shortcode5'); 
function be_display_posts_shortcode5($atts) { 

// Pull in shortcode attributes and set defaults 
extract(shortcode_atts(array(
    'post_type' => 'post', 
    'post_parent' => false, 
    'id' => false, 
    'tag' => '', 
    'category' => '', 
    'offset' => 0, 
    'posts_per_page' => '1', 
    'order' => 'DESC', 
    'orderby' => 'date', 
    'include_date' => false, 
    'include_excerpt' => false, 
    'excerpt_l' => 8, 
    'taxonomy' => false, 
    'tax_term' => true, 
    'tax_operator' => 'IN' 
), $atts)); 

// Set up initial query for post 
$args = array(
    'post_type' => explode(',', $post_type), 
    'tag' => $tag, 
    'category_name' => $category, 
    'p' => $id, 
    'posts_per_page' => $posts_per_page, 
    'order' => $order, 
    'orderby' => $orderby, 
    'offset' => $offset 
); 



// If Post IDs 
if($id) { 
    $posts_in = explode(',', $id); 
    $args['post__in'] = $posts_in; 
} 


// If taxonomy attributes, create a taxonomy query 
if (!empty($taxonomy) && !empty($tax_term)) { 

    // Term string to array 
    $tax_term = explode(', ', $tax_term); 

    // Validate operator 
    if(!in_array($tax_operator, array('IN', 'NOT IN', 'AND'))) 
     $tax_operator = 'IN'; 

    $tax_args = array(
     'tax_query' => array(
      array(
       'taxonomy' => $taxonomy, 
       'field' => 'slug', 
       'terms' => $tax_term, 
       'operator' => $tax_operator 
      ) 
     ) 
    ); 
    $args = array_merge($args, $tax_args); 
} 

// If post parent attribute, set up parent 
if($post_parent) { 
    if('current' == $post_parent) { 
     global $post; 
     $post_parent = $post->ID; 
    } 
    $args['post_parent'] = $post_parent; 
} 



$listing = new WP_Query(apply_filters('display_posts_shortcode_args', $args, $atts)); 
$count = 0; 
if (!$listing->have_posts()) 
    return apply_filters ('display_posts_shortcode_no_results', false); 

$inner = ''; 
while ($listing->have_posts()): $listing->the_post(); global $post; 
$count++; 

if($count == 1){ 
    $style = ' news-main-post'; 
} else { 
    $style = ' news-list-posts'; 
} 

    $title = '<div class="news-listing-title"><a class="title" href="'. get_permalink() .'">'. get_the_title() .'</a></div>'; 


    if ($include_date == 'true') $date = ' <div class="news-listing-meta"><span class="news-listing-date">'. get_the_date() . '</span><span class="news-listing-comment"><a href="'. get_comments_link() .'">('. get_comments_number() .')</a></span></div>'; 
    else $date = ''; 

    if ($include_excerpt == 'true') $excerpt = '<span>' .excerpt($excerpt_l) . '</span>'; 
    else $excerpt = ''; 


    $output = '<div class="news-listing' . $style . '"><div class="news-listing-item">'. $title . $excerpt . $date . '</div></div>'; 

    $inner .= apply_filters('display_posts_shortcode_output', $output, $atts, $title, $excerpt, $date); 

endwhile; wp_reset_query(); 

$open = apply_filters('display_posts_shortcode_wrapper_open', '<div class="news-listing-wrapper-s3">'); 
$close = apply_filters('display_posts_shortcode_wrapper_close', '<div class="clear"></div></div>'); 
$return = $open . $inner . $close; 

return $return; 
}  

回答

0

看看這裏:LINK看起來像它做你想做的事情。

+0

是的,我也發現了這篇文章,但我也發現通過對現有主題代碼進行實驗來解決問題更簡單。 無論如何感謝;) – bojan