在附件页上,我有一个指向上传文件的帖子/页面的链接。(对于直接添加到媒体库的文件,不会显示此选项,这很好。)
对于添加到帖子和页面的附件,以下代码将生成链接:
$post = get_post( get_the_ID() );
if ( $post->post_parent ) {
echo \'<a href="\' . get_permalink( $post->post_parent ) . \'">\' . get_the_title(
$post->post_parent ) . \'</a>\';
}
然而,当我尝试查看上传到自定义帖子类型的附件时,它不起作用。如果显示$post的var\\u转储,则会得到以下结果:
object(WP_Post)#398 (24) { ["ID"]=> int(789) ["post_author"]=> string(1) "1" ["post_date"]=> string(19) "2015-04-17 13:32:39" ["post_date_gmt"]=> string(19) "2015-04-17 13:32:39" ["post_content"]=> string(0) "" ["post_title"]=> string(5) "image" ["post_excerpt"]=> string(0) "" ["post_status"]=> string(7) "inherit" ["comment_status"]=> string(4) "open" ["ping_status"]=> string(4) "open" ["post_password"]=> string(0) "" ["post_name"]=> string(5) "image" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) "" ["post_modified"]=> string(19) "2015-04-17 13:32:39" ["post_modified_gmt"]=> string(19) "2015-04-17 13:32:39" ["post_content_filtered"]=> string(0) "" ["post_parent"]=> int(0) ["guid"]=> string(63) "wp-content/uploads/2015/04/image.jpg" ["menu_order"]=> int(0) ["post_type"]=> string(10) "attachment" ["post_mime_type"]=> string(10) "image/jpeg" ["comment_count"]=> string(1) "0" ["filter"]=> string(3) "raw" }
相关部分为["post_parent"]=> int(0)
这意味着附加到自定义帖子的文件没有父级。有人能证实这一点吗?或者这可能是我设置自定义帖子类型的错误吗?
我尝试了分层和非分层类型,以及支持和不支持“页面属性”。
提前感谢任何人的帮助,
亚当