wordpress the_content()== null虽然$ page->内容返回值

时间:2013-06-12 07:51:45

标签: php wordpress

为什么the_content()返回null的任何想法?当我在同一个地方使用$page->content时,它会从数据库中返回正确的值。

<?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 个答案:

答案 0 :(得分:3)

你不在WP循环中。你应该打电话给the_post()设置WP的大量全局变量。

也要注意嵌套的WP循环。曾经有过与它们相关的大量漏洞,可能仍有一些漏洞等待咬人。