修剪get_post_field中的内容

时间:2015-09-21 13:05:10

标签: php wordpress

我有一个代码显示主页上的子页面内容:

<?php /* list sub-pages content */

$portfolioID = $post->ID;

$portfolio_sections = array(
  'post_type' => 'page',
  'child_of' => $portfolioID,
  'sort_column' => 'menu_order',
  'sort_order' => 'ASC',
);

$sections = get_pages($portfolio_sections);

$hierachical = array();

if ( ! empty($sections) ) {
  foreach ( $sections as $section ) {
    if ( $section->post_parent == $portfolioID ) {
      if ( ! isset( $hierachical[$section->ID]) ) $hierachical[$section->ID] = array();  
      $hierachical[$section->ID]['child'] = $section;
      $hierachical[$section->ID]['grandchildes'] = array();
    } else {
      if ( ! isset( $hierachical[$section->post_parent]) ) $hierachical[$section->post_parent] = array();
      $hierachical[$section->post_parent]['grandchildes'][] = $section;
    }
  }
  foreach ( $hierachical as $id => $hierachical_data ) {

    if ( ! isset($hierachical_data['child']) || ! is_object($hierachical_data['child']) ) continue;

    echo '<div class="subpagegrid">';

    echo '<a href="'. get_permalink($hierachical_data['child']->ID) .'"><h2 class="childpage">' . get_the_title($hierachical_data['child']->ID) . '</h2></a>';
    echo apply_filters('the_content', get_post_field('post_content', $hierachical_data['child']->ID));

    if ( isset($hierachical_data['grandchildes']) && ! empty($hierachical_data['grandchildes']) ) {
      foreach ( $hierachical_data['grandchildes'] as $grandchild ) {
            echo '<div class="grandpages">';
            echo '<a href="'. get_permalink($grandchild) .'"><h3 class="grandchildpage">' . get_the_title($grandchild) . '</h3></a>';
            echo apply_filters('the_content', get_post_field('post_content', $grandchild ));
            echo '</div>';
      }
    }
    echo '</div>';
  }
}

?>

我想将内容的长度限制为例如。 50个字符(这看起来像一个摘录),但我不知道如何实现它。我相信这部分内容来自数据库: apply_filters(&#39; the_content&#39;,get_post_field(&#39; post_content&#39;, ...但是我如何影响长度? ?

0 个答案:

没有答案