Custom sidebars & custom page templates
-
I have posed this question to plugin‘s author, and given that it’s a free plugin I’m not sure if I’ll get an answer. Although my problem is happening with a particular plugin, I don’t believe it’s because of the plugin, and I think this could be a good learning situation for me. Hopefully someone can shed some light.
Someone helped me create two custom page templates. I can tell what’s going on from looking at the PHP, but I don’t really know PHP or have a great comprehension of WordPress’s core yet. My theme has a sidebar for pages, and whatever widget I add here shows on both custom page templates. It works as expected. However, when I use the plugin to create custom sidebars for pages, it works on all of my theme’s original pages (i.e. templates) but not for the two custom ones I added.
Two template-[nicename].php files create my custom page templates. Nothing in any theme file was changed. Am I supposed to add some code somewhere?
-
I’ll update in the hopes that someone can add some insight.
As a test I created a new custom page template by copying an origional theme template. I took template-faq.php (origional template) and renamed it template-test.php. I changed nothing about the file other than it’s name.
I then created a new page using this template. The page inherits the page sidebar as expected. The plugin I’m using to create custom sidebars works on this new custom template.
The thing that is different about my custom template that *isn’t* working with the plugin is the code between <!– Start of Page Container –> and <!– End of Page Container –> (although the <?php get_sidebar(‘page’); ?> is the same).
I don’t understand how the code in the template would cause the sidebar plugin not to work…
Site?
It’s an intranet site. I will paste the code of the custom template though, since it’s this template that isn’t working (I can make a custom template by copying an existing one and just renaming it, and it works).
<?php /* * Template Name: Department Template Created 11/2014 */ get_header(); ?> <!-- Start of Page Container --> <div class="page-container"> <div class="container"> <div class="row"> <!-- start of page content --> <div class="span8 page-content"> <div class="row separator"> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <article id="post-<?php the_ID(); ?>" <?php post_class("clearfix"); ?>> <h1 class="post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1> <hr> <?php if ( has_post_thumbnail() ) { the_post_thumbnail('std-thumbnail'); } the_content(); // WordPress Link Pages wp_link_pages(array('before' => '<div class="pages-nav clearfix">', 'after' => '</div>', 'next_or_number' => 'next')); ?> </article> <?php endwhile; endif; ?> <?php // get the department name's id# (passed through as page name parameter) so as to be able to indclude it in query array $deptname = wp_title('', false); $deptname=trim(strtolower($deptname)); $dept_id = get_cat_ID($deptname); ?> <section class="span4 articles-list" style="margin-left:0;"> <!-- Best Practices ID = 20--> <?php query_posts( array( 'category__and' => array($dept_id,20), 'posts_per_page' => 5, 'show_count' => 1 ) ); $total_posts =$wp_query->found_posts; $myposts = $wp_query->post_count; if ($myposts > 0) { ?> <h3><a href="/portal/?page_id=31?department_id=<?php echo $dept_id; ?>&department_name=<?php echo $deptname; ?>">Best Practices (<?php echo $total_posts; ?>)</a></h3> <?php while (have_posts()) : the_post(); ?> <ul class="articles"> <li class="article-entry standard"><h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4> <span class="article-meta"><?php the_modified_date('F j, Y'); ?> in <?php the_category(', ') ?> </span> <span class="like-count"><?php echo get_total_likes($post->ID); ?></span> </li> </ul> <?php endwhile; } ?> </section> <section class="span4 articles-list"> <!-- Policies ID = 21--> <?php query_posts( array( 'category__and' => array($dept_id,21), 'posts_per_page' => 5, 'show_count' => 1 ) ); $total_posts =$wp_query->found_posts; $myposts = $wp_query->post_count; if ($myposts > 0) { ?> <h3><a href="/portal/?page_id=33?department_id=<?php echo $dept_id; ?>&department_name=<?php echo $deptname; ?>">Policies (<?php echo $total_posts; ?>)</a></h3> <?php while (have_posts()) : the_post(); ?> <ul class="articles"> <li class="article-entry standard"><h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4> <span class="article-meta"><?php the_modified_date('F j, Y'); ?> in <?php the_category(', ') ?> </span> <span class="like-count"><?php echo get_total_likes($post->ID); ?></span> </li> </ul> <?php endwhile; } ?> </section> <section class="span4 articles-list" style="margin-left:0;"> <!-- References ID = 19--> <?php query_posts( array( 'category__and' => array($dept_id,19), 'posts_per_page' => 5, 'show_count' => 1 ) ); $total_posts =$wp_query->found_posts; $myposts = $wp_query->post_count; if ($myposts > 0) { ?> <h3><a href="/portal/?page_id=35?department_id=<?php echo $dept_id; ?>&department_name=<?php echo $deptname; ?>">References (<?php echo $total_posts; ?>)</a></h3> <?php while (have_posts()) : the_post(); ?> <ul class="articles"> <li class="article-entry standard"><h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4> <span class="article-meta"><?php the_modified_date('F j, Y'); ?> in <?php the_category(', ') ?> </span> <span class="like-count"><?php echo get_total_likes($post->ID); ?></span> </li> </ul> <?php endwhile; } ?> </section> <section class="span4 articles-list"> <!-- Recipes ID = 18--> <?php query_posts( array( 'category__and' => array($dept_id,18), 'posts_per_page' => 5, 'show_count' => 1 ) ); $total_posts =$wp_query->found_posts; $myposts = $wp_query->post_count; if ($myposts > 0) { ?> <h3><a href="/portal/?page_id=37?department_id=<?php echo $dept_id; ?>&department_name=<?php echo $deptname; ?>">Recipes (<?php echo $total_posts; ?>)</a></h3> <?php while (have_posts()) : the_post(); ?> <ul class="articles"> <li class="article-entry standard"><h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4> <span class="article-meta"><?php the_modified_date('F j, Y'); ?> in <?php the_category(', ') ?> </span> <span class="like-count"><?php echo get_total_likes($post->ID); ?></span> </li> </ul> <?php endwhile; } ?> </section> <section class="span4 articles-list"> <!-- add new subject area here as needed --> </section> </div> </div> <!-- end of page content --> <?php get_sidebar('page'); ?> </div> </div> </div> <!-- End of Page Container --> <?php get_footer(); ?>I see no way to edit my prior post. If I could I would delete all that code and just paste this portion:
<section class="span4 articles-list" style="margin-left:0;"> <!-- Best Practices ID = 20--> <?php query_posts( array( 'category__and' => array($dept_id,20), 'posts_per_page' => 5, 'show_count' => 1 ) ); $total_posts =$wp_query->found_posts; $myposts = $wp_query->post_count; if ($myposts > 0) { ?> <h3><a href="/portal/?page_id=31?department_id=<?php echo $dept_id; ?>&department_name=<?php echo $deptname; ?>">Best Practices (<?php echo $total_posts; ?>)</a></h3> <?php while (have_posts()) : the_post(); ?> <ul class="articles"> <li class="article-entry standard"><h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4> <span class="article-meta"><?php the_modified_date('F j, Y'); ?> in <?php the_category(', ') ?> </span> <span class="like-count"><?php echo get_total_likes($post->ID); ?></span> </li> </ul> <?php endwhile; } ?> </section>After deleting out that portion of code the plugin works on the custom template. So it must be a query. Someone pointed me in the direction of <?php wp_reset_postdata(); ?> but adding it to the end of the template didn’t solve the problem. I’m still trying…
The solution is that I need to use wp_reset_query(); between the last } and ?>.
The topic ‘Custom sidebars & custom page templates’ is closed to new replies.