Random post excerpt in sidebar.
-
Dear everybody,
For a custom theme I want to insert a random excerpt (wrapped in quotes).I currently use the following code for this (but I have tried some variations):
<?php
query_posts(array('orderby' => 'rand', 'showposts' => 1));
if (have_posts()) :
while (have_posts()) : the_post();
?>
<q><?php the_excerpt_rss(); ?></q>
<div class="read_more">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">Read more</a>
</div>
<?php endwhile; ?>
<?php endif;
?>This does works, but if I insert this code before the Loop, the content of the page only displays a post, no matter what page I want to view.
If I insert the code after the Loop everything works as expected, but to place it with css I have to useposition: absolute;. The quote is supposed to be beneath the main menu, so if this grows it will do so beneath the quote.Does someone knows what is wrong with my code?
The topic ‘Random post excerpt in sidebar.’ is closed to new replies.