by
0
101 Views
3 Badges
Top 5% !
Popular
Specified
Popularity: 8457th place
Created
Modified Dec 23, 2013

Published on:

No tags for this snippet yet.
LanguagePHP
SourceGithub

Artigos Relacionados

Artigos Relacionados: 
functions.php
post this code
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="http://www.snip2code.com/Embed/13236/Artigos-Relacionados?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
<?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; } ?>
If you want to be updated about similar snippets, Sign in and follow our Channels
Originally posted on https://gist.github.com/8089862