[wp-hackers] Shortcode to show excerpts by tag?

Bryan Spahr bryanspahr at gmail.com
Tue Feb 3 13:04:25 GMT 2009


Thanks Torben, and Jeremy, and Beau.  It's been said before, but bears
repeating - this community is one of the friendliest and most helpful
that I've ever been involved with.  The active discussion and
inclusive community are most refreshing!

Regards,
Bryan Spahr

> ---------- Forwarded message ----------
> From: Torben Brams <tbrams at gmail.com>
> Date: Tue, Feb 3, 2009 at 1:41 AM
> Subject: Re: [wp-hackers] Shortcode to show excerpts by tag?
> To: wp-hackers at lists.automattic.com
>
>
> Here's a quick implementation that lists titles along with permalinks based
> on a list of tags. You can use this as a starting point if you need to add
> excerpts as well.
> For example: [list_tagged tag="thai,cover"] will make a nice list of all
> posts with either the tag "thai" or the tag "cover"
> Implementation - add this to your functions.php or create a plugin:
> //Shortcode [list_tagged arglist]
> //All I have included here are the basic tag list and some wrappers (that I
> have not implemented - to keep things as simple as possible ;-) )
> add_shortcode('list_tagged', 'tbr_list_tagged');
> function tbr_list_tagged($atts, $content=null) {
> $atts=shortcode_atts(array(
> 'tag'       => 0,
> 'tag_before' => '',
> 'tag_after' => ''
> ), $atts);
> return tbr_list_tagged_src($atts);
> }
> function tbr_list_tagged_src($atts) {
>    $pages='<ul class="tbr_postlist">';
>    $posts = get_posts(array('tag'=>$atts['tag']));
>    foreach ( $posts as $mypost ) {
>        $pages.= '<li><a
> href="'.get_permalink($mypost->ID).'">'.$mypost->post_title.'</a></li>';
>    }
>    $pages.='</ul>';
>    return $pages;
> }
> I have a running example on http://brams.dk/thai-frontpage/thai-tones/ if
> you want to see, but I will remove it shortly, because it is totally out of
> context there...
> Hope this helps
> Kind regards
> Torben Brams
>
>
>


More information about the wp-hackers mailing list