【问题标题】:How to show Parent Excerpt on Child Page如何在子页面上显示父摘录
【发布时间】:2021-08-08 16:00:11
【问题描述】:

在 WordPress 中,我有一个附件页面(子页面)。
如何在此页面上显示父级摘录?
因为这段代码不起作用:

<?php global $post;
  if ( $post->post_parent ) { ?>

    <?php echo get_the_excerpt( $post->post_parent ); ?>

<?php } ?>

感谢您的帮助。
我真的很感激。

【问题讨论】:

    标签: php wordpress wordpress-theming attachment custom-wordpress-pages


    【解决方案1】:

    您可以使用wp_get_post_parent_id(),它将

    返回帖子父级的 ID。

    然后您可以通过get_the_excerpt() 显示摘录

    检索帖子摘录。

    你应该得到一些东西(以下未经测试)

    <?php
    echo get_the_excerpt(wp_get_post_parent_id());
    //...
    

    【讨论】:

    • 我尝试了这段代码,但也没有用:&lt;?php global $post; if ( $post-&gt;post_parent ) { ?&gt; &lt;?php echo get_the_excerpt(wp_get_post_parent_id()); ?&gt; &lt;?php } ?&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多