2011-06-03 129 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 
?> 
相關問題