I'm trying to display posts from specific categories. And I believe I have the correct code:
<?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 } ?>
I know there are posts in that category, because if I use the querystring ?cat=11
I can see them. Only not here. Nothing is showing. What am I doing wrong?
Edit: As requested, I'm posting the results from <?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 )
On a sidenote, I noticed in a different thread that someone had problems with this when not using it in single.php. I'm not even sure what that means. I mean, each layout of the webdesign has to be put in it's own page template php-file right?
Edit2: Here is the full code of the frontpage.php file:
<?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(); ?>
{
and}
in the if statement. I'm not sure if that needs to be there or not butprint_r( $GLOBALS['post'] );
in the line above this block. Then update your question with this info.