• i am trying to write the code for having just an excerpt of posts from a specific category (news) show on a page.

    here is the code i have:

    <h6>Latest News</h6>
    <p><?php
    	$args = array( 'numberposts' => '2', 'category' => 6, );
    	$recent_posts = wp_get_recent_posts( $args );
    	foreach( $recent_posts as $recent ){
    		echo '<a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' .   $recent["post_title"].'</a>';
    		echo '<br> Lorem ipsum dolor sit amet nuno valencia esta di mari askebar de coloumbusus.';
    		echo '<a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" > <hr>read more <br></a>';
    	}
    ?>
    </p>

    i can’t figure out how to call the excerpts.
    for now i just put “
    Lorem ipsum dolor sit amet nuno valencia esta di mari askebar de coloumbusus.” where i want the excerpt.

    i’ve searched but i can’t find anything relevant to within an argument array.

Viewing 1 replies (of 1 total)
  • Thread Starter rebeccacarney

    (@rebeccacarney)

    never mind, i got it.

    <h6>Latest News</h6>
    <p>
    <?php $my_query = new WP_Query('category_name=News&showposts=2');
      		while ($my_query->have_posts()) : $my_query->the_post();
      		$do_not_duplicate = $post->ID;?>
      		<?php
    			$strings = preg_split('/(\.|!|\?)\s/', strip_tags($post->post_content), 2, PREG_SPLIT_DELIM_CAPTURE);
    			echo apply_filters('the_excerpt', $strings[0] .  $strings[1]);
    			echo '<hr><p><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >read more</a></p>';
    		?>
     <?php endwhile; ?>
Viewing 1 replies (of 1 total)
  • The topic ‘show an excerpt for recent posts of a specific category’ is closed to new replies.