Want to get a space here? Contact us!
by

Thank the author with a small donation using PayPal.

0
Popularity: 7520th place
64 Views
2 Badges
Top 10% !
Specified
Created
Modified on Dec 23, 2013
This snippet is Public
None ... yet!
LanguagePHP
SourceGithub

Artigos Relacionados

Artigos Relacionados: 
functions.php
post this code
<iframe id="embedFrame" style="width:600px; height:300px;" src="http://www.snip2code.com/Embed/13236/Artigos-Relacionados"></iframe>
Click on the embed code to copy it into your clipboard Width:Height:
Leave empty to retrieve all the content First Line:Last Line:
<?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