WordPress

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

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

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

[php]
■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 ここまで –>
[/php]

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

-WordPress

執筆者:

関連記事

no image

WordPressでFLASHムービー

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

no image

Contact Form 7にパラメータ

必要があり、Contact Form 7にパラメータを渡すことにチャレンジ。 最初、以下のブログに書いてあるやり方でもって、そのまま簡単にできると思った。 WordPressの「Contact For …

no image

WordPressMe2.3.3で、Deprecatedエラー

朝、出社して管理しているお客様のサイトを見ると、上部に見たこともないエラーがずらずら出ていた。 Deprecated: Assigning the return value of new by ref …

no image

WordPress Visual Icon Fonts

Web制作で、FAQページを簡単に作る方法はないかなと考えて、解の一つがこの、WordPress Visual Icon Fontsプラグイン。 icon-question-circle こんなときど …

no image

Ads by datafeedr.com というWordPressのプラグインが動かない原因は自分のブラウザであった

何度設定しても、広告が表示されない、出てこないと思っていたら。 自分のFireFoxに入れているAdBlockPlus拡張が、広告をブロックしていただけであった。 気がつくのに1時間かかっちゃったよ! …