My first shortcode – display recent post
-
Hi all,
I’m trying to learn how to make shortcodes so I’m starting with an easy one to simply display the title of the most recent post and a short excerpt as seen here.
So I used the code:
function new_post_snippet($atts, $content=null){ $getpost = get_posts( array('number' => 1) ); $getpost = $getpost[0]; $return = $getpost->post_title . "<br />" . $getpost->post_excerpt . "…"; $return .= "<br /><a href='" . get_permalink($getpost->ID) . "'><em>read more →</em></a>"; return $return; } add_shortcode('newestpost', 'new_post_snippet');
Which almost works.
Everything displays as per the tutorial except for the excerpt…
What am I missing?
Cheers
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘My first shortcode – display recent post’ is closed to new replies.