Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a child theme based on the twenty ten theme which I am happy with except for one thing. My gallery posts (I am a photographer so the goal of my blog is pictures) do not show any images from the post on the main page. I want to have my main page be a list of recent gallery posts each of which should show the shortened version of the description with a preview image (first image from the posted gallery). I am using NextGen Gallery and slim box to display my images - if that makes a difference.

I have found the place where the main loop creates the entry for each post on the main page:

    <?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
        <div class="entry-summary">
            <?php the_excerpt(); ?>
        </div><!-- .entry-summary -->
<?php else : ?>
        <div class="entry-content">
            <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
            <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
        </div><!-- .entry-content -->
<?php endif; ?>

So, what I need to do is one of the following:

  1. Override the_content method to include my gallery's preview image along with what the theme does already.
  2. Override part of the main loop above to add an image after the call to the_content and before the call to wp_link_pages.
  3. Override the whole main loop to do the same.

I feel like I am missing something obvious because I see serious down sides to all three options I can come up with:

  1. I do not see any reference to overriding functions like the_content and even if I could I want to add to it not replace it. Is there even away to call the original method's functionality after you override a method?
  2. As far as I can see there is no way to override part of a loop - its all or nothing.
  3. Which leads me to 3 - replacing the main loop. At that point I have to seriously wonder if it is worth having a child theme if I replace the main loop. That's a lot of code that I don't need to own that I would end up owning.

Is there an obvious way to do this that I am missing?

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

Instead of overriding the main loop, you can always just create a template, similar to the main loop and use that on a separate page (which you then set to display as your home page).

You'd just need to set up a wp_query in that template to call the posts you want and run a loop on that.

That way everything is left in tact and you just have one page in your child theme. Then you can add what you like after the_content();.

That's how I'd normally go about this sort of thing.

See here: http://codex.wordpress.org/Stepping_Into_Templates

share|improve this answer
    
Brilliant! I was hoping there would be a better way. So, in the twenty_ten theme the index.php file has this comment above the call the main page loop <?php /* Run the loop to output the posts. * If you want to overload this in a child theme then include a file * called loop-index.php and that will be used instead. */. So, I still have to repeat the contents of the loop.php file but I can have my own that resides next to the original. Seems like a good way to go. –  Ian Lelsie Jun 26 '12 at 12:32
    
Yeh, but you can still leave the main loop intact if you don't want to override it. Then just set up a template with loop for pulling portfolio posts only, and use this on a 'Home' page. That way if you want to use the main loop later (for a more complete blog, not just porfolio), it's still there. edits: grammar. –  josh Jun 26 '12 at 12:40
add comment

Something to consider ...

Twenty Ten supports the Gallery post-format, you can simply create a "loop-gallery.php" template to be used with the theme rather than having to specifically over-write the "index" and/or create a Child-Theme.

NB: If the Twenty Ten authors choose to add a 'loop-gallery' template then you will need to over-load it via a Child-Theme.

share|improve this answer
    
I don't want to mess with the look of the gallery pages them selves. I am happy with the way they work now - using the NextGen plugin and slim box. All I want to do is make my home page better by having an image thumbnail for each gallery post appear on the home page. A loop-gallery.php would replace my gallery page generation and not the main page generation - correct? –  Ian Lelsie Jun 26 '12 at 14:07
    
You are correct ... I misread the point of you wanting to modify your "main page". –  Edward Caissie Jun 26 '12 at 19:06
    
Great thanks for the input. –  Ian Lelsie Jun 27 '12 at 20:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.