Using get_content twice on same page for different actions
-
I’m using the get_content twice on my home page. One shows an excerpt of my latest post, the other to display a random log entry. Unfortunately because I have set my excerpt in WordPress to show just one entry on my homepage, when I call the rand argument get_content I think it is also showing the excerpt from the latest post, despite showing the title from the other random posts. So my random posts, set to display 5 random posts, would show:
Random title 1
Content from the latest postRandom title 2
Content from the latest postRandom title 3
Content from the latest post…and so on. How should I code my homepage to show the content from the random posts instead? My current code is thus:
<?php get_header(); ?> <div id="wrap"> <div id="content-container"> <div id="content"> <div class="post-container"> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <div class="posttop"> <!-- <div id="date"> <p class="day"> <?php the_time('j'); ?> </p> <p class="month"> <?php the_time('F'); ?> </p> </div>--> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?> </a></h2> <div class="postinfo"><?php the_time('l, F j Y') ?></div> <div class='postinfoauthor'>Written by <?php the_author(); ?> <?php edit_post_link('Edit', ' | ', ''); ?> </div> </div> <div class="entry"><p> </p><p> </p><p> </p><p> </p><p> </p> <?php the_content('<br />Continue reading: ' . the_title('', '', false)); ?> </div> <!-- <div class="postbottom"> <div class="metainf">Filed Under: <?php the_category(', ') ?> </div> <div class="commentinf"> <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> </div> </div> --> </div> <?php endwhile; ?> <!-- <?php include (TEMPLATEPATH . '/navoptions.php'); ?>--> <?php else : ?> <h2>Not Found</h2> <p class="center">Sorry, but you are looking for something that isn't here.</p> <?php endif; ?> <div class="entry"> <h2>A random selection of my writing</h2> <?php $rand_posts = get_posts('numberposts=5&orderby=rand'); foreach( $rand_posts as $post ) : ?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?><?php the_content('Read more...'); ?></a> <?php endforeach; ?> </div> </div> <div style="float:left"> <?php get_sidebar(); ?> </div> </div> <div class="bgbottom"></div> </div> </div> <?php get_footer(); ?>
- The topic ‘Using get_content twice on same page for different actions’ is closed to new replies.