Skip Navigation

[Resolved] Conditional output without repeating headers

This support ticket is created 7 years, 3 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 2 replies, has 2 voices.

Last updated by rusty 7 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#569742

I have a job listing board on the site I'm building. There are jobs available in multiple states, and I'd like to have them listed by state with the state name at the top, but only if there are job posts for that state. If there are no jobs listed for a state, then don't show the state title.

The idea is to show a header that displays the state the jobs are available in, but show no header if there are no jobs in that state. For example, if I have jobs posted in Arizona and Nevada, but no jobs posted in California, I'd like to see:

ARIZONA

Job Title
Company
City, State, Zip

Job Title
Company
City, State, Zip

NEVADA

Job Title
Company
City, State, Zip

Job Title
Company
City, State, Zip

I've tried creating a conditional output based on a custom field called "state":

[wpv-conditional if="( $(wpcf-state) eq 'NV' )"]
<h3>Nevada</h3>
(My job listing content template shows title, company, city, state, zip as shown above)
[/wpv-conditional]

This works ok, but if I include the state at the top as shown, the state shows above every job, which is what I would expect because it's looping through the content template for each job that has Nevada listed as the state.

Is there a way to show the state at the top of the listings one time as shown above without having to create a separate view for each individual state? For example (pseudocode), "If there are posts where wpcf-state = NV, display <h3>Nevada</h3> at the top, then loop the posts where wpcf-state = NV below."

#569764

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hello,

Thank you for contacting our support forum.

It seems you are hardcoding the state into the view.

Why not create the states as taxonomies and then do a setup like the one in our documentation below.
https://toolset.com/documentation/user-guides/using-a-child-view-in-a-taxonomy-view-layout/

Thanks,
Shane

#570546

BRILLIANT! Works perfectly! Thanks a million Shane!