187 posts straight to the art designs
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $250,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Has referred 200+ members
+9 more
arrowthemes says

Hi, 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.

1722 posts Time is what you desire most, but waste carelessly.
  • Has sold $250,000+ on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Sells items exclusively on Envato Market
+6 more
Firsh says

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

187 posts straight to the art designs
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $250,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Has referred 200+ members
+9 more
arrowthemes says

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??

813 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $250,000+ on Envato Market
  • Sells items exclusively on Envato Market
  • Made it to the Authors' Hall of Fame
+6 more
LCweb says

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 '<div id="content-fill">';

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

echo '</div>';

// 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';
include(template.php);
187 posts straight to the art designs
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $250,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Has referred 200+ members
+9 more
arrowthemes says

Thanks Luca,

I will try that approach.

Apprezzo molto :)

by
by
by
by
by
by