Created
December 22, 2013 23:55
-
-
Save yeltsin/8089862 to your computer and use it in GitHub Desktop.
Artigos Relacionados
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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