[wp-hackers] Shortcode to show excerpts by tag?
Beau Lebens
beau at dentedreality.com.au
Mon Feb 2 18:51:45 GMT 2009
Hey Brian,
I just implemented something similar to this on my Page templates on
http://dentedreality.com.au (e.g.
http://dentedreality.com.au/projects/webpad/, "Recent Headlines" at
the bottom).
It's not a shortcode, it's done via a specific Custom Field when you
create the Page. Basically I just add a tag using the "project-tag"
Custom Field and then it uses that to load headlines. Here's the code
from the theme file:
<?php if ( $tag = get_post_custom_values( 'project-tag' ) ) : ?>
<?php $headlines = get_posts(array('tag'=>$tag[0])) ?>
<?php if ( count( $headlines ) ) : ?>
<h2>Recent Headlines for this Project</h2>
<ul>
<?php foreach ( $headlines as $post ) :
setup_postdata( $post ); ?>
<li><a href="<?php the_permalink(); ?>"><?php
the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endif; ?>
Seems to work fine.
Cheers,
Beau
On Mon, Feb 2, 2009 at 10:45 AM, Bryan Spahr <bryanspahr at gmail.com> wrote:
> Hi all -
> I'm looking to create a static page that includes a list of posts that
> have a certain tag. I'm thinking I should be able to do something
> like this:
>
> Blah blah static text blah blah blah
> --------------------------------
> [list_excerpts tag='orange']
>
> and would end up with something like this:
>
> Blah blah static text blah blah blah
> --------------------------------
> Related Links
> * the orange blah
> A story about blah blah
> * two orange blah blah
> A story about blah blah blah
> * blah blah blah three oranges
> A story about blah blah blah blah
>
> I could write a plugin from scratch, but would (obviously) prefer to
> find something that already works, or that I can apply minimal
> enhancements to,... or even just an example of the mini-loop to
> return the excerpts inside my plugin so I spend less time fumbling
> about.
>
> I'm sure this is easier than I have imagined. Thanks for any direction,
>
> Bryan Spahr
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
--
Beau Lebens
Dented Reality
beau at dentedreality.com.au
http://dentedreality.com.au
More information about the wp-hackers
mailing list