Skip Navigation

[Resolved] Alternating View Layout

This support ticket is created 3 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 12 replies, has 3 voices.

Last updated by JoelK2744 3 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#1956199

Hello, I'm trying to create a view using Blocks that has a repeating alternating layout...

1st (odd) item: 2 columns. 1st column image, 2nd column post title

2nd (even) item: 2 columns. 1st column post title, 2nd column image

Etc...

It's similar to this post - https://toolset.com/forums/topic/use-blocks-editor-to-create-view-with-alternating-template-for-odd-even-items/ - which suggests it isn't possible with Blocks. Is that still the case? If so how (and where) do you create a content template in the block editor and then use it within a legacy view? Is there any documentation on this?

Thanks

#1956529

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

It's correct that there isn't support for this yet in Blocks (there are workarounds using the conditional block and custom code, possibly not worth it).

If you go to Toolset > Settings, make sure that both the Blocks and Legacy UIs are available, and have Content Templates use the block editor by default.

Then to to Toolset > Content Templates and create two templates, one for each variant of the output you want.

Then go to Toolset > Views and create your View with the legacy editor. In the Loop Output section you'll insert the templates (use the Fields and Views button), and then add the wpv-item shortcode to determine when each template should be used (one with item=odd and the other with item=even).

https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-item

#1956665

That's great, thanks Nigel. It seems combining block templates with legacy views is really powerful.

I actually found a css solution in the end which is a bit of a cheat using :nth-child(even) and flex-direction: row-reverse - it seems to do the job but I'm glad there's also the option to mix block templates and legacy views as I'm sure I'll end up using that anyway!

Thanks again

#1956741

Actually...my CSS doesn't work quite as well as I was hoping. It does work but the Toolset specific styling gets lost on the frontend, I think because I'm using a GenerateBlocks grid container for the view. I don't suppose there is any news on better Toolset integration with GenerateBlocks? I know there's a Toolset Container/Grid but I find the GenerateBlocks options much more flexible.

Thanks

#1956965

Sorry I don't think it does have anything to do with GenerateBlocks.

I've also replicated this in a test environment with default WP 2021 theme.

I've created a view to show latest posts, added a Heading with link to post URL, then added a single field > Category > Link to term archive page - I've styled this with a small font size 12px (I've tried both typography and link typography). When you click update the styling to the font size at first seems to work, but then when you refresh the page it loses the styling and increase the font size to default.

Thanks

#1957145

Sorry one more update!...

I've tried a completely fresh WordPress install with only the default wordpress theme and toolset blocks installed and found the same issue, and the loss of styling isn't limited to the specific example above, I also tried a custom button style and that also gets lost once you refresh the page (or view the page when not logged in). However, the styling remains if the "Cache view" is toggled off but this presumably has performance implications?

#1957873

Hello,

For the new questions:

It does work but the Toolset specific styling gets lost on the frontend ...

It is a known issue, it happens if you save the post/page quickly before WordPress autosave completed, those custom style will lost in front-end when you refresh the page/post.

See similar thread:
https://toolset.com/forums/topic/custom-toolset-styles-for-buttons-disapear-at-first-reload/page/2/#post-1882435

It has been escalated to our developers, but I am not sure when will it be fixed, I have added this thread into our to-do list, and will update here if there is any news.

Currently, you need to save the post/page little slowly, until the WordPress autosave completed

#1958027

Hello, I've tried waiting a long time after saving but the issue persists. This is on a blank local wordpress site with default theme and toolset blocks installed, so easy to replicate. Interestingly if I remove the "Link to term archive page" and just display the category name the styling remains. But the button changes to default styling after one reload no matter how long I leave it to reload.

#1958043

I have tried it in a fresh WP installation + the latest version of Toolset plugins, it works fine if I save the page after WordPress autosave completed.

Please provide a test site with same problem, also point out the problem page URL, private message box enabled.

#1958061

Sorry Luo....I made a mistake in my previous reply, I have tried your method of waiting for the autosave to complete before saving the page and I can confirm that works for the button styling but it still doesn't work for me on the category archive link.

Here is a screen recording - hidden link

Thanks

#1958355

Just in case it helps with testing...with the button styling, it seems that simply adding a ">" after the text ( i.e. Read More > ) breaks the styling on reload. I did this to try and avoid calling up an icon font but it seems to cause the styling to be lost on reload for some reason.

Hopefully better GenerateBlocks integration is on the way as that uses SVG icons so doesn't require a font request.

#1962323

Thanks for the details, I can duplicate the same problem, the style lost even after autosave completed. I have already added this thread into out to-do list.

Currently, you can add a shortcode block, display the Views shortcode directly, for example:

<div style="font-size: 11px;">[wpv-post-taxonomy type="category" separator=", " format="link" show="name" order="asc"]</div>

More help:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-taxonomy

#1962643

Thanks Luo, glad it's been added to the to-do list and thanks for the shortcode workaround