Wordpress摘录 - 图像和文本

时间:2010-03-11 19:02:57

标签: wordpress

这是我的模型:

<德尔> http://img697.imageshack.us/img697/3172/featuresb.jpg

每个部分都是具有特定标签的帖子的摘录。

有没有办法做到这一点,所以客户不必触摸,标记或编码?

4 个答案:

答案 0 :(得分:0)

您可以使用自己的功能过滤内容。

而不是使用<?php the_content() ?>更好地使用它:<?php your_function(get_the_content()) ?>

该函数可以放在functions.php上,你可以自由编码。

答案 1 :(得分:0)

您可以使用the_content过滤器,

add_filter('the_content', 'my_content_filter'); // 
function my_content_filter($content) {
    global $post;
    if($post->post_excerpt == ''){ // check if the post has excerpt
        $content = strip_tags($content);  //strip tags
        $cont_array = explode(' ',$content);
        if(count($cont_array) > 55)  //number of words wanted in excerpt default is 55
        $content = implode(' ',array_slice($cont_array, 0, 55)).'...';
        $content = '<p>'.$content.'</p>';
    }else{
        $content = $post->post_excerpt; //copy excerpt to content
    }
    return $content; //return content
}

上面的代码检查帖子是否有摘录,如果有摘录则返回摘录,否则返回前55个单词(摘录的默认长度)。

答案 2 :(得分:0)

使用此代码限制帖子内容。

<a href="<?php the_permalink(); ?>"><?php substr($post->post_content, 0, 12); ?> ...</a>

答案 3 :(得分:0)

将它放在你的主题functions.php文件中:

function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
    array_pop($excerpt);
    $excerpt = implode(" ",$excerpt).'...';
} else {
    $excerpt = implode(" ",$excerpt);
} 
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}

然后在你的循环中添加这个:

<?php print '<p>'.excerpt(40).'</p>'; ?>