2011-06-03 77 views
0

我的代码显示content和page的title。我只想显示该特定页面内容的150个单词。如何在wordpress中显示页面的有限内容

这里是我的代码

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

?>

此代码显示,有ID 1319。我想DISPLY只有150字,请提供给我的建议,页面的所有内容。

我是非常感激你 我等着你的答复 感谢

回答

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 
?>