Skip Navigation

[Resolved] Dynamic Layouts Theme integration

This thread is resolved. Here is a description of the problem and solution.

Problem:
How can I integrate Layouts in my theme without destroying the Theme's native Loop?

Solution:
Integrating Layouts to your Theme the way elaborated in the DOC below, will remove the Theme's Loop and let you customise the Theme with Layouts ONLY.
You will not be able to view the customised Template anymore with your Theme's Loop.

An Agile approach is to wrap the Theme's Loop in a conditional and call Layouts only if desired.

This will allow you to use EITHER Layouts OR your theme's Loop.

The Function that does this looks like this:

//If Layouts is active and an Layout is assigned to a Post Type (rendered by this template), use Layouts
if ( defined( 'WPDDL_VERSION' ) && is_ddlayout_assigned() ) {
  get_header( 'layouts' ); //Optional call to a header-layouts.php template
    the_ddlayout( 'page-default' ); // Loads the 'page-default' layout by default(can be empty)
  get_footer( 'layouts' ); //Optional call to a footer-layouts.php template
}
     
// if not, use the normal WP/Theme loop
else {
//Here goes your Current Theme's Loop
}; // If Layouts are enabled (close the IF)

Relevant Documentation:
https://toolset.com/documentation/user-guides/layouts-theme-integration/

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

Last updated by FedericoI4663 7 years, 10 months ago.

Assisted by: Beda.

Author
Posts
#403675
category_Page.jpg

I am trying to integrate Layouts as described in you page https://toolset.com/documentation/user-guides/layouts-theme-integration/

But the code in my theme page index.php includes category.php where the 'while ( have_posts() ' executes more than 100 lines of code. So my impression is that replacing this will screw the theme.
(see attached img)

Could you please help ?
Many thanks - federico

#403755

Integrating Layouts to your Theme the way elaborated in the DOC you link to, will remove the Theme's Loop and let you customise the Theme with Layouts ONLY.
You will not be able to view the customised Template anymore with your Theme's Loop.

I rather suggest an Agile approach.

This will allow you to use EITHER Layouts OR your theme's Loop.

For this to work, we need a little more effort in PHP and check if Layouts Plugin is active, and if a layout is assigned to your Post Type.

The Function that does this looks like this:

//If Layouts is active and an Layout is assigned to a Post Type (rendered by this template), use Layouts
if ( defined( 'WPDDL_VERSION' ) && is_ddlayout_assigned() ) {
  get_header( 'layouts' ); //Optional call to a header-layouts.php template
    the_ddlayout( 'page-default' ); // Loads the 'page-default' layout by default(can be empty)
  get_footer( 'layouts' ); //Optional call to a footer-layouts.php template
}
    
// if not, use the normal WP/Theme loop
else {
//Here goes your Current Theme's Loop
}; // If Layouts are enabled (close the IF)

This is a more advanced approach but much more flexible and clean.

#404764

Thanks Beda,

it works but does not solve my issue, i found other problems with this theme and i am evaluating to change it for something more compatible with Toolset

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