Skip to content

Instantly share code, notes, and snippets.

@MattRead
Created May 30, 2012 19:41
Show Gist options
  • Save MattRead/2838495 to your computer and use it in GitHub Desktop.
Save MattRead/2838495 to your computer and use it in GitHub Desktop.
realted posts by tag
<?php
public function add_template_vars()
{
if ( isset($this->posts) && count($this->posts) ) {
$post = $this->post instanceof Post ? $this->post : $this->posts[0];
if ( $this->post instanceof Post && count($this->posts) == 1 ) {
$this->set_title( $post->title );
if ( $post->typename == 'entry' ) {
$this->assign( 'next', $post->ascend() );
$this->assign( 'previous', $post->descend() );
}
if ( count($post->tags) ) {
$related = Posts::get(array(
'vocabulary' => $post->tags->getArrayCopy(),
'content_type' => $post->content_type,
'status' => Post::status('published'),
'not:id' => $post->id,
'limit' => 5,
'orderby' => 'Rand()'
));
$this->assign( 'related_posts', $related );
}
}
}
elseif ( URL::get_matched_rule() == null ) {
$this->set_title('Page Not Found');
}
parent::add_template_vars();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment