我似乎不能在Get_Pages中显示摘录,并且不知道为什么?

时间:2014-08-11 作者:Lee

因此,我在get\\u页面中有一个foreach循环,它显示父ID中的子页面列表。

标题、特色图片和链接都很好,但我根本无法找到摘录。我在引用http://codex.wordpress.org/Function_Reference/get_pages

$args = array(
    \'child_of\'     => 16,
    \'title_li\'     => \'\',
    \'depth\'         => 0,
    \'sort_order\'    => \'DESC\',
    \'sort_column\'   => \'menu_order\'
);
$pages = get_pages( $args );
$output = \'\';
foreach($pages as $value){
    $thumb = get_the_post_thumbnail( $value->ID, $attr = \'\' );
    $output .= "<div class=\'case-studies-parent\'><div class=\'inner\'>";
    $output .= "<div class=\'image\'><a href=\'" . $value->post_name . "\' >" . $thumb . "</a>    </div>";
    $output .= "<div class=\'title\'><a href=\'" . $value->post_name . "\' >" .  $value->post_title . "</a></div>";
    $output .= "<div class=\'excerpt\'>". $value->post_excerpt . "</div>";
    $output .= "</div></div>";
} 
echo $output;
我可以改变$value->post_excerpt$value->post_content 这样可以正确地显示整个页面的内容。

我也尝试过各种变化,包括get_the_excerpt(), the_excerpt()post_excerpt 但无济于事。

我有什么遗漏吗?在Codex页面上post_excerpt 列为正确的回报,所以我真的不知道为什么它没有显示。(顺便说一下,是的,我已经在我的页面中添加了更多标签)

更新时间:var_dump($value)

object(WP_Post)[276]
public \'ID\' => int 155
public \'post_author\' => string \'1\' (length=1)
public \'post_date\' => string \'2014-08-07 09:40:53\' (length=19)
public \'post_date_gmt\' => string \'2014-08-07 09:40:53\' (length=19)
public \'post_content\' => string \'<h2>Mobile phone tracking</h2>
<p><span>Parents keen to know the location of their children, and businesses seeking to ensure safety of lone workers have since 2004, been able to purchase a mobile phone tracking service, designed and implemented by InverOak, in conjunction with Cybit for The Carphone Warehouse.</span></p>
<p>The Carphone Warehouse, Europe\'s leading independent retailer of mobile phones and services, asked InverOak to design a system that tracks the location of any mobile phone in the UK, \'... (length=2656)
public \'post_title\' => string \'The Carphone Warehouse\' (length=22)
public \'post_excerpt\' => string \'\' (length=0)
public \'post_status\' => string \'publish\' (length=7)
public \'comment_status\' => string \'closed\' (length=6)
public \'ping_status\' => string \'closed\' (length=6)
public \'post_password\' => string \'\' (length=0)
public \'post_name\' => string \'the-carphone-warehouse\' (length=22)
public \'to_ping\' => string \'\' (length=0)
public \'pinged\' => string \'\' (length=0)
public \'post_modified\' => string \'2014-08-11 10:01:34\' (length=19)
public \'post_modified_gmt\' => string \'2014-08-11 10:01:34\' (length=19)
public \'post_content_filtered\' => string \'\' (length=0)
public \'post_parent\' => int 16
public \'guid\' => string \'http://inveroak.local/?page_id=155\' (length=34)
public \'menu_order\' => int 0
public \'post_type\' => string \'page\' (length=4)
public \'post_mime_type\' => string \'\' (length=0)
public \'comment_count\' => string \'0\' (length=1)
public \'filter\' => string \'raw\' (length=3)
因此,post\\u摘录为空。但我不完全理解为什么,如果它包含在抄本的回报中?

更新:我发现3.1中删除了页面的摘录,并在主题函数中添加了手动摘录函数。php文件:

add_post_type_support( \'page\', \'excerpt\' );
虽然这看起来不错,但这与在编辑器中使用标记有什么区别吗?哪个更干净?

2 个回复
最合适的回答,由SO网友:Tomás Cot 整理而成

您可以使用this function wp_trim_words(). 它允许您格式化输出,并剥离内容中的所有HTML标记(它使用wp_strip_all_tags).

你必须通过post_content 作为第一个参数。

SO网友:Romain

如果您正在请求查询中每个帖子的摘录,您需要为每个帖子设置帖子数据。

$args = array(
    \'child_of\'     => 16,
    \'title_li\'     => \'\',
    \'depth\'         => 0,
    \'sort_order\'    => \'DESC\',
    \'sort_column\'   => \'menu_order\'
);
$pages = get_pages( $args );
$output = \'\';
foreach($pages as $value){

    $temp = $post;
    $post = get_post( $value->ID );
    setup_postdata( $post );
    $thumb = get_the_post_thumbnail( $value->ID, $attr = \'\' );
    $output .= "<div class=\'case-studies-parent\'><div class=\'inner\'>";
    $output .= "<div class=\'image\'><a href=\'" . $value->post_name . "\' >" . $thumb . "</a>    </div>";
    $output .= "<div class=\'title\'><a href=\'" . $value->post_name . "\' >" .  $value->post_title . "</a></div>";
    $output .= "<div class=\'excerpt\'>". echo get_excerpt(190) . "</div>";
    $output .= "</div></div>";
    wp_reset_postdata();
    $post = $temp;
} 
echo $output;
附言:你的摘录有什么内容吗?也许代码在您的页面上,您是否检查了css以查看摘录是否未隐藏?

结束

相关推荐

Url中的wp-login.php与符号结果为404

我有一个问题,如果wp登录,wordpress站点将抛出404。php后面附加了一个符号和(例如,session expired参数)。我更改了主题,禁用了所有插件,重命名了。htaccess访问。htaccess1和我还有404。看起来像是wp登录。php未链接“&;”在它之后,例如“wp login&;whatever=blah”。如果“redirect\\u to”中有冒号,例如“redirect\\u to”,我还有另一个问题=http://blah.com/“这也会导致404。如果删