简体   繁体   中英

Get the wordpress loop to show posts on second page

So i have made a wordpress site from zero (own theme templates and everything).

if i open the site the content of index does show up as intended. Its just header, some static content (text and images) and links (didn't use the wordpress menus, just some permalinks to the other pages). Project consists of the index page and some other pages created in the dashboard via page -> create -> use my Template. One of this pages, the product page, is header, footer, sidebar with custom widgets on it and some static text.

After the static text i want to show some products represented via posts. For this i wanted to use "the loop", which as i understood should be capable of showing all posts. This is the code for the loop.

             <div>
                <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                    <div class="article">
                        <h2 class="title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
                        <?php the_content(); ?>
                    </div> <!-- .article -->
                <?php endwhile; endif; ?>
            </div>

This does not seem to show the posts i have created for testing, but only the title (no text, 'cause i haven't entered it) of the Site the loop is on ("Products").

So what am i doing wrong?

Sorry for the detailed description. Thanks in advance.

Okay, for anyone with the same problem, i found an answer. This was actually quite tricky and kind of counter intuitive.

As far as i did right, you can set "static homepage" and "blogpage" in dashboard -> settings -> read. So far so good, but then i got weird problems wit my custom template blog page, as it was force shown the static home too.

Solution was found in the template hierarchy of wordpress. When i set custom pages for the new static home, i had name collision with my template called home.php. So when i used the template home_page.php for my static home and the index.php for the "custom blog page", magic happened and it just worked as intended!

Easy for people with wordpress experience, i think, but hard work for me. But on the other hand i now have quite the inside in how wordpress processes templates!

Hope, that might help so with the same issues!

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