I have 5+ blogs that I manage and I'm trying to make the page layout a little more efficient for updates. For each blog, they have about 5-6 custom pages with generally the same code, except for the content area. This is an example of what I've written successfully already.
(sorry for the length, trying to be thorough on the 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 would be standard on all custom pages except for the include link.
For example, I would use the line <?php include 'content-contributors.php'; ?>
to call the following file:
<?php
// Get all users, display in alphabetical order
$allUsers = get_users('role=contributor&orderby=display_name&order=ASC&exclude=');
$users = array();
// Remove subscribers from the list as they won't write any articles
foreach($allUsers as $currentUser)
{
if(!in_array( 'subscriber', $currentUser->roles ))
{
$users[] = $currentUser;
}
}
?>
<section class="author-content" role="main">
<!-- insert content here -->
</section>
Since this would be very repetitive when updating upwards of 20-30 some pages, I wanted to shrink this down to one custom page per blog. Here's what I 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 the original include with <?php include get_stylesheet_directory_uri() . '/includes/inc-page-content.php'; ?>
and calls this 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 {
// do nothing
}
?>
Unfortunately nothing happens. I've looked over my code and thought it made sense. Hopefully this is a simple fix. Maybe I'm over-complicating things.
Appreciate any help. Thanks!