dougang1967 2013-06-12 07:51
浏览 40
已采纳

wordpress the_content()== null尽管$ page-> content返回值

Any ideas why the_content() is returning null? When I use $page->content in the same place, this returns the correct value from database.

<?php get_header(); ?>

    <div id="main" class="clearfix" role="main">

        <?php $attachments = new Attachments( 'attachments' ); ?>
        <?php if( $attachments->exist() ) : ?>
            <div id="myCarousel" class="carousel">

                <!-- Carousel items -->
                <div class="carousel-inner">
                    <?php $i = 0; while( $attachments->get() ) :  $i++; ?>

                    <div class="<?php if($i == 1){ echo 'active'; } ?> item item-<?php echo $attachments->id(); ?>">
                        <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php echo $attachments->field( 'title' ); ?>"><?php echo $attachments->image( 'featured-home' ); ?></a>

                        <?php if($attachments->field('caption')){ ?>
                        <div class="carousel-caption">
                            <?php echo $attachments->field('caption'); ?>
                        </div>
                        <?php } ?>
                    </div>

                    <?php endwhile; ?>
                </div>

                <?php if($i > 1) { ?>
                <!-- Carousel nav -->
                <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
                <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>
                <?php } ?>

                <div class="carousel-overlay icons">
                    <a href="http://www.facebook.com" target="_blank" class="facebook">Facebook</a>
                    <a href="http://www.twitter.com" target="_blank" class="twitter">Twitter</a>
                    <a href="http://www.youtube.com" target="_blank" class="youtube">YouTube</a>
                    <a href="#" target="_blank" class="feed">RSS Feed</a>
                </div>
            </div>
        <?php endif; ?>

        <?php if (have_posts()) : ?>
        <article id="post-<?php the_ID(); ?>" <?php post_class(array('row-fluid','clearfix')); ?> role="article">
            <div id="content" class="span8">
                <header>
                    <h1><?php echo get_post_meta($post->ID, 'custom_tagline' , true);?></h1>

                    <?php the_content(); ?>
                </header>

                <section class="post_content hasSidebar">
                    <?php query_posts('showposts=10');
                    while (have_posts()) : the_post(); ?>
                        <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article">
                            <header>
                                <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail( 'wpbs-featured' ); ?></a>

                                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

                                <?php if(get_comments_number() >= 1): ?>
                                <a href="<?php comments_link() ?>" title="<?php comment_date() . ' - ' . comment_excerpt(); ?>" <?php comment_class(); ?>><?php comments_number(); ?></a>
                                <?php endif; ?>

                                <p class="meta"><?php _e("Posted", "bonestheme"); ?> <time datetime="<?php echo the_time('Y-m-j'); ?>" pubdate><?php the_date(); ?></time> <?php _e("by", "bonestheme"); ?> <?php the_author_posts_link(); ?> <span class="amp">&</span> <?php _e("filed under", "bonestheme"); ?> <?php the_category(', '); ?>.</p>
                            </header>

                            <section class="post_content">
                                <?php the_excerpt(); ?>
                            </section>

                             <?php if(has_tag()): ?>
                            <footer>
                                <p class="tags"><?php the_tags('<span class="tags-title">' . __("Tags","bonestheme") . ':</span> ', ' ', ''); ?></p>
                            </footer>
                            <?php endif; ?>
                        </article>
                    <?php endwhile ?>

                    <?php content_paging_nav('nav-below'); ?>
                </section>

                <footer>
                    <p class="clearfix"><?php the_tags('<span class="tags">' . __("Tags","bonestheme") . ': ', ', ', '</span>'); ?></p>
                </footer>
            </div>

            <?php get_sidebar('sidebar2'); ?>
        </article>
        <?php else : ?>

        <article id="post-not-found">
            <header>
                <h1><?php _e("Not Found", "bonestheme"); ?></h1>
            </header>
            <section class="post_content">
                <p><?php _e("Apologies, but no results were found. Perhaps searching will help find a related post.", "bonestheme"); ?></p>
            </section>
            <footer>
            </footer>
        </article>

        <?php endif; ?>

    </div> <!-- end #main -->

<?php //get_sidebar(); // sidebar 1 ?>

<?php get_footer(); ?>
  • 写回答

1条回答 默认 最新

  • douqian6315 2013-06-12 08:05
    关注

    You're not in a WP loop. You should call e.g. the_post() to set up WP's slew of globals.

    Beware of nested WP loops, too. There used to be a gazillion bugs related to them, and there might still be a few lying around just waiting to bite.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable