SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy 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

  2. #2
    SitePoint Guru
    Join Date
    Nov 2001
    Location
    Fort Lauderdale
    Posts
    814
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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. :-(

    Quote Originally Posted by 4SeeN View Post
    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.

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    Chapter 3 is about "the loop". If you look at 03 loop-index.php
    PHP Code:
    <?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;


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •