WordPress Snippet

ワードプレスをカスタマイズしよう

落書き カテゴリ 投稿リスト

$html	= '%3$s<li class="%4$s"><a href="%1$s">%2$s</a></li>';
$args	= array(
	'posts_per_page'=> 5,
	'category' => 41,
	'post_status' => 'publish',
	'orderby' => 'post_date',
	'order'=> 'DESC',
);
$myposts= get_posts( $args );

foreach ( $myposts as $key=> $post ) {

	setup_postdata( $post );

	$category= get_the_category();

	if ( $key== 0 ) {
		printf( '<h3 id="%1$s">%2$s</h3>', sanitize_key( $category[ 0 ]->slug ), esc_html( $category[ 0 ]->name ) );
		printf( '%2$s<ul class="%1$s">', sanitize_key( $category[ 0 ]->slug ), "\r\n" );
	}
	printf( $html, get_permalink(), the_title( '', '', false ), "\r\n\t", sanitize_key( $category[ 0 ]->slug . '-' . basename( get_permalink() ) )
	);

	if ( !isset( $myposts[ $key + 1 ] ) ) {
		print "\r\n</ul>";
	}
}
wp_reset_postdata();
<h2 id="aciform">aciform</h2>
<ul class="aciform">
	<li class="aciform-27603"><a href="http://www.example.com/wp/archives/27603">form test</a></li>
	<li class="aciform-27443"><a href="http://www.example.com/wp/archives/27443">test</a></li>
	<li class="aciform-27414"><a href="http://www.example.com/wp/archives/27414">svg2</a></li>
	<li class="aciform-27411"><a href="http://www.example.com/wp/archives/27411">テスト</a></li>
	<li class="aciform-27289"><a href="http://www.example.com/wp/archives/27289">Custom Featured Image</a></li>
</ul> 

[emulsion_relate_posts]