seems to be working when i use ‘name’ instead of ‘id’:
$taglist = get_terms('post_tag', 'hierarchical=0&orderby=name&hide_empty=1');
foreach ($taglist as $pftag) {
query_posts('tag='.$pftag->name.'&posts_per_page=2&orderby=date');?>
<h3><?php echo ($pftag->name); ?></h3>
<?php while (have_posts()) : the_post();
purplefrog_excerpt_tile();
endwhile; }
echo works instead of print_r
Thread Starter
arndis
(@arndis)
Thank you, and this does get a little farther — the tag headings that have posts now have appropriate posts.
Unfortunately half the tags turn up empty — just the heading, no posts. All those tags do have posts belonging to them already, so this shouldn’t be happening. The only thing I can see in common between them is that all those tags are made of multiple words — they have spaces in them. Earlier I tried changing one multiword tag to be one word, but the query_posts output did not change.
Help please?
good observation –
using the slug seems to bring out all posts:
query_posts('tag='.$pftag->slug.'&posts_per_page=2&orderby=date');?>
(this is not very clearly documented in the codex)
Thread Starter
arndis
(@arndis)
Yes, that does work! Thank you!
And no, it’s not terribly well documented. The code above started life looping through categories, and that was fairly simple to get working thanks to the example at http://iamnotagoodartist.com/how-to/wordpress-how-to-sort-category-archive-posts-by-subcategory/. The main problem was linking each heading, for which I have an ugly makeshift because get_category_link won’t work properly.
When I started converting it to do the same thing for tags, I found one roadblock after another — there were no obvious equivalent tag functions for the category functions I had been using. I eventually stumbled on get_terms, which has presented its own problems.
Thread Starter
arndis
(@arndis)
Of course, soon I’m going to add another layer of complexity to the whole thing by telling query_posts to only consider posts with a custom field…won’t that be fun?
But first I have a couple years of projects to upload.
Thread Starter
arndis
(@arndis)
And for anyone looking for the code of the complete solution, it is posted with comments at http://themeshaper.com/forums/topic/create-post-list-grouped-by-tag?replies=2#post-12365.
Thread Starter
arndis
(@arndis)
Code over at themeshaper got broken because I’m not used to BBPress.
Pastebin of working code over at http://wordpress.pastebin.com/zavDfaqZ.