开发者

how to show limited content of page in wordpress

开发者 https://www.devze.com 2023-03-10 00:45 出处:网络
I have code the dis开发者_高级运维playing content and `title\' of page.I want to show only 150 words of that particular page content.

I have code the dis开发者_高级运维playing content and `title' of page.I want to show only 150 words of that particular page content.

Here is my code

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

?>

This code showing all content of page that have id 1319.I want to disply only 150 word please provide me the suggestion.

I shall be very thankful to you I am waiting for your reply thanks


Use

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

Or

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

精彩评论

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