Include PHP in specified HTML ID


I’m totally a rookie in PHP so I’d surely appreciate some help here.

I have template.php which has the structure of header, main-content, sidebar and footer. within main-content I have a div with a unique id, say #content-fill.

Is it possible using php to include php files into my template.php by targeting the #content-fill div? For instance, I create blog.php and include template.php. then within template.php I get the #content-fill and include a blog-content.php file?

Here is my attempt: :winktongue:
<?php include("template.php"); ?>
//php code to include blog-content.php within the #content-fill in template.php

Thanks in advance.


Yes, put that line into the div. What’s the question? :slight_smile:


Sorry, Firsh: seems I didn’t explain myself well - take #2

I have two php files template.php and blog-content.php. template.php has a div structures that forms the site elements (header, sidebar, main-content and footer)
What I want to do is using a third file (call it blog.php) include the template.php first (that I can do), then within the already included template.php target a specific html #id where I’ll include the blog-content.php within the #main-content section of the template.php.

(note if simply include the template.php and blog-content.php into blog.php in sequence, blog-content will appear below the footer of template.php. What I want is for it to appear within the main-content section of template.php.

Hope that makes sense??


Hi arrowthemes.
You can’t target an html ID to include a PHP file as you described, but you can define a variable to choose what to include in the template.php file.

for example, assuming you have this template.php:

//header code
// sidebar code

echo '
'; if(isset($include_page)) { if($include_page == 'blog') {include('blog-content.php');} else {include('other_content.php');} } echo '
'; // footer code

In this way you have only to specify what to show in the target div in the blog.php page.
blog.php page:

$include_page = 'blog';


Thanks Luca,

I will try that approach.

Apprezzo molto :slight_smile: