Skip to content

Instantly share code, notes, and snippets.

@kachi
Created April 5, 2012 06:16
Show Gist options
  • Select an option

  • Save kachi/2308399 to your computer and use it in GitHub Desktop.

Select an option

Save kachi/2308399 to your computer and use it in GitHub Desktop.
<?php
function getCatItems($atts, $content = null) {
extract(shortcode_atts(array(
"num" => '5',
"cat" => ''
), $atts));
global $post;
$oldpost = $post;
$myposts = get_posts('numberposts='.$num.'&order=DESC&orderby=post_date&category='.$cat);
$retHtml='<ul>';
foreach($myposts as $post) :
setup_postdata($post);
$retHtml.='<li><a href="'.get_permalink().'">'.the_title("","",false).'</a></li>';
endforeach;
$retHtml.='</ul>';
$post = $oldpost;
return $retHtml;
}
add_shortcode("list", "getCatItems");
?>
/*ショートコードは以下のように書く*/
[list cat="1" num="10"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment