Navigation überspringen

[Gelöst] Adding a class to button when a certain condition is false

This support ticket is created vor 4 Jahren, 4 Monaten. 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/Karachi (GMT+05:00)

Dieses Thema enthält 22 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von AlimB3245 vor 4 Jahren, 4 Monaten.

Assistiert von: Waqar.

Author
Artikel
#1763427

Hi Waqar

It was my mistake I had the [wpv-item index=last] after the opening [wpv-conditional] tag.. fixed it.. and it's fine

[wpv-layout-start][wpv-items-found]<!-- wpv-loop-start --><wpv-loop>[wpv-item index=other][wpv-conditional if="( '[types field='id' output='raw'][/types]' ne '' )"][types field="id" output="raw"][/types],[/wpv-conditional][wpv-item index=last][wpv-conditional if="( '[types field='id' output='raw'][/types]' ne '' )"][types field="id" output="raw"][/types][/wpv-conditional]</wpv-loop><!-- wpv-loop-end -->[/wpv-items-found][wpv-no-items-found][/wpv-no-items-found][wpv-layout-end]

the style code is not being displayed as html now.. but the effect of the style code (one of the button to be hidden) is not happening..

Regards,
Alim

#1763973

Hi Waqar

I had a suggestion..

If you are using the conditional code to change the style to display or not.. why don't we simply use the conditional code to display or hide..

I mean if we use 2 conditional containers and show and hide, wouldn't it be much easier?

Please do advise and resolve... also the styling issue is also a bit nagging.. would appreciate a quick resolution as the site is live..

Regards,
Alim

#1764035

Thank you for sharing these updates.

The structure of blocks is different in this content template, as compared to the one for the brand owners.

For this content template, you'll need to update the CSS code accordingly too:


<style>
.wp-block-columns .wp-block-column .tb-button.shop-online-button,
.wp-block-columns .wp-block-column .tb-button.optician-no-brands {
display:none;
}
</style>

[wpv-conditional if="( '[wpv-view name='related-optician-eyewear-brand-brand-ids']' ne '' )"]
<style>
.wp-block-columns .wp-block-column .tb-button.shop-online-button {
display:block !important;
}
</style>
[/wpv-conditional]

[wpv-conditional if="( '[wpv-view name='related-optician-eyewear-brand-brand-ids']' eq '' )"]
<style>
.wp-block-columns .wp-block-column .tb-button.optician-no-brands {
display:block !important;
}
</style>
[/wpv-conditional]

Note: To check which CSS code is applying to different page elements, you can use Google Chrome's inspect element tool, as explained in this guide:
versteckter Link

As for directly using the conditional block, it is possible but will require a custom shortcode as the view's shortcode output can't be used in a conditional block.

You'll first register a custom shortcode that will get the view's output and returns 1 if it is not empty and 0 otherwise.

Example:


add_shortcode('output_view_check_optician', 'output_view_check_optician_fn');
function output_view_check_optician_fn() {
	$content = do_shortcode("[wpv-view name='related-optician-eyewear-brand-brand-ids']");

	if(!empty(trim($content))) {
		return '1';
	}
	else
	{
		return '0';
	}
}

Next, please add "output_view_check_optician" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.

After that, you can add two conditional blocks, one to show each button and then this new shortcode will be available in the list of conditional checks.

As for the button background colors, I tried to save the background settings and the issue with the header slider returned once the content template was saved.

Can you please share some details about how are you adding this slider, so that I can investigate this issue on my test website.

For now, you can fix the slider block again and use some custom CSS code, to apply black background to both buttons:


.wp-block-columns .wp-block-column .tb-button.shop-online-button a.tb-button__link,
.wp-block-columns .wp-block-column .tb-button.optician-no-brands a.tb-button__link {
background-color: rgba( 0, 0, 0, 1 );
}

#1764087

Hi Waqar

The Slider issue seems resolved .. it was not actually the slide but the conditional code that was changing the greater than sign to some text value everytime.. but now it looks like it's ok

I've added the CSS to change the background to black.. seems to be fine.. thanks..:-)..

Now one button is visible but it's the button where the condition below is being met
[wpv-conditional if="( '[wpv-view name='related-optician-eyewear-brand-brand-ids']' ne '' )"]
even if there are no brand ids
versteckter Link
for example this optician has brand is as you can see the eyewear brands visible

but this optician has no brands and should have shown the other button
versteckter Link
but it's showing the same button.. so somewhere the view is never NULL I guess.. could you please check the VIEW and confirm this please?

Regards,
Alim

#1765013

Thanks for the update and glad that the slider is fixed.

I noticed that some extra spaces were becoming part of the "Related Optician Eyewear Brand Brand IDs" view's output, which was putting off the "empty" conditional check.

I've removed the "[wpv-filter-meta-html]" shortcode from the view's "Output Editor" section and those empty spaces are removed from the output and the conditional check seems to be working, for both cases.

#1765023

Hi Waqar,

Thanks for your patience and efforts.. really appreciate it..:-)..

I just need some advise before I mark this ticket as resolved.. I am happy with the 'style' approach you've taken and as long as it works I am happy.. but going ahead would the display based on condition approach be better? I mean more solid.. because if I add some block or change the class or something the styling that's targeting the button could change and then it would not work .. right?
I just want to confirm if I am thinking right..

And also I am launching the pilot project soon..in a couple of days..;-).... and I just wanted to thank you and the toolset team who have been super super super helpful and have helped me create this application...:-)..

Thanks again and have a nice day..:-)..

Regards,
Alim

#1765087

Thank you so much for your kind words and glad I could help 🙂

It is great to know that you find our products and services useful and we'll do our best to meet the expectations in the future as well.

You're thinking on the right lines and if I'd have to choose between the custom CSS approach or the custom shortcode inside the conditional block, I'd go with the latter one, as it would be more stable in a long run.

#1765145

My issue is resolved now. Thank you!