ウチヤマ
side_custum_post_most_popular.php
まずWP Most Popular
を追加
コードを書く必要が有る
http://2inc.org/blog/2012/03/05/1266/ 説明 すでにカスタムポスト対応済み 元が
//アーリー指定法
$posts = wmp_get_popular( array(
'limit' => 5,
'post_type' => array( 'post', 'custom1', 'custom2' ),
'range' => 'monthly'
) );
//これが元ソース
echo '<div class="widget-container popular-posts">
<dl>
<dt>最近1ヶ月の人気の記事</dt><dd><ul>';
$posts = wmp_get_popular( array( 'limit' => 5, 'post_type' => 'post', 'range' => 'monthly' ) );
global $post;
if ( count( $posts ) > 0 ): foreach ( $posts as $post ):
setup_postdata( $post );
?>
<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
<?php
endforeach; endif;
wp_reset_postdata();
echo '</ul></dd></dl></div>';
//これがオリジナル改造ソース
<?php
echo '<h2 class="widgettitle">最近1ヶ月の人気の記事</h2>';
//ここから
$posts = wmp_get_popular( array( 'limit' => 5, 'post_type' => 'jirei_new', 'range' => 'monthly' ) );
global $post;
if ( count( $posts ) > 0 ): foreach ( $posts as $post ):
setup_postdata( $post );
//ここまででループ指定
?>
<div class="popular_one">
<div class="popular_sam">
<?php
//カスタムフィールドスイートのループコード 画像1個だけ
$i = 0;
$kiji = 1;//この回数でフォーチ終わる。
$fields = $cfs->get('jirei_imgs');
foreach ($fields as $field) :
if($i >= $kiji)://siが3よりおおきくなったら
break;//ループおわり
else://それまではこれで出力
?>
<?php
$attachment_id = $field['jirei_img'];
$sample_photo = wp_get_attachment_image($attachment_id,'jirei_small');?>
<a href="<?php the_permalink(); ?>">
<?php
echo $sample_photo;
?>
</a>
<?php
$i++;//多分繰り返すごとに$iに数値が1つづ増える
endif;
endforeach;
?>
</div>
<div class="popular_title"><a href="<?php the_permalink(); ?>">
<?php the_title(); ?></a></div>
<div class="popular_date" style="padding-top:5px;">
<?php get_trim_str(array('str'=>get_post_meta($post->ID,"jirei_disp",true), 'len'=>100)); ?>
</div>
</div>
<?php
//これがループとじ
endforeach; endif;
wp_reset_postdata();
echo '';
?>