开发者

Wordpress excerpt - image and text

This is the mockup I have:

http://img697.imageshack.us/img697/3172/featuresb.jpg

Each section will be an excerpt of a post that has a certain tag.

Is there any way of do开发者_JAVA技巧ing this so a client doesnt have to touch and tags or code like that?


You could filter the content with your own function.

Instead of using <?php the_content() ?> its better to use this: <?php your_function(get_the_content()) ?>

The function can be put on functions.php and you are free to code.


You can use the_content filter like so,

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
}

The above code checks if the post has excerpt, if it has excerpt it returns excerpt else returns first 55 words (default length for excerpt).


use this code for limit the post content.

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


Put this in your themes functions.php file:

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

then add this this in your loop:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜