php - 如何在子页面上显示父摘录
问题描述
在 WordPress 中,我有一个附件页面(子页面)。
如何在此页面上显示父摘录?
因为这段代码不起作用:
<?php global $post;
if ( $post->post_parent ) { ?>
<?php echo get_the_excerpt( $post->post_parent ); ?>
<?php } ?>
谢谢你的帮助。
对此,我真的非常感激。
解决方案
你可以使用wp_get_post_parent_id()
which will
返回帖子父级的 ID。
然后您可以显示摘录,get_the_excerpt()
其中将
检索帖子摘录。
你应该得到一些东西(以下未经测试)
<?php
echo get_the_excerpt(wp_get_post_parent_id());
//...
推荐阅读
- javascript - 如何执行异步功能
- algorithm - 使用 DFS 查找矩阵中是否存在路径?
- ruby - 不同类之间的 Ruby TempFile 行为
- reactjs - 代码拆分在 chrome 上加载所有块文件,但在 Firefox 中分别加载它们
- oracle - 我可以在 oracle 中创建参数化视图吗
- php - Wordpress 从管理选项中检索值
- c++ - 如何获得两个二维点云之间的准确转换?
- java - 如何在 Couchbase 中将属性数据类型从字符串转换为数组
- laravel - Laravel 强制 Http 获取资产
- powershell - 从漫游配置文件中删除所有 Microsoft 团队 .exe 引用