Skip Navigation

[Resolved] Displaying a checkbox field as radio buttons in the view template

This support ticket is created 2 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 – 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 7 replies, has 2 voices.

Last updated by johnC-13 2 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#2319689

Tell us what you are trying to do?
Display the values for a checkbox custom field as bulleted list.

Is there any documentation that you are following?
I could not locate any.

Is there a similar example that we can see?
The Content Template contains the following reference to the checkbox field:
[types field='areas-of-practise'][/types]

What is the link to your site?
hidden link

"Areas of Practise" at bottom of page.
May need to whitelist your IPS for you to access it since this is a staging site.

#2319957

Shane
Supporter

Languages: English (English )

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

Hi John,

Thank you for getting in touch.

In order to do this we will need to use a custom shortcode to parse the values and then display it as list.

Essentially what you'll be doing is taking each of the value and compiling it into an html list.

If you're familiar with how to write php code then you can use the tool below to generate the custom shortcode.
hidden link

If you're not comfortable at taking a go at it then i'll be more than happy to assist.

Please let me know if this help.
Thanks,
Shane

#2319961

Hi Shane,

Would you be so kind as to assist in generating that shortcode?

Thanks.

John

#2319973

Shane
Supporter

Languages: English (English )

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

Hi John,

Add the following to your Toolset custom code settings at Toolset->Settings->Custom Code. Once you've done this please ensure that you've activated it.

// Add Shortcode
function checkbox_list( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'list' => '',
		),
		$atts
	);

	$checklist = "<ul>";
	$arrs = explode(',',$atts['list']);
	foreach($arrs as $arr){
	    $checklist .= '<li>'.$arr.'</li>';
	}
	$checklist .="</ul>";
	return $checklist;

}
add_shortcode( 'checkbox_list', 'checkbox_list' );

Here is an example usage.

[checkbox_list list="[types field='areas-of-practise'][/types]"]

Please let me know if this helps.
Thanks,
Shane

#2319977

Thanks Shane,

And just to confirm ... this will output the checkbox list selections/values (The ones we assign when editing a record in Toolset).... as a ordered list when we output it to the Content Template. Correct?

John

#2320005

Shane
Supporter

Languages: English (English )

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

Hi John,

That's correct.

However the display will be like bullet points instead of numbers.

Is it that you wanted them to be listed with the position number beside them like below?

1. Value 1
2. Value 2
3. Value 3

If so then all you need to do is to change the

    and the

to <ol> and </ol> respectively.

Thanks,
Shane

#2320615

Thanks again Shane! Great support!

#2320617

My issue is resolved now. Thank you!