editing index file in child theme

Discussion in 'WordPress' started by sixrfan, Sep 10, 2010.

  1. #1
    please advise how i get ONLY THE MOST RECENT blog posting FROM A SPECIFIC CATEGORY to appear on my index page (http://greenrefurbishing.com/wordpress/).

    i'm building a child theme of Twenty Ten. Should I be editing the index.php file in the TwentyTen theme folder? Or the index.php file in my child theme folder, or something else? I've already made changes to the index.php in the child theme folder in order add in that slider that you see.

    and after identifying which file, what code do i put there to get just the most recent post from a sepecific category?

    FYI, i was just starting to slightly get my head around child themes and the loop before 3.0 but now i'm completely lost. please advise. thanks in advance!
     
    sixrfan, Sep 10, 2010 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yeah, keep editing the files in the child theme folder. If you start editing TwentyTen, other child themes may not work.

    Replace ID with the category ID number:
    
    <?php 
    $latestposts = get_posts('numberposts=1&category=ID'); 
    foreach($latestposts as $post) :
       setup_postdata($post); 
    ?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php the_excerpt(); ?>
    <?php endforeach; ?>
    
    Code (markup):
     
    Last edited: Sep 11, 2010
    Cash Nebula, Sep 11, 2010 IP
  3. sixrfan

    sixrfan Well-Known Member

    Messages:
    354
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    that worked perfectly. thank you!

    out of curiosity though, why didnt a loop-index.php file need to be created? from what i've read (and am confused about) in some of the tutorials is that i was supposed to create that file???
     
    sixrfan, Sep 12, 2010 IP
  4. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Great! :)

    It's an optional method of reusing code in a theme. Wordpress always goes back to index.php when it can't find certain files.
    There is a diagram on the Template Hierarchy page that shows how it works but it has not been updated for version 3.

    TwentyTen uses the new get_template_part function to load certain loop files.
    It first looks in the child theme folder for loop-index.php and loop.php, then it searches for those files in the parent folder.
    Since you have index.php in your child theme, Wordpress uses that instead of the parent file so the function never runs.

    I hope that's right :)
     
    Last edited: Sep 12, 2010
    Cash Nebula, Sep 12, 2010 IP