我试图显示特定类别的帖子。我相信我有正确的代码:
<?php if ( in_category(\'11\') ) { ?>
<div class="post">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="entry">
<?php the_content(); ?>
</div>
</div>
<?php } ?>
我知道这一类中有帖子,因为如果我使用querystring
?cat=11
我能看到他们。只是不在这里。什么都没有显示。我做错了什么?
编辑:根据要求,我正在发布来自<?php print_r( $GLOBALS[\'post\'] ); ?>
WP_Post Object ( [ID] => 10 [post_author] => 1 [post_date] => 2013-03-08 12:46:36 [post_date_gmt] => 2013-03-08 12:46:36 [post_content] => This is the content from my static frontpage.php [post_title] => Forside [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => open [post_password] => [post_name] => forside [to_ping] => [pinged] => [post_modified] => 2013-03-12 07:30:56 [post_modified_gmt] => 2013-03-12 07:30:56 [post_content_filtered] => [post_parent] => 0 [guid] => http://vsandbox.net/wordpress/?page_id=10 [menu_order] => 0 [post_type] => page [post_mime_type] => [comment_count] => 0 [filter] => raw )
在旁注中,我注意到在另一个线程中,有人在单线程中没有使用它时遇到了问题。php。我甚至不知道那是什么意思。我的意思是,Web设计的每个布局都必须放在自己的页面模板php文件中,对吗?
编辑2:这是frontpage的完整代码。php文件:
<?php
/*
Template Name: Forside
*/
?>
<?php get_header(); ?>
<div id="content">
<div id="inner-content" class="wrap clearfix">
<div id="main" class="twelvecol first clearfix" role="main">
<!-- START LOOP -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php print_r( $GLOBALS[\'post\'] ); ?>
<section class="entry-content clearfix" itemprop="articleBody">
<?php the_content(); ?>
</section> <!-- end article section -->
<p>Innlemmet 2011</p>
<?php if ( in_category(\'11\') ) { ?>
test
<div class="entry">
<?php the_content(); ?>
</div>
<?php } ?>
<p>Innlemmet 2012</p>
<?php if ( in_category(\'12\') ) { ?>
<div class="post">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="entry">
<?php the_content(); ?>
</div>
</div>
<?php } ?>
<p>Innlemmet 2013</p>
<?php if ( in_category(\'12\') ) { ?>
<div class="post">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="entry">
<?php the_content(); ?>
</div>
</div>
<?php } ?>
<!-- END LOOP -->
<?php endwhile; else: ?>
<p><?php _e(\'Sorry, no posts matched your criteria.\'); ?></p>
<?php endif; ?>
</div> <!-- end #main -->
</div> <!-- end #inner-content -->
</div> <!-- end #content -->
<?php get_footer(); ?>