web-dev-qa-db-ja.com

検索結果の投稿とページを区別する

検索結果の投稿とページをどのように区別できますか。

必要なのは投稿にthe_time divを表示することですが、ページには表示しません。無関係なので。

機能付き?以下のループの<?php if (!is_page()) }は役に立ちません。

<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>

//prevent this div from displaying for pages: 
<div class="searchdate"><?php the_time('F jS, Y') ?></div>

<?php the_excerpt(); ?>

<?php endwhile; ?><?php else : ?><?php endif; ?>
1
markratledge

これを試して...

<?php //prevent this div from displaying for pages:
if ( get_post_type() != 'page' ) : ?>
   <div class="searchdate"><?php the_time('F jS, Y') ?></div>
<?php endif; ?>

is_page()条件タグは、現在表示されているコンテンツが単一ページビューであるかどうかだけをチェックします。現時点ではあなたには何もありません。 http://codex.wordpress.org/Function_Reference/is_page を参照してください。

3
Michal Mau