0

私はWordpressの開発にかなり慣れていません。私はこのコードを単一のページに使用しており、無限ループで最新の投稿のみを出力しています。同じ投稿が何度も呼び出されると、ページはどんどん長くなります。すべての投稿を順番に表示するにはどうすればよいですか?

<?php
/*
 * Template Name: Portfolio
 */
?>
   <?php include 'header.php'; ?>

    <div id="content">
        <div id="content_inner">
            <!--start the loop -->
            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                <!--get posts-->
                <?php query_posts('cat=uncategorized') ?>
                <!--display the content-->
                <?php the_content(); ?>
            <!--end the loop-->
            <?php endwhile; else: ?>
            <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
            <?php endif; ?>
        </div>
    </div>

    <?php include 'footer.php'; ?>

    </div> <!--end allwrap-->
4

1 に答える 1

0

呼び出すquery_postsと、データベースに対してクエリが再実行されます。これをループ内に置くと、無限ループの原因になります。

次の行をループの外に移動する必要があります。

<?php query_posts('cat=uncategorized') ?>

次のようなものが得られます。

<!--get posts-->
<?php query_posts('cat=uncategorized') ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

             <!--display the content-->
            <?php the_content(); ?>
            <!--end the loop-->
<?php endwhile; else: ?>
            <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<?php wp_reset_query(); ?>

追加することも重要ですwp_reset_query()

于 2012-10-29T20:33:08.640 に答える