My test loop is correct, but still doesn't work.
-
Hi everyone,
Since few days I’m doing a tutorial on how to build a theme from scratch and attach it to wordpress.
I’m a WordPress/PHP beginner but because everything is explained thoroughly so i can understand the how and what.
At this moment I’m stuck at creating the loop in my index.php and after puzzling I have not been able to figure out what the problem is.The steps in the tutorial are as follows:
1. Add content by installing “Theme Unit Test” from the WordPress site.
2. From index.html (base design w/o WordPress) copy the entire content and articles
3. Paste it between get_header and get_footer in index.php
4. Remove from pasted HTML the entire sidebar and replace it with a default one: get_sidebar
5. The content articles pasted into index.php has 3 articles in total; remove the last 2 so you have one left.
6. Add the loop ….The tutorial places a test loop first to see if it works. The tutorial loop works, mine doesn’t.
My loop looks like this:
<?php if (have_posts()) : while(have_posts()) : the_post(); ?> display the post <?php endwhile; else : ?> <h1><?php _e('No posts were found!' , 'adaptive-framework'); ?></h1> <?php endif; ?>
In the tutorial video “display the post” is repeated about 10 times, mine is only showed once. I have continued with the tutorial video which covers the loop to see if at a later point things would become clear, but nope.
The source files are available and the loop works fine in their version.
I have double checked the spelling but all seems fine. When I replace my loop with the one from the source files it still doesn’t work. Copy/pasting doesn’t help me learn, but it’s a good way to test if something goes wrong.Source file loop (the extra .php hasn’t been covered yet in the tutorials I have seen & done):
<?php if (have_posts()) : while(have_posts()) : the_post(); ?> <?php get_template_part('content', get_post_format()); ?> <?php endwhile; else : ?> <article id="post-<?php the_ID(); ?>" <?php post_class('no-posts'); ?>> <h1><?php _e('No posts were found.', 'adaptive-framework'); ?></h1> <?php endif; ?>
I have read about how to loop on the WordPress site and what I have seems to be correct. The mistake must be somewhere else instead.
The puzzling is about to give me a headache lol. I have checked the previous tutorial videos to see if I have missed something but no.I’m running WordPress on a localhost (xampp)
WordPress version: 3.8.1
Tutorial video: https://www.youtube.com/watch?v=Tbx011AsX4U
At about 5:20sec. they begin with writing the loop.
Tutorial source files: http://cdn.tutsplus.com/wp/authors/japh/adaptive-source.zipI have uploaded my themefolder in a .rar here: http://speedy.sh/hBXZP/adaptive.rar (no password)
It also contains the Theme Unit Test from the WordPress site if you want to use it as a test.I hope that I have given all the information you need to find the mistake.
Many thanks in advance!
- The topic ‘My test loop is correct, but still doesn't work.’ is closed to new replies.