Woo! I sorted it out.
It all depended on use of WP_Query which I wasn’t very familiar with.
This opens up a whole realm of possibilities 🙂
Of course, as usual, if anyone has a suggestion of tidier code, that’d be legend. I might turn this into a function to make my template files a little neater (and give me the option to use this elsewhere – such as on the author page)
<?php
$otherReleases = new WP_query();
$otherReleases->query(array('orderby'=>date,'cat'=>15,'author'=>$post->post_author,'post__not_in'=>array($post->ID)));
if ($otherReleases->have_posts()) :
?>
<h3>Other releases by this artist</h3>
<ul class="other-releases">
<?php while ($otherReleases->have_posts()) : $otherReleases->the_post(); ?>
<li>
//get other release info
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
In action here: http://devel.invisibleagent.com/2006/02/22/corrugated-tunnel-we-are-electronix/
As you can see it displays all my normal loop stuff, and then at the end, as there are other releases (cat15) by this ‘author’ it displays what they are. Still needs styling etc, but the camel’s back is broken now..
Right, after messing around with things for the whole night, I’ve now written a function to allow me to access the same sort of display on the author page.
I thought I’d throw it in here just in case anyone had any suggestions for improvement.
The function call is set up like this:
<?php get_author_releases($post->post_author, $post->ID); ?>
on single.php such as: http://devel.invisibleagent.com/artist/corrugated/
and
<?php get_author_releases($post->post_author); ?>
on the author.php template such as: http://devel.invisibleagent.com/2006/02/22/corrugated-tunnel-we-are-electronix/
and the function looks like:
function get_author_releases($author, $current=NULL) {
global $post;
global $curauth;
$user_info = get_userdata($author);
$releasecover = "No Cover";
$releaseformat = "Format Unknown";
$otherReleases = new WP_query();
// Check if the $current parameter is assigned
// if it is then the function is being used on a release page and should not display the current release - only any other releases
// otherwise display all releases
if ( !empty ($current) ) {
$otherReleases->query(array('orderby'=>date,'cat'=>15,'author'=>$author,'post__not_in'=>array($current)));
$intro = "Other releases by ";
} else {
$otherReleases->query(array('orderby'=>date,'cat'=>15,'author'=>$author,));
$intro = "Releases by ";
}
// If there are any posts to display, display heading and start UL
if ($otherReleases->have_posts()) :
echo "<h2>" . $intro . $user_info->nickname . "</h2>\r\n";
echo "<ul class='other-releases'>\r\n";
// Begin loop
while ($otherReleases->have_posts()) : $otherReleases->the_post();
echo "<li>\r\n";
echo "<a href='" . get_permalink() . "' rel='bookmark' title='Link to " . $post->post_title . "'>";
$releasecover = get_post_meta($post->ID, "release-cover", true);
if (!empty($releasecover)) {echo $releasecover;}
echo "</a>";
echo "<h3 class='post-title'>" . $post->post_title . "</h3>\r\n";
echo "<p>";
$releaseformat = get_post_meta($post->ID, "release-format", true);
if (!empty($releaseformat)) {echo $releaseformat . " / ";}
echo the_time('Y') . "</p>";
echo "<p class='release-link'><a href='" . get_permalink() . "' rel='bookmark' title='Link to " . $post->post_title . "'>View Details</a></p>\r\n";
echo "</li>\r\n";
endwhile;
echo "</ul>\r\n";
endif;
}
At first I tried to assign all my content to a variable and just return it, but that was a disaster. I had some fun and games then trying to find out what I needed to call as $post->etc but anyway, got there eventually. I got to get me some sleep!