Team:ETH Zurich/labblog/catfunction.php

From 2014.igem.org

Revision as of 16:35, 6 July 2014 by Clormeau (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

function jc_post_by_category($atts, $content = null) {

   extract(shortcode_atts(array(
       "nb" => '5',
       "orderby" => 'post_date',
       "order" => 'DESC',
       "category" => '1'
   ), $atts));
   global $post;
   $tmp_post = $post;
   $myposts = get_posts('showposts='.$nb.'&orderby='.$orderby.'&category='.$category);
$out = '
    '; foreach($myposts as $post){ setup_postdata( $post ); $out .= '
  • <a href="'.get_permalink().'">'.the_title("","",false).'</a>
  • ';
       }
    
    $out .= '
';
   wp_reset_postdata();
   $post = $tmp_post;
   return $out;

} add_shortcode("post-by-category", "jc_post_by_category");