简体   繁体   中英

Using the loop to display content, every page only displays Homepage

I am building a theme in WordPress and being a little out of practise I am struggling to make The Loop work properly. I have inserted the most basic loop into the theme and it displays the content fine.. but when I click onto another page or the news page etc, it still just displays the home page.

I'm not sure if I'm just being oblivious to some blindingly obvious problem with my code, but I assumed that the loop displayed whichever page you were currently viewing, or do I have to set up a mishmash of if(is_page('home')) then do a certain wp_query etc?

The loop code I have is inserted below, and if theres any information I forgot I will try update this post with it.

<?php query_posts(); ?>
    <div class="content">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <h2><?php the_title() ;?></h2>
        <?php the_content(); ?>
    <?php endwhile; else: ?>
        <p>Sorry, no posts to list</p>
    <?php endif; ?>
    </div>

Summary: The Loop is only displaying Homepage content on every page.

edit:

Even after disabling my plugin with the first loop in it, the proper Loop isn't working. it is the exact code posted above, and it just won't display the page I am on, or the news on the correct page or anything.... what am i missing

Try removing the query_posts(); line and try again

Apparently... My WordPress install doesn't work with pretty permalinks. As soon as I set it back to default settings, it all worked fine, but if I choose any option other than default, then only the homepage shows up (on any theme).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM