wordpress theme breaks after inserting external php ? possible mistake in folder config?

I am new to wordpress and following is my scenario.
I am inserting an external php script in wordpress by creating a new template in the theme and then using that template in a new page.

When I do this the new content is visible in the loaded page (and works as expected) but the theme breaks for the page i.e. all side bars (right and bottom) get lost. and if i am logged in the wpadmin bar at top is lost for that page only.
for all other pages everything comes back.

Read More

Could you guys please help me what could be going wrong here.
I doubt that there is some folder config going wrong somewhere.

Following is what I am doing:
inside my new theme page template –

<?php 
 /**
 * The template for displaying pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages and that
 * other "pages" on your WordPress site will use a different template.
 *
 * Template Name: abctemplate
 * @package WordPress
 * @subpackage Twenty_Sixteen
 * @since Twenty Sixteen 1.0
 */
?>

<?php
get_header();
 ?>

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">

        <?php
        // Start the loop.
        while ( have_posts() ) : the_post();

            // Include the page content template.
            get_template_part( 'template-parts/content', 'page' );      

            include_once dirname(ABSPATH) . 'abcindex.php'; // <=== the EXTERNAL SCRIPT


            // If comments are open or we have at least one comment, load up the comment template.
            if ( comments_open() || get_comments_number() ) {
                comments_template();
            }

            // End of the loop.
        endwhile;
        echo "end post loop";   
        ?>

    </main><!-- .site-main -->

    <?php get_sidebar( 'content-bottom' ); ?>

</div><!-- .content-area -->

<?php echo "get_sidebar"; get_sidebar(); ?>
<?php echo "get_footer"; get_footer(); ?>

The above script internally after setting some variables, calls following template:

require_once(‘templates/’.$template.’/index.php’);

the above template is a simple html page calling some variables in above abc/index.php

calling this breaks the wordpress theme mostly, the sidebars, (i am not sure yet if it breaks something else).
Could this mean that wordpress did not find the required side bar related files? but everything is inside the theme template.

Basically this whole thing is a scenario of loading an existing webpage into wordpress. I have the functionality working but UI breaks.

Related posts

2 comments

  1. The problem I see first is naming the templates.

    you have the following, which will throw a PHP parse error:

    <?php 
     Template Name: abctemplate 
    ?>
    

    Have a look at the documentation here: https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/

    A template name should be in a docblock as follows

    <?php
    /**
     * Template Name: Full Width Page
     *
     * @package WordPress
     * @subpackage Twenty_Fourteen
     * @since Twenty Fourteen 1.0
     */
    
  2. Guess what ! it was the die() which was breaking everything. And the way I found it was totally lame(removing approx 2000 lines of code one by one). Anyways the reason makes a bit sense to me now. Thanks!

Comments are closed.