<div class="img-box">
<ul>
<?php
$args = array(
'post_type' => 'topics',
'taxonomy' => 'info',
'term' => 'event',
'numberposts' => '-1',
);
$my_posts = get_posts($args);
foreach ( $my_posts as $post ) {
setup_postdata($post); ?>
<?php
$attach_id = get_post_meta($post->ID,"メイン画像",true);
$image_info = wp_get_attachment_image_src( $attach_id , 'full' );
list( $url, $w, $h) = $image_info;
$h = intval(200 * ( $h / $w ));
$alt = get_post_meta($attach_id , '_wp_attachment_image_alt', true);
?> <li><a href="<?php the_permalink() ?>"><img src="<?php echo $url; ?>" alt="<?php echo $alt; ?>" width="118px" height="<?php echo $h; ?>" />
</li>
<?php
}
?>
</ul>
</div>
page.phpで出力るす場合
<?php
$args = array(
'post_type' => 'topics',
'posts_per_page' => 50,
'tax_query' => array( /* カスタム分類 */
array(
'taxonomy' => 'info',
'field' => 'slug',
'terms' => 'event',
)
)
);
?>
<?php $loop = new WP_Query($args); ?>
<div class="jutaku-box">
<ul>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
$attach_id = get_post_meta($post->ID,"メイン画像",true);
$image_info = wp_get_attachment_image_src( $attach_id , 'full' );
list( $url, $w, $h) = $image_info;
$h = intval(200 * ( $h / $w ));
$alt = get_post_meta($attach_id , '_wp_attachment_image_alt', true);
?> <li><div class="jutaku-img-box"><a href="<?php the_permalink() ?>"><img src="<?php echo $url; ?>" alt="<?php echo $alt; ?>" width="118px" height="<?php echo $h; ?>" /></a></div>
</li>
<?php endwhile; ?>
</ul>
<?php $tax_posts = get_posts('post_type=カスタムタイプ&taxonomy=カスタム分類&term=ターム&posts_per_page=3'); if($tax_posts): ?>
<ul>
<?php foreach($tax_posts as $tax_post): ?>
<li><a href="<?php echo get_permalink($tax_post->ID); ?>"><?php echo esc_html($tax_post->post_title); ?></a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php
$args=array(
'tax_query' => array(
array(
'taxonomy' => 'newsoll', //タクソノミーを指定
'field' => 'slug', //ターム名をスラッグで指定する
'terms' => array( 'event','report','information' ) //表示したいタームをスラッグで指定
),
),
'post_type' => 'news', //カスタム投稿名
'posts_per_page'=> 5 //表示件数(-1で全ての記事を表示)
);
?>
<?php query_posts( $args ); ?>
<?php if(have_posts()): ?>
<?php while(have_posts()):the_post(); ?>
ページが存在する場合の指定
<?php endwhile; else: ?>
ページが存在しない場合の指定
<?php endif; ?>
<?php wp_reset_query(); ?>