[wp-hackers] Re: get_posts / query_posts need a pro

Mr. Awesome theone.andonly.mr.awesome at gmail.com
Tue Mar 11 06:27:02 GMT 2008


Andrew Ozz wrote:
> Try:
> <?php
> $myposts = get_posts('numberposts=1&category=3');
> $mypost = $myposts[0];
> setup_postdata($mypost);
> ?>
>
> then 1st line in the loop:
> <?php if ( $post->ID == $mypost->ID ) continue; ?>
>
> Just an idea, not tested...

Hmm, could you use your code above with the code I put in the email 
once? I'm not sure what, or where exactly this stuff is supposed to be 
going.. I tried various ways, but nothing seemed to be working. Here 
below is the code from the header.php file... (Just stuff for the upper 
post stuff) The below that, is the main index.php loop code stuff...

*HEADER.PHP STUFF:*

<div id="announcement-post">
<?php
 global $post;
 $myposts = get_posts('numberposts=1&category=3');
 foreach($myposts as $post) :
setup_postdata($post);
 ?>

<div class="post" id="post-<?php the_ID(); ?>">
<div class="date">
                <span class="monthyear"><?php the_time('F') ?></span>
                <div class="day"><?php the_time('j') ?></div>
                <span class="monthyear"><?php the_time('Y') ?></span>
                </div><h2 class="posttitle"><a href="<?php 
the_permalink() ?>" rel="bookmark" title="<?php _e('Permanent link to'); 
?> <?php the_title(); ?>"><?php the_title(); ?></a></h2>
           
                <p class="postmeta"> <?php _e('Filed under'); ?> <?php 
the_category(', ') ?>
                <?php edit_post_link(__('Edit'), ' &#183; ', ''); ?>
                </p>
                <div class="postentry">
                <?php if (is_search()) { ?>
                    <?php the_excerpt() ?>
                <?php } else { ?>
                    <?php the_content(__('Read the rest of this entry 
&raquo;')); ?>
                <?php } ?>
                </div>
           
                <p class="postfeedback">
                <?php comments_popup_link(__('comments (0)'), 
__('comments (1)'), __('comments (%)'), 'commentslink', __('comments 
off')); ?>
                </p>               
                <!--
                <?php trackback_rdf(); ?>
                -->
</div> <?php endforeach; ?>

*INDEX.PHP STUFF...*

<?php get_header(); ?>


    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); 
?>            <div class="post" id="post-<?php the_ID(); ?>">
    <div class="content2">
      
            <div class="date">
                <span class="monthyear"><?php the_time('F') ?></span>
                <div class="day"><?php the_time('j') ?></div>
                <span class="monthyear"><?php the_time('Y') ?></span>
                </div><h2 class="posttitle"><a href="<?php 
the_permalink() ?>" rel="bookmark" title="<?php _e('Permanent link to'); 
?> <?php the_title(); ?>"><?php the_title(); ?></a></h2>
           
                <p class="postmeta"> <?php _e('Filed under'); ?> <?php 
the_category(', ') ?>
                <?php edit_post_link(__('Edit'), ' &#183; ', ''); ?>
                </p>
                <div class="postentry">
                <?php if (is_search()) { ?>
                    <?php the_excerpt() ?>
                <?php } else { ?>
                    <?php the_content(__('Read the rest of this entry 
&raquo;')); ?>
                <?php } ?>
                </div>
           
                <p class="postfeedback">
                <?php comments_popup_link(__('comments (0)'), 
__('comments (1)'), __('comments (%)'), 'commentslink', __('comments 
off')); ?>
                </p>               
                <!--
                <?php trackback_rdf(); ?>
                -->

            </div><!--endcontent2-->
            </div>
               
        <?php endwhile; ?>

        <p><?php posts_nav_link('', __(''), __('&laquo; Previous 
entries')); ?>
        <?php posts_nav_link(' &#183; ', __(''), __('')); ?>
        <?php posts_nav_link('', __('Next entries &raquo;'), __('')); ?></p>
       
    <?php else : ?>

        <h2><?php _e('Not Found'); ?></h2>

        <p><?php _e('Sorry, but no posts matched your criteria.'); ?></p>
       
        <h3><?php _e('Search'); ?></h3>
       
        <?php include (TEMPLATEPATH . '/searchform.php'); ?>

    <?php endif; ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>






More information about the wp-hackers mailing list