Doug Foster
asked on
adding content excerpt option to shortcode
I found some old code in functions.php which creates a shortcode for future events. I'd like an option in the shortcode to include the excerpt (and if not there, a portion of the content). How do I add that?
add_shortcode('upcoming_events','upcoming_events');
function upcoming_events($atts){
$ret = '';
//wp_query get upcoming events list titles.
$args = array(
'post_type' => 'events',
'posts_per_page' => 6,
'post_status' => 'future',
'order' => 'asc'
);
$the_query = new WP_Query( $args );
if($the_query->have_posts()){
$ret .= '<section class="widget widget_text"><div class="widget-wrap"><div class="textwidget">';
while ($the_query->have_posts()){
$the_query->the_post();
$ret .= '<span>'.get_the_date('m/d/Y').' - <a href="'.get_the_permalink().'">'.get_the_title().'</a><hr/>';
}
$ret .= '</div></div></section>';
}
wp_reset_postdata();
return $ret;
ASKER
Hi Julian.
Yes, i want it to be a parameter in the short code, and have it pull the post's excerpt if it exists. If not, i thought it would be in the settings how many characters to take from the content, but i can change it to what i need. Let's start with 100 characters.
Thanks!
Yes, i want it to be a parameter in the short code, and have it pull the post's excerpt if it exists. If not, i thought it would be in the settings how many characters to take from the content, but i can change it to what i need. Let's start with 100 characters.
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This worked great. Exactly what I asked for. Thanks Julian.
You are welcome.
So you want to be able to pass the short code a parameter and based on that you want to pull the posts excerpt if (it exists) otherwise you want an excerpt of the data (how much in that case)?