WordPress.org

Ready to get started?Download WordPress

Forums

Attitude
[resolved] posts in random order ONLY on homepage (2 posts)

  1. zocimike
    Member
    Posted 4 months ago #

    Hi

    This theme is realy great!
    I would like if the posts on the main page would be randomized on every load. I have done it with the code: query_posts('orderby=rand')

    ...but there is a problem: all posts shown on every category and tag pages of my menu. I want it only in main loop. Is there any solution?

    /****************************************************************************************/
    
    if ( ! function_exists( 'attitude_theloop_for_archive' ) ) :
    /**
     * Fuction to show the archive loop content.
     */
    function attitude_theloop_for_archive() {
    	global $post;
    query_posts('orderby=rand');
    	if( is_front_page() ) {
    		while( have_posts() ) {
    			the_post();
    
    			do_action( 'attitude_before_post' );
    ?>
    	<section id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    		<article>
    
    			<?php do_action( 'attitude_before_post_header' ); ?>
  2. zocimike
    Member
    Posted 3 months ago #

    finally I solved it:
    put this code before the WP loop in index.php
    <?php query_posts($query_string . '&orderby=rand') ?>

Reply

You must log in to post.

About this Theme

About this Topic

Tags

No tags yet.