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;
}    
4

1 回答 1

0

看看这里:LINK看起来像是在做你想做的事。

于 2012-10-12T19:45:06.353 回答