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の固定ページのページネイションで、ひと苦労

・WordPressで作ったWebサイト上で、とある固定ページのひとかたまりにおいて、100ページほどの報告書を目次付きで載せている。 ・で、頁をめくるような要領で、次へとか戻るとかのページを移動する …

no image

WP Limit Post Automaticallyプラグインはとても賢い

とあるサイトを管理していて、WPで長文を書くことが多い。 カテゴリー一覧でリスト表示した場合、全文表示されるととっても見にくい。特に画像が多いと。 その場合にも見やすいように文章の前半に「続きを読む- …

no image

WorpPressのGoogle Mapのプラグインをテスト中

このページを参考に、WordpressのLightweight Google MapsおよびKtai Locationプラグインをテスト中。 これはすごい。 特に、地名や住所を [geo] というタグ …

no image

TinyMCE Advancedで表が作れないトラブル

WordPressで表を造る近道のTinyMCE Advanced。 ・・・だが今回、インストールはしたものの、表作成のボタンをクリックしても白いのっぺらぼうのウィンドウが出るだけで何も出来ないという …