Need help with get_posts on index.php!
-
I need some help with using get_posts on index.php! When I use it at the top of the page (before anything else) things like the_permalink() give the permalink of the first post in The Loop. In fact everything but the_excerpt() does. Could anyone help? I’ve included the code below.
<div id="featured"> <h1>Featured Story</h1> <?php $posts2 = get_posts( "numberposts=1&orderby=post_date&category=7" ); ?> <?php if( $posts2 ) : ?> <?php foreach( $posts2 as $post2 ) : setup_postdata( $post2 ); ?> <h2><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2> <?php $args = array( 'post_type' => 'attachment', 'numberposts' => null, 'post_status' => null, 'post_parent' => $post->ID ); $attachments = get_posts($args); if ($attachments) { foreach ($attachments as $attachment) { echo apply_filters('the_title', $attachment->post_title); the_attachment_link($attachment->ID, true, array(250,200)); break; } } ?> <?php the_excerpt(); ?> <hr /> <div style="text-align: right"><strong><a href="<?php the_permalink() ?>">Continue reading '<?php the_title(); ?>' »</a></strong></div> <?php endforeach; ?> <?php endif; ?> </div>
Addendum: I already tried putting it in a separate file and including that. No luck.
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Need help with get_posts on index.php!’ is closed to new replies.