如何在wordpress中显示有限的页面内容

时间:2011-06-03 13:14:39

标签: wordpress

我有代码显示页面的content和“标题”。我想只显示该特定页面内容的150个单词。

这是我的代码

<?php 
$args = array(
   'include' => 1319,
   'post_type' => 'page',
   'post_status' => 'publish'
 );  
$mypages = get_pages($args); 

foreach($mypages as $page)
{   

    $content = $page->post_content;

    $content = apply_filters('the_content', $content);
?>

<div class="page_botheadingtop">
<?php echo $page->post_title ?>
</div>
<div class="page_botheadingmiddle">
<?php echo $page->post_content;  ?>
</div>

<div class="page_botheadingbottom">
<a href="<?php echo get_page_link($page->ID) ?>">Read More..</a>
</div>



<?php
}   

&GT?;

此代码显示标识为1319的所有网页内容。我只想显示150字,请提供建议。

我将非常感谢你 我在等你的回复 感谢

1 个答案:

答案 0 :(得分:1)

使用

<?php
the_excerpt_max_charlength(140);

 function the_excerpt_max_charlength($charlength) {
$excerpt = get_the_excerpt();
$charlength++;

if ( mb_strlen( $excerpt ) > $charlength ) {
    $subex = mb_substr( $excerpt, 0, $charlength - 5 );
    $exwords = explode( ' ', $subex );
    $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
    if ( $excut < 0 ) {
        echo mb_substr( $subex, 0, $excut );
    } else {
        echo $subex;
    }
    echo '[...]';
} else {
    echo $excerpt;
}
}
?>

<?php
$my_excerpt = get_the_excerpt();
if ( $my_excerpt != '' ) {
// Some string manipulation performed
 }
 echo $my_excerpt; // Outputs the processed value to the page
 ?>