Code Samples in "WordPress Anthology": Chapter 3

I am hoping you can give some help. I bought the e-book “WordPress Anthology” and I have started to work though the code examples in Chapter 3.

WHERE am I supposed to create/place my work?

Do I change index.php in the twentyeleven theme directory? Do I create a child theme and work in there? Do I alter the index.php in the root directory?

It doesn’t really say unless I’ve really missed it. I’ve read Chapter 3 quite a few times looking for specific directions. On page 58 it shows a little code snippet to demonstrate the default loop, but does not say where this snippet should go to function correctly.

And then we have the code excerpts extracted from the code archive: index.php, loop-index.php … WP_Query.php (etc). How are these called?? In what directory do I put them to test my work? Do they automatically get called in The Loop contained in index.php??

thank you for any help

Lynda E Postal

correct me if I am wrong, I found this post while doing another search so just replying as I am sure someone knows the exact answer and they may reply here. You never should edit any of the root files or wordpress core files. You would edit your theme file, either the page, single, index… depending on what you were trying to accomplish(basically creating custom page/post template files). I haven’t touched child themes yet though. Still experimenting with other things slowly.

I’m still a bit confused. I’ve tried making a copy of index.php and placing it in a ‘twentytenchild’ directory. I can get the child css to work, but not any of the code changes made in the new twentytenchild/index.php.

I really must be missing something. :frowning:

Chapter 3 is about “the loop”. If you look at 03 loop-index.php

<?php if (have_posts()) : $postcounter = 1; ?>

<h1>Latest Posts</h1>
<ul class="mini-list">
	
<?php while (have_posts()) : the_post(); ?>

<li>
  <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a> <?php the_time("j M"); ?></h2>
  <p>
    <?php if ($postcounter == 1) {
             the_content();
	  } else {
              the_excerpt();
	    } ?>
  </p>
  <p><?php the_tags( "Tagged with: ", " / ", "" ); ?> </p>
</li>

<?php 
  if (($postcounter % 3) == 0) { ?>
     <li class="break">
       <a href="http://www.example.com">Buy my widgets please</a>
     </li>
<?php  } 
$postcounter++; ?>

<?php endwhile; ?>
</ul>
<?php else: ?>
  <h1>No posts to show</h1>
  <p>Sorry, we got nada. Nothing. Bupkis. Zippo. Diddly-squat. Sorry to disappoint.</p>
<?php endif; ?>

you can see HTML mark-up and PHP logic and function calls.

AFAIK, most of what the chapter is dealing with should go in whatever theme your using’s index.php file, inside “the loop”.
“The loop” is the “while” i.e.
the opening
while (have_posts()) : the_post();
and the closing
endwhile;