是否未显示来自自定义字段的值?

时间:2011-03-13 作者:janoChen

由于某些原因,此自定义字段未显示在页面中。

这是模板文件:

<?php

/**
 * Template Name: bbPress - Topics (Newest)
 *
 * @package bbPress
 * @subpackage Theme
 */

?>

<?php get_header(); ?>

        <div id="container">
            <div id="content" role="main">

                <?php do_action( \'bbp_template_notices\' ); ?>

                <?php while ( have_posts() ) : the_post(); ?>

                    <div id="topics-front" class="bbp-topics-front">
                        <div class="entry-content">

                            <div id="page-intro">
                                <?php the_content(); ?>
                            </div>

                            <?php get_template_part( \'loop\', \'bbp_topics\' ); ?>

                        </div>
                    </div><!-- #topics-front -->

                <?php endwhile; ?>

                <?php if ( get_post_meta($post->ID, \'note\', true) ) : ?>
                    <div id="note">
                        <p><?php echo get_post_meta($post->ID, \'note\', true); ?><p/>
                    </div>
                <?php endif; ?>

            </div><!-- #content -->
        </div><!-- #container -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>
正如您所看到的,一切都已设置好:

enter image description here

2 个回复
最合适的回答,由SO网友:Rob Williams 整理而成

您是在循环之外进行的,因此$post在这一点上是未定义的。把它放在endwhile 它应该会起作用。

SO网友:Guillo

我也有类似的情况global $post 解决方案成功。:)

结束

相关推荐