0
    <?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

0

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(); ?>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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