Skip to content

Instantly share code, notes, and snippets.

@marushu
Last active December 20, 2015 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marushu/6087589 to your computer and use it in GitHub Desktop.
Save marushu/6087589 to your computer and use it in GitHub Desktop.
これはアカンヤツ。 returnが無い方ね (^^)
<?php function category_list( $atts ) {
extract( shortcode_atts( array(
'post_type' => 'post',
'cat_name' => '',
'num' => 3,
'class' => 'relational_lists',
'order' => 'date',
), $atts ) );
global $post;
$args = array(
'post_type' => $post_type,
'category_name' => $cat_name,
'numberposts' => $num,
'order' => $order,
);
$relational_posts = get_posts( $args );
foreach( $relational_posts as $post ) {
$post_date = get_the_time( 'Y年m月d日', $post->ID );
$post_link = get_permalink( $post->ID );
$post_title = get_the_title( $post->ID );
echo '<li>' . $post_date . '<a href="' . $post_link . '">' . $post_title . '</a></li>';
}
}
add_shortcode( 'cat_list', 'category_list' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment