SimpleeWP theme01にはあらかじめ『お知らせ』という名前でカスタム投稿を1つ設定させて頂きました。
企業サイトやSHOPサイトなどでお知らせや新着情報だけ別に管理したいことはよくあります。
<固定ページ>ではほとんど更新が発生しないページを用意して、
<投稿>で更新追加が多いカテゴリーの管理をするやり方は一般的です。
<お知らせ>や<新着情報>などは、その他のカテゴリーの記事と一緒になると、
過去の記事を探しづらくなってくる場合があります。
後々、メンテナンスしやすい設定。
そんなつもりで用意しています。
トップページのウィジェット(大)の直下に表示されます。
必要ない場合には、テンプレート<index.php>の該当箇所を削除してください。
また、他の場所に設置したい場合も、テンプレート内の
<!--▽カスタム投稿を使用しない場合はここから削除▽-->
<div id="news">
<h5 class="widget-title">Information
<div style="float:right;"><a href="<?php echo home_url() ; ?>/information/"><span class="box_r" style="font-size:10px; color:#666;">お知らせ一覧 <i class="icon-double-angle-right"></i></span></a></div>
</h5>
<ul>
<?php
// ▽ポストタイプとタクソノミーを入力
$post_type = 'information';
$taxonomy = 'category';
// △
$args=array(
'post_type' => $post_type,
'post_status' => 'publish',
'posts_per_page' => 3,
'orderby' => 'date',
'order' => 'DESC' ,
'ignore_sticky_posts'=> 1
);
$my_posts = get_posts($args);
foreach ($my_posts as $post) {
setup_postdata($post);
$post_title = $post->post_title;
?>
<li>
<span class='date'><?php echo get_post_time('Y.m.d D'); ?></span>
<?php
$terms = get_the_terms( $post->ID, $taxonomy );
if ( $terms && ! is_wp_error( $terms ) ) :
$draught_links = array();
foreach ( $terms as $term ) {
echo '<a class="' . $term->slug . '" href="' . home_url( '/' ) . $term->taxonomy .'/'. $term->slug . '">' . $term->name . '</a>';
}
endif;
$days=14; $today=date('U'); $entry=get_the_time('U'); $diff1=date('U',($today - $entry))/86400;
if ($days > $diff1) { echo ' <img src="' . get_template_directory_uri() . '/img/new/new_02.png" alt="New" />'; }
?>
<br />
<i class="icon-double-angle-right"></i> <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
</li>
<?php } ?>
</ul>
<!-- END NEWS --></div>
<!--△カスタム投稿を使用しない場合はここまで削除△-->
となっている箇所を、そのままコピーして利用できます。
【追記】2014年12月
現在、テーマによってはカスタム投稿「お知らせ」もウィジェット対応しています。
テンプレートを直接修正することなく、お知らせ一覧をウィジェットエリアに挿入することも可能となりました!