不知道我做错了什么。我是一名初学者,但我已经尝试了很多东西:
我正在尝试打印来自图像的post\\u父级的内容。这是我现在正在使用的。我可以发布标题,但不能发布内容(在打印内容方面,我只能成功地打印图像的内容(实际上是图像的“描述”,而不是我想要的)。
<?php echo wp_get_attachment_image( $post->ID, \'post-image\' ); ?>
<h4 class="attach-title"><?php the_title(); ?></h4>
<p>
    <a
        href="<?php echo get_permalink( $post->post_parent ); ?>"
        title="<?php esc_attr( printf( __( \'Return to %s\', APP_TD ), get_the_title( $post->post_parent ) ) ); ?>"
        rel="gallery">
        <?php
            printf(
                \'<span class="meta-nav">\' . __( \'← Return to %s\', APP_TD ) . \'</span>\',
                get_the_title( $post->post_parent )
            );
        ?>
    </a>
</p>
<p>
    <a
        href="<?php echo get_permalink( $post->post_parent ); ?>"
        the_content="<?php esc_attr( printf( __( \'Return to %s\', APP_TD ), get_the_content( $post->post_parent ) ) ); ?>"
        rel="gallery">
        <?php
            printf(
                \'<span class="meta-nav">\' . __( \'← Return to %s\', APP_TD ) . \'</span>\',
                get_the_content( $post->post_parent )
            );
        ?>
    </a>
</p>
 前两段代码工作正常,但最后一段是我想提取内容的地方。但这段代码只是打印图像本身的描述,而不是post\\u父对象的内容。
 
                    最合适的回答,由SO网友:Johansson 整理而成
                    正如另一个答案所述,您不能将ID传递给get_the_content() 作用你可以用get_post(), 但还有另一个方便的函数可以用来获取内容:
这个get_post_field( $field, $post_id, $context ) 功能是您需要的:
$content = apply_filters( \'the_content\', get_post_field( \'post_content\', $post->ID ) );
 The
the_content 过滤器还确保一些功能(如短代码或自动段落)将按预期工作。
只需更换第二个<a>...</a> 使用此选项:
<?php echo apply_filters( \'the_content\', get_post_field( \'post_content\', $post->post_parent ) ); ?>