記事一覧を入れたいんですよね!
http://appofit.com/wordpress/template-wp/shortcode-wp/
▽2
●
gizmo5 ●80ポイント ベストアンサー |
質問にあるコードを機械的に書き写しただけですが、以下のようになると思います。
function hogeFunc() { global $post; $html = ""; $tmp_post = $post; $category_ids = array( '17' ); //カテゴリーIDを指定 $numberposts = '100'; //一覧表示したい記事数を数字で指定 foreach ( $category_ids as $category_id ) { $html .= '<h3>' . get_cat_name( $category_id ) . '</h3><ul>'; $postslist = get_posts( "category=$category_id&numberposts=$numberposts&order=DESC&orderby=modified" ); foreach ( $postslist as $post ){ $html .= sprintf( '<li> <a href="%s">%s %s</a></li>', esc_attr(get_permalink( $post->ID )), esc_html($post->post_title), get_the_modified_date('Y年n月j日') ); } $html .= '</ul>'; } $post = $tmp_post; return $html; } add_shortcode('hoge', 'hogeFunc');
パーマリンクの esc_attr() は無くても良いかもしれませんが、タイトルの esc_html() はやっておいた方が良いと思います。
http://codex.wordpress.org/Function_Reference/esc_html
サンプルは探せばたくさん見つかると思います。
http://www.virment.com/wordpress/1582/