CodeCanyon

Include PHP in specified HTML ID

78 posts
  • Has been a member for 1-2 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Author had a Free File of the Month
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 10 and 49 users
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.

4 months ago
1379 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 1 and 9 items
  • Europe
  • Referred between 1 and 9 users
Firsh says

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

4 months ago
78 posts
  • Has been a member for 1-2 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Author had a Free File of the Month
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 10 and 49 users
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??

4 months ago
141 posts
  • Has been a member for 1-2 years
  • Exclusive Author
  • Sold between 5 000 and 10 000 dollars
  • Bought between 1 and 9 items
  • Italy
  • Referred between 1 and 9 users
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);
4 months ago
78 posts
  • Has been a member for 1-2 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Author had a Free File of the Month
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 10 and 49 users
arrowthemes says

Thanks Luca,

I will try that approach.

Apprezzo molto :)

4 months ago
by
by
by
by
by