how to add loop in header
-
Hi, i have a problem, i want to add a post loop in header in order to show the last new post in one singol category and then in the index the rest of.
i’m trying by this code in header.php:
<?php query_posts('cat=248&posts_per_page=1'); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div id="post-<?php the_ID(); ?>"> <?php the_content(''); ?> </div> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?>in this way category id is 248 and show only the last post.
and in index i’m using this:
<?php query_posts($query_string . "&cat=-248"); ?> <?php if (have_posts()) : ?> <?php $c = 0; ?> <?php while (have_posts()) : the_post(); ?> <?php if ( !is_paged() && ++$c == 1 ) { ?> <div id="post-<?php the_ID(); ?>"> <?php the_content(''); ?> </div> <?php } else { ?> <div id="post-<?php the_ID(); ?>"> <?php the_content(''); ?> </div> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?>this code, in order to assign a different style to the last inserted post in category different from 248 just in homepage, but this doesn’t work. Post are showed correctly but it’s impossible to access to single post. any suggestion?
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
The topic ‘how to add loop in header’ is closed to new replies.