Skip Navigation

[Résolu] Output on frontend not as expected

This support ticket is created Il y a 6 années et 8 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Ce sujet contient 10 réponses, a 2 voix.

Dernière mise à jour par Jas Il y a 6 années et 8 mois.

Assisté par: Nigel.

Auteur
Publications
#623902

Jas
location 3 screenshot.png
location 2 screenshot.png
location 1 screenshot.png
screenshot view.png
custom post fields.png
Dr chanakarn.png

Hi there, once again, a beginner here,

The info that I've added into the custom post type form i've created, isn't displaying correctly on the front end, which seems like it has to be a problem with the content template I've created, but i'm not sure why. The documentation I've viewed seems to address the most common usages, however, i'm creating a directory for doctors, and in the part of the world i'm working in (South East Asia) one individual doctor, will often work out of up to 3 different clinics or hospitals, and each location can require multiple phone numbers etc. When I add additional phone numbers say for the first location, the second phone number for the first location, is getting bumped down so that is displays in the second location spot on the front end (but not in the custom post type form). And then, the second location title, displays again, a second time, for the actual phone number for that location.

Sorry if this is confusing. I've attached some example screenshots to help clarify. I'm happy to give you access to the admin, but a little confused about how to do that. Not sure exactly which password i am to give you etc.

Thanks in advance for your help!

lien caché

#624176

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Hi there

It sounds like you need repeating groups of fields, whereby your custom post type has a group of fields for each location, with the location name, location hours, location phone number(s) etc., and that you can add as many groups of these fields as you have locations.

The new versions of Toolset that are currently in beta add a new UI for repeating fields groups, adding them in the back-end and in CRED forms, which will simplify this, and you can try out the betas on a test site to get a feel for how this will work. You can add repeating field info when editing posts in the back-end, but these have not been added to CRED forms yet, and is likely to take a while.

The current implementation involves creating child posts to act as a container for the related fields.

It is a little cumbersome (hence the work to update it) but is described here: https://toolset.com/documentation/user-guides/creating-groups-of-repeating-fields-using-fields-tables/

Please have a look through that to see if you can implement it and let me know if you run into problems.

#624495

Jas
Dr Chanakarn edit.png

Hi Nigel, Ok, so because I haven't officially launched my site yet (I've published it but have made it private access for now via Ultimate members plugin), I just am working right in main site and not a test site. (Hopefully this is still not a bad idea in this case, for some reason that I am unaware of)?

I created a container post type called Locations via the documentation you pointed me to, and pointed it to its parent Health Services, and then created a new field group with the fields required, linking those to "Locations" post type. In the Single service Health template, (Using the Divi builder option) I didn't want to delete the original info yet, but duplicated what I already had to compare, and in the middle module added the View "locations for doctor". Which gives me all the info, but it isn't laid out the way i'd like it to be. Please see Dr. Chanakarn.png screenshot from original message.
Would it be possible to give you access to the backend so you can see what I've done and why it's not fully working. I tried adding a module before that one for another comparison and just individually entering the individual fields for the field group Location, as it seemed like if I did this, i could customize each individual field better, but this didn't show up on the front end at all.
Thanks for your patience!

#624521

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Let me mark your next reply as private so I can get credentials from you and then I can take a look at your template.

You may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup of your site, even though I don't intend to make any changes, I'll just be looking at your set-up.

#625631

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

I tried to access your site but the password is incorrect.

Could you please check and update the password in the next, private, reply.

#626575

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Screen Shot 2018-03-20 at 11.42.32.png

Hi there

Sorry for the delay getting back to you, it was a long weekend here in Ireland.

The set-up you have is basically correct, but you simply added your fields to the locations View without any kind of formatting, they were not even split onto separate lines (see screenshot).

I edited the View in question, shifting the fields into a separate template to make it easier to edit, and then adding simple heading and paragraph tags to improve the layout.

I also added conditional shortcodes so that fields are only output if they have content, and so where there is no phone extension, for example, it doesn't create an empty line.

#626820

Jas
Dr Somporn front end screenshot.png
Dr Somporn screenshot.png

Thanks Nigel, so that's starting to look a lot better. however this view is still only showing 1 phone number even though I have inputted more into the custom post type fields on the back-end. And hopefully i've added this correctly to make the phone numbers clickable:

[types field='phone' output='raw'][/types]

The one number that shows up, is clickable. If I propagate additional info (notes/ext/hours) into the locations fields of the custom post type, then the additional phone numbers suddenly show up also... and anything i subsequently add to the location of doctors info, also becomes a clickable link, even though i thought i was just making phone numbers clickable so far.... (It would be great for email and website to be clickable too, but maybe not ext. and definitely not notes).

The other thing is that I'd really like is as per very first sreenshot from original message, Dr. Chanakarn.png, I'd like each location to have a header Location 1@, Location 2 @, Location 3 @. Do I have to create a new loop View for each of these then and add it to content template?

Thanks Nigel! Respect to the long weekend!

#627271

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Hi there

I had a small error where I inserted the first conditional shortcode that it was checking the wrong field, which I have now fixed.

The problem with the links was because the first link you inserted was correct, but for the second two you forgot the closing a tags which were "leaking" into other content.

I have added "Location" in the title.

If you want to have Location 1, Location 2, etc. that would require you to register a custom shortcode to count the loop iteration which you could use to generate the number.

I can suggest the code to use, but would only do that if you are comfortable adding some custom code to your site and inserting the shortcode in the required place.

#627604

Jas

THANKS SO VERY MUCH NIGEL!!!! If the code is fairly straight forward and if there is clear documentation to follow, i'd give it a try. However, I don't want you to spend any more of your time if it seems like it would be over my head. At some point in the not-to-distant future, I will likely need to hire someone to help me with this sort of thing. For now, i just wanted to do/learn as much on my own as I could, so that I felt comfortable with the basics before someone took over.

#627706

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

You can register a custom shortcode for this by adding the following to your theme's functions.php file (or using a plugin such as Code Snippets):

/**
 * Add loop-iteration shortcode
 * 
 * Attributes
 * 'n' (optional) : test for nth iteration
 */
add_shortcode( 'loop-iteration', function( $atts ){

	global $loop_n;

	if ( !isset( $loop_n ) ) {
		$loop_n = 0;
		return $loop_n;
	}

	$loop_n++;

	if ( !isset( $atts['n'] ) ) {
		// no nth parameter, just return the current index
		return $loop_n;
	}
	else {
		$remainder = ( $loop_n + 1 ) % $atts['n'];
		return ( $remainder == 0 );
	}

});

Then use the shortcode in the output of a View to show the current iteration, which in your case you would want it to display something like this:

<p>Location @[loop-iteration]</p>
#628308

Jas

Thanks so much Nigel!