Skip Navigation

[Resolved] Random post with conditional

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to show one random post, but sometimes the results are empty.

Solution: It's best to avoid using conditional HTML in a View's loop output area. Instead, add the condition to your View's Query Filter. This will help make the number of results consistent.

This support ticket is created 6 years, 9 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by shenom 6 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#627853

Tell us what you are trying to do?

As You can see here - we have a section that´s called 'HERAUSGEPICKT'. What´s a kind of 'Shop of the month'.

hidden link

This is currently 'handmade'. What we trying to archive is to make this part filled with the content of posts / shops - randomly output a shop with every visit a user make.

What way would You recommend? We build up a content template with Fusion Builder - but that don´t seems the way.

We could build it up without the Fusion Builder to have more HTML access - but the whole random part would be still missing.

Is 'Views' the way to go? We already use the random listing - but it seems more for list output or more then one item listing.

Best / Sascha

#628121

Hi, a View is still the best way to accomplish this. Within the View editor screen, there is a "Limit and Offset" section that allows you to configure how many results should be displayed. You can set the limit to 1 and use the random order feature to display a random, single post. If you are unable to see the "Limit and Offset" section in the View editor, scroll up to the top right corner and click "Screen Options." You can turn sections on or off from this panel.

#628370

Hi Christian.

Thank You. Already set it up in a raw way that works - as You can see here : hidden link

The second row is the one with the dynamic stuff. If You refresh it - You see the change. We used the Content Template we already set up.

Is it right, that there isn´t a way to use the Toolset shortcodes in Fusion Builder sections like 'URL' i.e. for buttons. I show it here:

hidden link

hidden link

So in the end parts like photos with preset effects (zoom) from Fusion Builder or Buttons must be done by 'hand'?! Or do YOu know another way?

Thank You

#628505

I don't think Fusion Builder accepts shortcodes in the Button URL field. You could try to recreate the button in a text module, then replace the URL with a shortcode. First place a hard-coded URL like http://google.com in the Button URL. Open the browser console and go to the front-end of the site to see the button. Inspect the markup on the front-end of the site. Copy the markup for the button module and insert it in a text module, and replace the google.com URL with the shortcode.

#628653

Hi.

Thought in the same direction - but Fusion Builder don´t like that. Doing strange things after pasting the code in a text field.

I´ll get in touch with theme fusion and check if they think about open up their modules for shortcodes.

One last thing. In the final stage we just want to show a random shop that is marked as 'Premium'. We did a checkbox and used a conditional output in the the views editor:

[wpv-conditional if="( $(wpcf-premium) eq '1' )"][wpv-post-body view_template="Shop Pick"][/wpv-conditional]

3 Shops are marked as 'Premium'. But that seems somehow to 'simple'. No output is generated. Another advice would be very welcome!

hidden link

Thank You!

#628888

You should remove the Premium conditional and add another item to the Query Filter. The way you have it configured now, the Query Filter will return only one result, regardless of Premium or not Premium. If that one result is not "Premium" then nothing will be shown because of the conditional HTML. Add the "Premium" criteria to the View's Query Filter instead.

#628896

Hi.

That´s it! I choosed this to be my query filter setting : Premium ist ein/e DECIMAL with 1 decimal places gleich 1

If that´s how You would go as well - cool. If You say there is a smarter setting - it´s welcome.

Thx again!