Skip Navigation

[Résolu] Display a Content Template with PHP

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
How can I display a Content Template with PHP?

Solution:
You can use the Views API

render_view_template

Example:

echo render_view_template('80', $mypost));

Relevant Documentation:
https://toolset.com/documentation/user-guides/views-api/

100% of people find this useful.

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 3 réponses, has 3 voix.

Last updated by benjaminJ-3 Il y a 7 années et 4 mois.

Assisted by: Beda.

Auteur
Publications
#460712
uk3.jpg
uk2.jpg
uk1.jpg

I am trying to: insert a view or post body in header content template

I visited this URL: local development

I expected to see: screenshot UK2.jpg

Instead, I got: no page content, just duplicate header. Same happens if I insert post body via shortcode.

My content template code

<div class="bblue">
<div class="container pt-2">
<div class="row">
<label for="show-menu" class="show-menu"><div class="mmenu acenter"><img src="/wp-content/uploads/Mobile-menu.jpg" alt="Mobile menu" width="44" height="40" class="size-full" /></div></label>
<input type="checkbox" id="show-menu" role="button">
[listmenu menu=shopmenu]
</div>
</div>
</div>

<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-3 col-md-3 acenter">left-menu</div>
<div class="col-xs-12 col-sm-9 col-md-9">[wpv-view name="banner"]</div>
</div>
</div>

It doesn't depend on view code as it happens with empty view as well. Same with post body. In example if I will put code below it results in screenshot uk3.jpg

<div class="bblue">
<div class="container pt-2">
<div class="row">
<label for="show-menu" class="show-menu"><div class="mmenu acenter"><img src="hidden link" alt="Mobile menu" width="44" height="40" class="size-full" /></div></label>
<input type="checkbox" id="show-menu" role="button">
[listmenu menu=shopmenu]
</div>
</div>
</div>

<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-3 col-md-3 acenter">left-menu</div>
<div class="col-xs-12 col-sm-9 col-md-9">[wpv-post-body view_template='None' id='13']</div>
</div>
</div>

#460802

Content Templates replace the_content() part of your Templates, and headers are usually a separate File, called way previously to the_content() in a WordPress theme.

You can not create a whole page template with a Content Template.

Your theme has to deliver the header, body and footer.

In the Body, it will call the_content() and that is the part that usually displays your Post Content.
This can be styled and altered with Content Templates.

To achieve what you need you either need to use PHP can call the View/Content Template in your header.php file with PHP, or integrate Layouts in your Theme and construct the Page templates with that Plugin.
https://toolset.com/documentation/user-guides/layouts-theme-integration/
https://toolset.com/documentation/user-guides/views-api/

Please let me know if you need help with this.

#460896

Thank you ! You saved my day! I was inserting content template with shortcode

<?php do_shortcode('[wpv-post-body view_template="header"]'); ?>

Now everything works perfectly!

#1237211

The answer/solution at the top of this page has an extra right bracket ")" on the right hand side.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.