php - Single Custom Wordpress Child Page -


i have 5+ blogs manage , i'm trying make page layout little more efficient updates. each blog, have 5-6 custom pages same code, except content area. example of i've written already.

(sorry length, trying thorough on background here)

<?php   /* template name: contributors page */  get_header(); ?>  <div id="main-content">     <div class="container">         <div id="content-area" class="clearfix">             <div id="left-area">                 <?php include 'content-contributors.php'; ?>             </div> <!-- #left-area -->              <?php get_sidebar(); ?>         </div> <!-- #content-area -->     </div> <!-- .container --> </div> <!-- #main-content -->  <?php get_footer(); ?> 

this code standard on custom pages except include link.

for example, use line <?php include 'content-contributors.php'; ?> call following file:

<?php   // users, display in alphabetical order $allusers = get_users('role=contributor&orderby=display_name&order=asc&exclude=');  $users = array();  // remove subscribers list won't write articles foreach($allusers $currentuser) {     if(!in_array( 'subscriber', $currentuser->roles ))     {         $users[] = $currentuser;     } }  ?>  <section class="author-content" role="main"> <!-- insert content here --> </section> 

since repetitive when updating upwards of 20-30 pages, wanted shrink down 1 custom page per blog. here's tried:

<?php   /* template name: custom page */  get_header(); ?>  <div id="main-content">     <div class="container">         <div id="content-area" class="clearfix">             <div id="left-area">                 <?php include get_stylesheet_directory_uri() . '/includes/inc-page-content.php'; ?>             </div> <!-- #left-area -->              <?php get_sidebar(); ?>         </div> <!-- #content-area -->     </div> <!-- .container --> </div> <!-- #main-content -->  <?php get_footer(); ?> 

here i've replaced original include <?php include get_stylesheet_directory_uri() . '/includes/inc-page-content.php'; ?> , calls file:

<?php     if ( is_page( 'archives' ) ) {         echo "include get_stylesheet_directory_uri() . "'/content-archives.php'";     }     elseif ( is_page( 'contributors' ) ) {         echo "include get_stylesheet_directory_uri() . "'/content-contributors.php'";     }     elseif ( is_page( 'subscribe' ) ) {         echo "include get_stylesheet_directory_uri() . "'/content-subscribe.php'";     }     elseif ( is_page( 'sitemap' ) ) {         echo "include get_stylesheet_directory_uri() . "'/content-sitemap.php'";     }     elseif ( is_page( 'tags' ) ) {         echo "include get_stylesheet_directory_uri() . "'/content-tag_cloud.php'";     }     elseif ( is_page( 'thankyou' ) ) {         echo "include get_stylesheet_directory_uri() . "'/content-thankyou.php'";     }      else {         // nothing     }  ?>  

unfortunately nothing happens. i've looked on code , thought made sense. simple fix. maybe i'm over-complicating things.

appreciate help. thanks!

get_stylesheet_directory_uri() returns stylesheet uri (url) - can't include php-file through url (actually can in cases, very should).

you should use get_stylesheet_directory() instead.

also, @clyff pointed out, don't wrap include statements in echo statements - doing turning them strings (and what's more syntax in lines way off, quotes don't add up, i'm surprised if don't fatal errors...?)

to include file theme root this:

include get_stylesheet_directory() . '/content-thankyou.php'; 

...or if in file in theme root, should do:

include 'content-thankyou.php'; 

btw don't see reason include file purpose include other files. if understand trying do, can put whole thing in custom template:

<?php   /* template name: contributors page */  get_header(); ?>  <div id="main-content">     <div class="container">         <div id="content-area" class="clearfix">             <div id="left-area">                 <?php                 if ( is_page( 'archives' ) ) {                     include 'content-archives.php';                 } elseif ( is_page( 'contributors' ) ) {                     include 'content-contributors.php';                 } elseif ( is_page( 'subscribe' ) ) {                     include 'content-subscribe.php';                 } elseif ( is_page( 'sitemap' ) ) {                     include 'content-sitemap.php';                 } elseif ( is_page( 'tags' ) ) {                     include 'content-tag_cloud.php';                 } elseif ( is_page( 'thankyou' ) ) {                     include 'content-thankyou.php';                 } else {                     // nothing                 }                 ?>             </div> <!-- #left-area -->              <?php get_sidebar(); ?>         </div> <!-- #content-area -->     </div> <!-- .container --> </div> <!-- #main-content -->  <?php get_footer(); ?> 

Comments