Forum Replies Created

Viewing 3 replies - 16 through 18 (of 18 total)
  • Thread Starter denisecontent

    (@denisecontent)

    I figured it out.

    First put this code into your Child theme’s function.php file:

    
    session_start();
    
    add_filter( 'posts_orderby', 'randomise_with_pagination' );
    function randomise_with_pagination( $orderby ) {
    	if( is_category( 'Alabama' )  ) {
    	  	// Reset seed on load of initial archive page
    		if( ! get_query_var( 'paged' ) || get_query_var( 'paged' ) == 0 || get_query_var( 'paged' ) == 1 ) {
    			if( isset( $_SESSION['seed'] ) ) {
    				unset( $_SESSION['seed'] );
    			}
    		}
    	
    		// Get seed from session variable if it exists
    		$seed = false;
    		if( isset( $_SESSION['seed'] ) ) {
    			$seed = $_SESSION['seed'];
    		}
    	
    	    	// Set new seed if none exists
    	    	if ( ! $seed ) {
    	      		$seed = rand();
    	      		$_SESSION['seed'] = $seed;
    	    	}
    	
    	    	// Update ORDER BY clause to use seed
    	    	$orderby = 'RAND(' . $seed . ')';
    	}
    	return $orderby;
    }

    Now next –
    You need to create a php file for each category using these instructions: https://docs.presscustomizr.com/article/172-using-the-wordpress-template-hierarchy-with-the-customizr-theme.

    Then place your php randomizing code within the php file – which is:

    <?php /* Start the Loop */ ?>
    
    <?php
    if (is_category(‘your-category-slug-name’)) {
    query_posts($query_string . ‘&orderby=rand’);
    }
     else {
    query_posts($query_string . ‘&orderby=title&order=ASC’);
    }
    ?>
    <?php while ( have_posts() ) : the_post(); ?>

    Now Customizr’s instructions are to add this file to the Child Theme. I could not make this work for my site. So I tried going to the root level of the template where index.php is and I added it there.

    Once I did all that – I refreshed the category page and wa la – my category posts were now displaying in random order across all pages without duplicates.

    Thread Starter denisecontent

    (@denisecontent)

    Oh just in case anyone asks – I have caching on my server turned off – so that should NOT be an issue. And I have been clearing my browser just to make sure.

    Thread Starter denisecontent

    (@denisecontent)

    Myles

    Thank you for your reply. And yes – the restaurant sites we do always make me hungry… unfair isn’t it?

    I have been thinking of trying a different slider. I had to do that for a realtor’s site previously due to load problems.

    Also we are going to optimize the images and take out one. The video is a must have as well as the tables and chairs although we may go back and get a pic with people sitting and eating. The pictures we took were before his store opened for the day with just a few kids to model the ice cream. And some lucky people at the coffee house next door got free ice cream because we did not want it to go to waste.

    Customizr is a great theme … but the slider is a bit lacking. There are a couple of sliders I prefer to Customizr’s slider but I was hoping to keep the time down on this job.

    Back to work…

    Thank you for your help once again – Denise

Viewing 3 replies - 16 through 18 (of 18 total)