【WordPress】 新着記事をショートコードで任意の場所に表示

function getCatItems($atts, $content = null) { extract(shortcode_atts(array( “num” => ’10’ ), $atts)); global $post; $oldpost = $post; $myposts = get_posts(‘numberposts=’.$num.’&order=DESC&orderby=post_date’); $retHtml=”; foreach($myposts as $post) : setup_postdata($post); $retHtml.=”.get_post_time(‘Y/m/d’).”.the_title(“”,””,false).”; endforeach; $retHtml.=”; $post = $oldpost; return $retHtml;}add_shortcode(‘latestarticle’, ‘getCatItems’);

情報源: 【WordPress】 新着記事をショートコードで任意の場所に表示