简体   繁体   中英

Wordpress, i dont get an excerpt

I have some pages, where i filled in some text, however, in this loop i've builted, It doesn't ouput an excerpt, can figure out why ?

The script:

<?php   
    $pageChildren = get_pages('sort_column=menu_order&number=5&hierarchical=0&child_of=16');
    if ( $pageChildren ) {
      foreach ( $pageChildren as $pageChild ) {
    ?>

    <div class="four columns rightbox">

        <div class="panelbox">      
             <?php echo '<h2><a href="' . get_permalink($pageChild->ID) . '">'. $pageChild->post_title.'</a></h2>'; ?>
            <?php 
            if (!empty($pageChild->post_excerpt)){
                echo '<p><a href="' . get_permalink($pageChild->ID) . '">' . $pageChild->post_excerpt.'</a> </p> ';
            }
            ?>

        </div>   
    </div>

    <?php
      }
    }
    ?>

You can try it.

     <?php the_excerpt(); ?> 

or

    <?php the_excerpt(80); ?>

* 80 is a word Limit.

Add code in your function.php

add_action( 'init', 'my_add_excerpts_to_pages' );
function my_add_excerpts_to_pages() {
     add_post_type_support( 'page', 'excerpt' );
}

在此处输入图片说明

select 'excerpt' option in screenoption on page header. and add page excerpt content.

In WordPress the excerpt is a feature for posts, pages have the post_excerpt property but it is only because they share the same database fields as the posts. If you want to enable excerpt area for your pages put the following code in functions.php.

add_action( 'init', 'add_pages_excerpts' );
function add_pages_excerpts() {
    add_post_type_support( 'page', 'excerpt' );
}

Now there should be 'Excerpt' area in 'Admin->New Page' ( if not, open the screen options at the right top corner and click on 'Excerpt' checkbox ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM