Siteorigin panels for content templates / widget areas.
-
I feel like the WordPress sidebars/widgets functionality can be very limiting. I really want to be able to layout the content in widget areas like you do with content in siteorigin’s panels.
So what I did was define a content type called “Content Templates” and then a simple function to render that content. A perfect example is in the footer. Sometimes I want multi-row footers and there are so many possible layouts that it is a pain and/or takes custom coding for every different layout.
I am using Roots theme, but it should work with most any theme footer instead of using a side bar.
Below is some example code. Please tell me what you think. I am know there are tons of reusable content type plugins already out there but I figure using site-origins for this too would be a good way.
Custom Post Type
First create custom post type called “Content Template”add_action('init', 'cptui_register_my_cpt_content_templates'); function cptui_register_my_cpt_content_templates() { register_post_type('content_templates', array( 'label' => 'Content Templates', 'description' => 'These are templates used for autogenerated pages and other pages that.', public' => true,'show_ui' => true, 'show_in_menu' => true, 'capability_type' => 'post','map_meta_cap' => true,'hierarchical' => true,'rewrite' => array('slug' => 'content_templates', 'with_front' => true), 'query_var' => true,'exclude_from_search' => true, 'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes','post-formats'), 'labels' => array ('name' => 'Content Templates','singular_name' => 'Content Template', 'menu_name' => 'Content Templates', 'add_new' => 'Add Content Template','add_new_item' => 'Add New Content Template', 'edit' => 'Edit', 'edit_item' => 'Edit Content Template', 'new_item' => 'New Content Template','view' => 'View Content Template','view_item' => 'View Content Template','search_items' => 'Search Content Templates','not_found' => 'No Content Templates Found','not_found_in_trash' => 'No Content Templates Found in Trash','parent' => 'Parent Content Template', ) ) ); }
Render Content Template Function
function the_content_template( $slug ){ $my_query = new WP_Query( array( 'post_type' => 'content_templates','name' => $slug ) ); if ( $my_query->have_posts() ) { while ( $my_query->have_posts() ) { $my_query->the_post(); the_content(); } } wp_reset_postdata(); }
Call content template instead of sidebar/widget area
Footer.php instead of
<?php dynamic_sidebar('sidebar-footer'); ?>
use
<?php the_content_template('footer'); ?>
Create content
In admin create a “Footer” Content Template to layout the footer however you want.
- The topic ‘Siteorigin panels for content templates / widget areas.’ is closed to new replies.