Site logo

Archived topic

Create Home Page with Categories and Random Posts

9 replies · Started by Amos on June 20, 2022

Viewing posts 1–10 of 10

Hello Support,

I just bought this theme today and an tying to create an home page with Categories and random posts generated from this categories on every refresh.
Such that it looks like on screen below;
Home Page Posts

Hi there,

There isn't a feature built-in in GP for this.

You can consider using the Query Loop block we will be introducing in GB 1.5:
https://generateblocks.com/generateblocks-1-5-dynamic-data-query-loops-image-blocks/

It's currently in release candidate 3 so if everything goes well then the official version should be released this week.

That being said, it does not have the randomized feature you are looking for. So if that is absolutely required then you will need to look for another plugin or hire a developer to create a custom solution for you.

Let me know if this helps :)

Thank you for the quick response. However I am really trying to avoid the use of plugins that would otherwise add unnecessary weight on the site. Major reason I bought GP is because of good web vitals.

Anyways, which plug-in do you recommend or any contact for a developer that can help?

Thx

Hi Amos,

Well, GenerateBlocks is a Lightweight plugin which is also our product.

It doesn’t have a randomize feature but we can filter it so that it acts as such.

For instance, I have a Query Loop Block with such settings: https://share.getcloudapp.com/Z4uAqBwR

Then, I add my-query to the class list of the Grid Block within the Query Loop Block as such: https://share.getcloudapp.com/v1uO4zmd

Lastly, I add this PHP snippet:

add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
		if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-query' ) !== false ) {
			$query_args['orderby'] = 'rand';
		}

		return $query_args;
}, 10, 2 );

This snippet sets the order to random which in turn randomizes the posts shown.

Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets

With regards to other plugins, we don’t have a specific recommendation, however, here’s the search results for plugins for custom queries: https://wordpress.org/plugins/search/post+query/

Lastly, here’s our recommendation for custom developments: https://generatepress.com/what-support-includes/#:~:text=Custom%20WordPress%20Development

We also have a Facebook community page/group where I find people also offer development services (not affiliated with us): https://www.facebook.com/groups/1113359788719597

Hope this helps!

Hello Fernando,

This looks promising. I am gonna try the same and give feedback. Many thanks for the quick response and support.
Best
Amos

Hello Fernando,

Seems the randomization is not working as suggested.
Query Loop Settings

What could I be doing wrong?

Thank you for the support.

Hi Amos,

The my-query class has to be added to the Post Template Block within the Query Loop Block. Can you try adding it to that Block instead?

Example: https://share.getcloudapp.com/yAu166Pz

Kindly let us know how it goes.

It seems it worked. But it randomizes even on while on posts page on wordpress.

Hey Amos,

The query loop block you are using is not the GB one, it's the WP's query loop block.

As you can see in Fernando's screenshot, GB's query loop block uses a different icon in blue color:)

This archived topic is closed to new replies.