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.
    <?php $my_query = new WP_Query( "cat=11&posts_per_page=1" );
   if ( $my_query->have_posts() ) { 
       while ( $my_query->have_posts() ) { 
           $my_query->the_post();
           the_excerpt();
       }
   }
   wp_reset_postdata(); ?>

Where it says the_excerpt, how come I am unable to add other code alongside this? I'm guessing it's because it's still within the PHP tag, but I am unsure of how to seperate the two. Is there a way to make a section where the_excerpt is so that I may add additional code? I'm trying to add:

<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="postdetails">
Written by <strong><?php the_author(); ?></strong>
<?php the_time ('j F, Y'); ?>
Posted in: <strong><?php the_category(', '); ?></strong>
<?php the_tags(); ?>
</div>

and THEN the excerpt

Thank you

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

To insert new code you need to break php code and past your new html+/-php code. But pay attention that after passing all will have correct syntax.

Your question should be made like this:

<?php $my_query = new WP_Query( "cat=11&posts_per_page=1" );
if ( $my_query->have_posts() ) { 
    while ( $my_query->have_posts() ) { 
        $my_query->the_post(); ?>

        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
        <div class="postdetails">
            Written by <strong><?php the_author(); ?></strong>
            <?php the_time ('j F, Y'); ?>
            Posted in: <strong><?php the_category(', '); ?></strong>
            <?php the_tags(); ?>
        </div>

        <?php the_excerpt();
    }
}
wp_reset_postdata(); ?>
share|improve this answer
    
Brilliant, thank you –  Phill May 23 '12 at 6:11
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.