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

執筆者:

関連記事

WooCommerceでメールの本文を追加編集する

このやり方、Google先生の手を借りていろんなページをあさってみたけど、詳しい記事がない。 なので、最近WooCommerceを使い始めた私が。 プラグインの、WooCommerce Email T …

no image

WordPress管理画面のパスワード忘れたとき

ローカルインストールのWordPressの管理画面のパスワードを忘れたときに、以下のページが参考になったので、備忘録。 WordPress のパスワードをマニュアルでリセットする方法 | コリス

no image

WordPressでFLASHムービー

丸一日格闘した。 しかし甲斐あって、インデックスファイルに作ったフラッシュムービーファイルとの連携表示が出来た。 このサイトが参考源。 WordPress で index.html を共存させる方法 …

no image

最近見つけた良記事の備忘録

Microsoft WordからWordPressへ記事を投稿する方法 *Ateitexe そろそろ本気でWordPress!Web制作初心者が劇的に成長できるオススメ国内有名ブログ18選 無料でモリ …

no image

Responsiveが超高速で作れるArtisteer最高

Webの高速制作ツールのArtisteerがResponsiveに対応しているのは知っていた。 けども、Wordpressでウィジェットとして追加したブロックの一つ一つについて、モバイルで表示したくな …