WordPress

WordPressのトップページにニュースタイトル欄を設けたい

投稿日:2010年12月22日 更新日:

追記:トップページに最新記事5件を日付・タイトルをリスト表示。
さらに過去30日以内の記事にはNEWアイコンを付けるコード。

■index.phpの
<?php include (TEMPLATEPATH . '/sidebar1.php'); ?><div class="art-layout-cell art-content">
の、下あたりに以下を追加。

<!-- ニュース カテゴリの表示その1 ここから -->
<div class='art-post'>
<div class="art-post-body">
<div class="art-postmetadataheader">
<h2 class="art-postheader">
  <img width="26" height="26" alt="postheadericon" src="<?php bloginfo('template_url'); ?>/images/postheadericon.png">
<?php _e('トピックス'); ?></a>
</h2>
</div>
</div>
<ul>
    <?php query_posts('showposts=5&cat=1'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
 
    <li><span class="date">
    <?php the_time('Y年n月j日'); ?>
 
    <?php
        $days=30;
        $today=date('U'); $entry=get_the_time('U');
        $diff1=date('U',($today - $entry))/86400;
        if ($days > $diff1) {
        echo '<img src="/wordpress/wp-content/themes/kosen_inove/images/new.gif" alt="New" />';
    }
    ?>
    </span>
 
        <a href="<?php the_permalink(); ?>"><?php the_title();?></a>
    </li>
    <?php endwhile; endif; ?>
</ul>
</div>
<!-- ニュース カテゴリの表示その1 ここまで -->
<!-- ニュース カテゴリの表示その2 ここから -->
<div class='art-post'>
<div class="art-post-body">
<div class="art-postmetadataheader">
<h2 class="art-postheader">
  <img width="26" height="26" alt="postheadericon" src="<?php bloginfo('template_url'); ?>/images/postheadericon.png">
<?php _e('トピックス'); ?></a>
</h2>
</div>
</div>
<?php $posts = get_posts('numberposts=3&order=desc'); ?>
<ul>
<?php foreach($posts as $post): ?>
    <li><?php the_time('Y-m-d') ?> 
    <a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<!-- ニュース カテゴリの表示その2 ここまで -->

■page.phpだと、うまくいかない・・・?

-WordPress

執筆者:

関連記事

WordPressのお勉強のために、本を1冊購入することにした。

PDFデータのみの販売で2,500円。 PDFでさわりだけ見たけど、なかなかツボを突いた本の予感。Eclipseでブレークポイントを設定してWordPressの処理の流れを追っていくくだりが一番楽しみ …

no image

予約投稿のテスト

WordPressでは、時間が来れば表示してくれる「予約投稿」ができます。

no image

ディレクトリを作成できませんでした。 /public_html

この現象、WP_MEMORY_LIMITがおかしいかもという書き込みを見つけて、 wp-settings.phpの適当な箇所に以下を書き込んだら、直った。 define(‘WP_MEMOR …

no image

旧xoops myalbum 珍しいもの 2

かまぼこ工場4 harvest 2006-1-15 17:19 969 0 工場の職人さん、俺たちが子連れで行ったからか、作り上げた作品をわざわざ天地を整えて、ガラスのすぐ近くのみやすい位置に置いてく …

no image

WelcartのデータをColorMeShopに移行する

基本的には、WelcartのデータをMySqlAdminでエクスポートして、出来たデータをColorMeShopの商品一括登録でインポートするという流れ。 以下、手順を備忘録。 1.MySqlAdmi …