Last active
December 20, 2015 06:39
-
-
Save marushu/6087589 to your computer and use it in GitHub Desktop.
これはアカンヤツ。
returnが無い方ね (^^)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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