- This topic has 13 replies, 2 voices, and was last updated 6 years, 3 months ago by Tom.
-
AuthorPosts
-
December 20, 2017 at 9:57 am #453966NBC
I use the posts page to display work samples that I set up as individual posts. The chronological order in which posts appear makes no sense for what’s essentially a portfolio page.
I do load randomized posts in a sidebar on my samples pages, but that’s not the same thing as randomizing the posts on the posts page itself.
I’ve looked for a plug-in that would randomize the samples. All of them work only in sidebars.
I’ve looked for code I can add to my child theme. Nothing I’ve found works.
Any suggestions?
December 20, 2017 at 10:46 pm #454278TomLead DeveloperLead DeveloperHi there,
You could probably do something like this: https://generatepress.com/forums/topic/custom-post-type-templyte-code/#post-346744
December 21, 2017 at 6:27 am #454492NBCYessss! That’s perfect!
Thanks so much, Tom!
December 21, 2017 at 10:08 am #454696TomLead DeveloperLead DeveloperYou’re welcome π
December 21, 2017 at 10:27 am #454711NBCThis solution does have one unexpected consequence. It randomizes the Posts listing in the dashboard. That can make it difficult to find the post you want to edit, because when you load page 2, the list randomizes again. Kinda like playing Whac-a-Mole. π
I can work around it (log in; visit the site to load the page I want to edit; click on the “Edit” link at the top of the page).
December 21, 2017 at 10:45 am #454730TomLead DeveloperLead DeveloperAh, try this instead:
function tu_rand_posts( $query ) { if ( $query->is_main_query() && ! is_admin() ) { $query->set( 'orderby', 'rand' ); } } add_action( 'pre_get_posts', 'tu_rand_posts' );
December 21, 2017 at 11:48 am #454757NBCThank you, Tom! That’s exactly it. You’re super!
December 21, 2017 at 9:36 pm #454966TomLead DeveloperLead DeveloperGlad I could help π
December 26, 2017 at 3:31 pm #457436NBCHi, Tom (and Leo):
I’m posting this question here because it relates directly to the rest of the thread.
The site I was building at the time I started this thread is live now (allfornonprofits.com).
I notice that if I bring up the main sample page (the posts page) through the “Our work” link, and scroll down until the “Continue” button appears, I get repeats of posts that already loaded.
Anything in particular I need to do to forestall that?
December 26, 2017 at 8:45 pm #457537TomLead DeveloperLead DeveloperThis is on the Our Work page? I just gave it a shot and didn’t notice any duplicated posts.
Maybe try clearing your browser cache.
Let me know π
December 27, 2017 at 6:53 am #457851NBCI load another batch of posts using the “Continue” button, and that’s when the repeated posts appear.
December 27, 2017 at 11:26 pm #458235TomLead DeveloperLead DeveloperAh, displaying the posts randomly can cause this issue in WordPress.
Perhaps this will help?: https://wordpress.stackexchange.com/a/33275
December 28, 2017 at 4:39 am #458361NBCHi, Tom:
Looks like that takes care of it! I tested it on my localhost dev server and will implement on the running site.
Thank you again for all you do!
December 28, 2017 at 9:58 am #458640TomLead DeveloperLead DeveloperGlad I could help! π
-
AuthorPosts
- You must be logged in to reply to this topic.