Skip to content

Instantly share code, notes, and snippets.

@yeltsin
Created December 22, 2013 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yeltsin/8089862 to your computer and use it in GitHub Desktop.
Save yeltsin/8089862 to your computer and use it in GitHub Desktop.
Artigos Relacionados
<?php
function wpapi_more_from_cat( $title = "Similier Articles:" ) {
global $post;
$categories = get_the_category( $post->ID );
$first_cat = $categories[0]->cat_ID;
$output = '<h3>' . $title . '</h3>';
$args = array(
'category__in' => array( $first_cat ),
'post__not_in' => array( $post->ID ),
'posts_per_page' => 5
);
$posts = get_posts( $args );
if( $posts ) {
$output .= '<ul>';
foreach( $posts as $post ) {
setup_postdata( $post );
$post_title = get_the_title();
$permalink = get_permalink();
$output .= '<li><a href="' . $permalink . '" title="' . esc_attr( $post_title ) . '">' . $post_title . '</a></li>';
}
$output .= '</ul>';
} else {
$output .= '<p>Desculpe, esta categoria só possui um artigo e você está lendo-o agora!</p>';
}
echo $output;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment