【问题标题】:Wordpress, i dont get an excerptWordpress,我没有摘录
【发布时间】:2013-05-23 12:09:53
【问题描述】:

我有一些页面,我在其中填写了一些文本,但是,在我构建的这个循环中,它没有输出摘录,能弄清楚为什么吗?

脚本:

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

【问题讨论】:

  • 您的代码已经完成,因此请参考下面的评论以显示页面内容的 post_excerpt。

标签: php wordpress


【解决方案1】:

你可以试试。

     <?php the_excerpt(); ?> 

    <?php the_excerpt(80); ?>

*80 是一个单词限制。

【讨论】:

  • 你没有在摘录中传递参数。
【解决方案2】:

在你的function.php中添加代码

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

在页眉的屏幕选项中选择“摘录”选项。并添加页面摘录内容。

【讨论】:

    【解决方案3】:

    在 WordPress 中,the excerpt 是帖子的一项功能,页面具有 post_excerpt 属性,但这只是因为它们与帖子共享相同的数据库字段。如果您想为您的页面启用摘录区域,请将以下代码放入 functions.php 中。

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

    现在'Admin->New Page'中应该有'Excerpt'区域(如果没有,打开右上角的屏幕选项并单击'Excerpt'复选框)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-29
      • 2014-10-24
      • 2014-04-12
      相关资源
      最近更新 更多