- This topic has 12 replies, 6 voices, and was last updated 2 years, 1 month ago by David.
-
AuthorPosts
-
October 14, 2021 at 3:46 pm #1963813Elvis
I didn’t find this topic, if it exhists, please move the question there.
On my homepage I want to have a section that displays several CPTs, let’s say, recently published ones.
As far as I understand, element (block) depends on its location in CPT > Archive, or in blog if post_type is post, to loop over content of the query. This does not help as it limits the loop to archive pages, preventing the possibility of sections and queries in pages.
I also tried to use headline, within wordpress core query block to display CPT custom fields data in loops, doesn’t work.
Is a homepage like this possible with GP premium https://kulturforum-zagreb.org/ or like this https://apuri.hr/ ?
PS
A feature request? Can you provide a dynamic content block in the context of GenerateBlocks (for premium users) so that it can be used outside of elements context? It seems as a basic thing nowadays.
October 14, 2021 at 5:08 pm #1963842ElvinStaffCustomer SupportHi Elvis,
For now, you can try using WP Show Posts to display a query loop for CPTs. https://wpshowposts.com/
But in the future, GenerateBlocks and WP Show Posts are set to merge.
Tom plans to merge the 2 plugins by adding a post grid block to GenerateBlocks, effectively turning WPSP into a block.
But we don’t have ETA for this at the moment. π
October 15, 2021 at 2:24 am #1964093ElvisHi Elvin,
well that’s a minimal name difference. πThank you for a quick reply.
I am trying to avoid shortcodes in gerneal, however since this is something that would be merged into the product in the future I would maybe even use it if there weren’t a following problem.
The plugin misses a feature that is kind of the point of my problem. It does not fully support CPTs. Post meta is limited to standard post meta. I cannot choose to display, or orderby custom fields. Let’s say I want to display book cards, I cannot display book author name in my card with the plugin.
Is there a way to pull what I build as elements with shourcodes into a page. I think I know your answer, but grabing onto a straw here. I hear blocksy pro can do this.
Alternatively, can you recomend (preferably gutenberg way) a 3rd party plugin that would add this for now missing functionality, following a GP philosophy of lean, accessible code?
Thanks
October 15, 2021 at 3:17 am #1964135DavidStaffCustomer SupportHi there,
Block elements are simply templates that can be Hooked into other places, such as a custom loop.
Breaking it down you would need to create a shortcode that:a. Sets the query args
b. outputs a loop
c. includes a hook inside that loopHeres a shortcode i made to do that for a custom build as an interim solution until GB has a query block:
https://gist.github.com/diggeddy/b71bf07aa55eecb0c34191f9fe05d224
The shortcode it create is:
[db_display_custom_post_loop]
The hook name it outputs inside the loop is:db_custom_post_loop
For the Block Element, you would set the Hook to Custom Hook, and add the above to the field provided.
The Display Rules can be set to the Entire site as it will only get called where that hook is output.You will need to add some Custom CSS to create the grid however.
Something to play with.
October 15, 2021 at 6:18 am #1964287ElvisHi David,
thanks for the answer.
This looks nice. A couple of questions though.Why hook? I am allready working on a shortcode for displaying links to documents, so I taught I can tweak this to do more .. here https://gist.github.com/thisbit/baa25d414af2c81f1f5615930c581f38
Why would a hook be useful for a situation that is trying to be used instead a GP query block?
Additionaly, performance wise, what do you think, would it be better to have dedicated separate shortcodes, or only one? Let’s say, one when someone wants to output a grid of CPTs with featured image etc, another when someone wants a list of recent articles, another for when someone wants to list events coming up… or would it be better to create one, and then let user tweak their query via shotcode params, which in turn also spits different markup, fields etc?
I beleive for users it would be better to have one, and tweak with params, I am just wondering about performance.
Thanks a lot.
October 15, 2021 at 7:06 am #1964323DavidStaffCustomer SupportThe purpose of the Hook is for you to attach your Block Element ( Type: Hook ) to output your content.
Aside from the limited design options with the core Query Block, you don’t have access to custom post_meta.
So my method allows you to build your custom template in Block Element and output it in your custom loop shortcode.Shortcodes – one vs many – really depends … A few simple shortcodes will probably be more performant then a single shortcode that has LOTS of params/queries/conditions running. But i think the difference would be negligible. I would go with whats best for the end user to work with.
October 15, 2021 at 7:12 am #1964329ElvisOh, nice, didn’t think about it this way at all.
For me hooks are these permanent spots within the wp system, not mooving about. πHmm. This way I would be kinda able to design the CPT template visually in the coresponding block element with GP, but then insert it anywhere I want via the shortcode.
Thanks so much.
Best,
EOctober 15, 2021 at 7:23 am #1964337DavidStaffCustomer SupportGlad to be of help.
And thanks for the 5 stars !! much appreciated.
October 26, 2021 at 8:01 pm #1977075NoisyHi,
You can also take a look at PostX. It allows you to display different kinds of posts (and CPT) grids that are quite customizable (with plenty of query settings).
But well, if you want to keep a low number of plugins, definitely go with David’s suggestion.
February 2, 2022 at 4:09 am #2102514GaryHi David
Sorry picking this thread up again as I’m using your solution on a site I’m building currently as stop gap until the query block arrives. I’m using the code snippet you shared above to output a custom post type listing for some FAQs on some pages.
I’ve added the code snippet via the Snippets plugin and created a block element content template assigned to the custom hook in the snippet, but the content template isn’t being output.
I can see the rest of the code from the shortcode is though so I know the shortcode has registered OK and is working.
If I have the above snippet activated and the block element registered to the correct custom hook which I appear to shouldn’t it just work? By the way I’ve also set the display rules for the element to entire site, so I don’t think it is that either. Not sure if I’ve missed a step somewhere?
Any help would be much appreciated.
Thanks
February 2, 2022 at 4:43 am #2102539DavidStaffCustomer SupportHi there,
the code snippet works for the standard Posts, you would need to update the query args in that snippet to include your custom post type.
March 3, 2022 at 7:46 am #2140822LucyJust dropping in to say a big “thanks” for this solution, David! Exactly what I needed.
For anyone that doesn’t want to deal with the code, the plugin mentioned on this thread, PostX, is a good one with lots of flexibility.March 3, 2022 at 7:54 am #2140999DavidStaffCustomer SupportHi Lucy – thats really kind of you – glad it was of use π
-
AuthorPosts
- You must be logged in to reply to this topic.