Skip Navigation

[Gelöst] Adding content from other pages or posts to the layout

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
The user created a layout for a post but wanted to display some content from another post

Solution:

The solution is that each of our shortcodes for e.g [types field='some-field'][/types] allow for you to pass an ID into it.

So if the post that you want to display has an id of 4 then you can pass the ID 4 into the shortcode like this.
[types field='some-field' id='4'][/types] this will allow you to display the information from that post.

This support ticket is created vor 7 Jahren, 1 Monat. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 21 Antworten, hat 3 Stimmen.

Zuletzt aktualisiert von benH-6 vor 7 Jahren.

Assistiert von: Shane.

Author
Artikel
#576492

I want to add a single piece content from a specified posts or page into my layout. I'm working round this by adding a "visual editor" and placing content in that, but I'd like to be able to include content from another page, (so that others can just edit the page, and change the content)

I've tried using "Post Content" cell, but that seems like something else? Also I've tried using content template, but that seems, very confusing, doesn't work for me, and makes my woocomerce product archive view go very. Is there a simple way I can add content from another post? I'm sure I'm missing something ovbvious

Many thanks for any pointers.

#576659

Shane
Supporter

Sprachen: Englisch (English )

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

Hi Ben,

Thank you for contacting our support forum.

This isn't natively possible unless the posts are in some Parent/Child relationship. Is the content within the same CPT or is it from different CPT.

Also how would your template know which content to be loading.

Please let me know as we may be able to resolve this with a small snippet of code.

Thanks,
Shane

#576661

Hi Shane.

Ok I assumed you'd somehow tell the content template cell, or whathaveyou, that you want to load say the body (or other field) of a certain post/page.

from the description of Content Template Cells..."One of the most prominent features of this cell is that it allows you to show contents of any page or post. A layout can include any number of Content Template cells, which show various fields for different content."

I'm guessing this somehow means something else than what I imagined, i.e. you could show the content of any page or post!

Ok, I'll try and find some other way round this, maybe I'm looking at it the wrong way round somehow, I'll start my thinking again.

Thanks for your help..

Ben

#576672

Shane
Supporter

Sprachen: Englisch (English )

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

Hi Ben,

What you can do is to add a visual editor cell and then add the shortcode for the content you want to display to the visual editor and then pass the ID of that post into the shortcode.

Example
[wpv-post-body id='2048']

This will display the body content of the post with ID 2048 even if you are on post 1000.

Please let me know if this clears things up a bit.

Thanks,
Shane

#577090
Toolset_Layout_behaviour.png

Ok, so I've been trying this with very odd and erratic results. At first I thought I was making mistakes, then It seemed row order in my layout had some part to play, but to be honest I'm not sure. I rearranged the rows to at least provide a regular repeatable result.

Using your example code above ( I used [wpv-post-body id='1' ]in a visual editor above my archive loop row (this all in layouts). Front end now displays the content of the hello-world post at the top of my wc archive pages, this works for pages too.

However without having made any changes to my lower bootstrap woocomerce archive rows, they are now affected by the shortcode you provided. To the extent all shop items are listed only by their post-body, no imgaes, extra fields,etc. It's like its been totally overwritten by this one piece of shortcode in the visual editor What gives? Is this a bug? Why would a visual editor row make any difference to the rows below? As soon as I remove the shortcode, all returns to normal.

It seems crazy. Is this expected behaviour? Any ideas?

Ben
x

#577364

Shane
Supporter

Sprachen: Englisch (English )

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

Hi Ben,

Would you mind providing me with admin access to the website so that I can have a more detailed look at this for you ?

The private fields will be enabled for your next response.

Thanks,
Shane

#577435

Shane
Supporter

Sprachen: Englisch (English )

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

Hi Ben,

I see the issue.

Maybe we can work around this issue with a custom shortcode but you will need to let me know which field you want the content to be pulled from.

Thanks,
Shane

#577449

Ok, that's great.

It would useful to know what the problem is. Seems a lot more tricky than I was expecting for a relatively straight forward operation.

Are there any fields that the info can't be pulled from? Maybe if you could set it to pull info from the body of a post that would be the most helpful for now. If it uses post-id's then I can just copy/paste/re-use, yes?

Thanks Shane.

#577459

Shane
Supporter

Sprachen: Englisch (English )

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

Hi Ben,

You can use the shortcode below.
[post_content id='1']

All I did was to use the basic and default wordpress function to get the content.

I would need to investigate this issue further and forward to our development team but this should allow you to achieve what you want 🙂

Thanks,
Shane

#577481

Ok, that's great. And frustratingly simple! Thanks for seeing it through though.

Just while I'm here, and is there a similar simple code to display the description of a custom taxonomy or category, when viewing that taxonomy or category's archive page. (in my current the most imminent use would be a brief description of each category, above the items within that category) Is this something else that could cause the problems experienced earlier?

#577680

Shane
Supporter

Sprachen: Englisch (English )

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

Hi Ben,

I'm happy I was able to help.

You can actually use this https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-taxonomy-description

Please let me know if this helps.

Thanks,
Shane

#578754

So, I haven't implemented this bit yet, as I'm still recovering from the last confusion! But the link you gave, only states the code can be used in the context of a view. So I'll try that later.

Was this maybe the problem with the first code you gave me? that it should only be used in a view? rather than in a visual editor. Or was this a bug? You said you needed to get a response from the development team, did they get back on this?

It'd be good to know so as to restore my confidence in the layout system.

#579003

Hi Shane,

Actually this isn't resolved at all.

I didn't think to test your solution fully, my bad. Because it was showing the content for post id 1, I assumed your code worked. but it doesn't work at all as far as I can tell. But I'm guessing you didn't test it either.

Your solution:

"You can use the shortcode below.
[post_content id='1']"

This within a visual editor.

However, no matter what the post id number, the result is always the same, the content of post id 1 is displayed on the front end. Even removing the id part of the shortcode completely, still does the same thing, i.e. shows the content of post id1 on the front end..

What is going on? I don't mean to be rude in anyway, but the support here has been weird. Solutions that break entire archive loops, and now another one that doesn't actually work. I'm losing my confidence greatly here.

Please could I request a different member of the support team look at this? Is that possible without causing problems?

Thanks,

Ben

#579188

Hi, Shane is out today but will return tomorrow with an update on your question. Thanks for your patience.

#579604

Shane
Supporter

Sprachen: Englisch (English )

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

Hi Ben,

I tried taking another look at this to see whats going on but it seems that you removed admin privileges from the account.

Could you make it an admin account so that I can have another look as using the another ID should work since the shortcode is using the wordpress basic function and just passing an ID to it.

Thanks,
Shane