Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom Theme PHP File Include Issue
#1
Hello,

I am having an issue where I created a custom PHP file, that gets all the pictures in an image directory, and displays them on the page in correctly formatted DIV/IMG tags.

It will work correctly when I use it in a "Standalone" scenario, however...When I include it in the template.php file, the img tags do not show up, I believe this is because of a permission issue when included?

However I also noticed that I cannot use get_theme_url() function either, it says it is undefined.
Reply
#2
what version of GS.....
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#3
(2015-09-09, 04:15:51)shawn_a Wrote: what version of GS.....

GetSimple CMS – Version 3.3.7
Reply
#4
(2015-09-09, 04:26:44)korey.badgley Wrote:
(2015-09-09, 04:15:51)shawn_a Wrote: what version of GS.....

GetSimple CMS – Version 3.3.7

Should note... I am using a self-modified version of the Innovation Theme
Reply
#5
are you using functions.php or including your own php file from your template ?
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#6
(2015-09-09, 04:15:51)shawn_a Wrote: what version of GS.....

I should reword that....

I cannot use the get_theme_url() in the php file that I am trying to use.


Code:
$folder = 'assets/images/projects/';
$filetype = '*.*';
$images = glob($folder.$filetype);

$j = 0;

$column1 = array();
$column2 = array();
$column3 = array();

foreach($images as $i){
   //echo "<img id='imagesLine' onmouseover='changeImage(\"".$i."\")' src='".$i."' />";
   switch ($j) {
       case 0:
           $column1[] = $i;
           $j = $j+1;//set for next
           break;
       case 1:
           $column2[] = $i;
           $j = $j+1;//set for next
           break;
       case 2:
           $column3[] = $i;
           $j = 0;//set for next
           break;
   }
   
}

   foreach($column1 as $i) {
       echo $i . "<br />";
   }

   echo "<div class='imageContainer'>";
   echo "<div class='col-3'>";
   foreach($column1 as $i){
       echo "<img class='project' src='http://localhost/WebDesignerWebsiteCMS/theme/Innovation/". $i."' />";
   }
   echo "</div>";
   echo "<div class='col-3'>";
   foreach($column2 as $i){
       echo "<img class='project' src='".$i."' />";
   }
   echo "</div>";
   echo "<div class='col-3 last'>";
   foreach($column3 as $i){
       echo "<img class='project' src='".$i."' />";
   }
   echo "</div>";
   echo "</div>";

The above is what I am trying to use, and the place where I'd like to use the function get_theme_url() is...


Code:
$folder = get_theme_url . 'assets/images/projects/';
Reply
#7
(2015-09-09, 04:40:12)shawn_a Wrote: are you using functions.php or including your own php file from your template ?

Trying to include my own php file. 

Named: images.inc.php
Reply
#8
well first off its
get_theme_url(false)
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#9
(2015-09-09, 04:52:02)shawn_a Wrote: well first off its
get_theme_url(false)

Just tried that, still has the same issue.
Google Drive link to Image
Reply
#10
theme_functions is only included on front end
so you will want to do that

include_once(GSADMININCPATH.'theme_functions.php');
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#11
PHP Code:
function getImages() {

$folder get_theme_url(false) . '/assets/images/projects/';
$filetype '*.*';
$images glob($folder.$filetype);

$j 0;

$column1 = array();
$column2 = array();
$column3 = array();

foreach(
$images as $i){ 
    
 
   switch ($j) {
 
       case 0:
 
           $column1[] = $i;
 
           $j $j+1;//set for next
 
           break;
 
       case 1:
 
           $column2[] = $i;
 
           $j $j+1;//set for next
 
           break;
 
       case 2:
 
           $column3[] = $i;
 
           $j 0;//set for next
 
           break;
 
   }
 
   


 
   foreach($column1 as $i) {
 
       echo $i "<br />";
 
   }

 
   echo "<div class='imageContainer'>";
 
   echo "<div class='col-3'>";
 
   foreach($column1 as $i){ 
 
       echo "<img class='project' src='http://localhost/WebDesignerWebsiteCMS/theme/Innovation/"$i."' />";
 
   
 
   echo "</div>";
 
   echo "<div class='col-3'>";
 
   foreach($column2 as $i){ 
 
       echo "<img class='project' src='".$i."' />";
 
   
 
   echo "</div>";
 
   echo "<div class='col-3 last'>";
 
   foreach($column3 as $i){ 
 
       echo "<img class='project' src='".$i."' />";
 
   
 
   echo "</div>";
 
   echo "</div>";



I put all of the above inside a function, inside the themes_functions.php, and it still does not populate.
Reply
#12
well not sure why you put it there, you shouldn't modify core files.

But
glob($folder.$filetype);
$folder is not a folder its a url, you asked for url...

You are probably looking for
PHP Code:
GLOBAL $TEMPLATE;
$folder GSTHEMESPATH .$TEMPLATE
I would put my project files in uploads though not themes unless they are assets.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#13
(2015-09-09, 07:36:36)shawn_a Wrote: well not sure why you put it there, you shouldn't modify core files.

But
glob($folder.$filetype);
$folder is not a folder its a url, you asked for url...

You are probably looking for

PHP Code:
GLOBAL $TEMPLATE;
$folder GSTHEMESPATH .$TEMPLATE
I would put my project files in uploads though not themes unless they are assets.

It seems that I am still not understanding....Sorry....

The images.inc.php file is being used to create front-end code. It creates all the tags, except the <img /> tags.

The reason i am using the assets>images folder, is because I wasn't sure how to get the data>uploads folder, using php code...without it puking back at me, saying there were no images.

Thank you for all the help you are providing me, this is one of the reasons why I wanted to stick with GS...Support.
Reply
#14
Well like I said you are using a url as a file path.
You should at least use debugLog() for tracing stuff.

And the sa_dev plugin for front end debugging
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#15
What about doing a scandir on GSTHEMESPATH . $TEMPLATE . '/assets/images/' , then prepend global $SITEURL to each result and output. Voila.
Reply
#16
(2015-09-09, 08:41:54)shawn_a Wrote: Well like I said you are using a url as a file path.
You should at least use debugLog() for tracing stuff.

And the sa_dev plugin for front end debugging

Bad news, using the sa_dev plugin makes my front-end jquery scroller break....
Reply
#17
(2015-09-09, 09:03:12)Tyblitz Wrote: What about doing a scandir on GSTHEMESPATH . $TEMPLATE . '/assets/images/' , then prepend global $SITEURL to each result and output. Voila.

Globals are not working properly... which does not make sense... 

GSCMS is acting like the file I created, and put into my custom theme folder, is not connected, nor does it understand how to use it.

I even tried taking all the PHP code, and placing it DIRECTLY into the template.php file, and it still does not create the <img /> tags... 
Reply
#18
Hehe you gotta take smaller steps man.

You keepmsaying img tags.

How about you just take it one peice at a time.

Print_r($folder);
Print_r($images);

And fix one piece at a time.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#19
(2015-09-09, 10:49:15)shawn_a Wrote: Hehe you gotta take smaller steps man.

You keepmsaying img tags.

How about you just take it one peice at a time.

Print_r($folder);
Print_r($images);

And fix one piece at a time.

Thank you for working with me.....

Print_r("Folder: " . $folder); http://localhost/WebDesignerWebsiteCMS/theme/Innovation/assets/images/projects/

Print_r("Images" . $images); Returns nothing and has no error message.

It seems the following glob() is not working? Is there something that could be preventing glob() from running?


PHP Code:
$folder get_theme_url(false) . '/assets/images/projects/';
$filetype '*.*';
$images glob($folder.$filetype); 
Reply
#20
Your folder is still a url....
Lol
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#21
The folder should be named... path..... it needs to be a URL, as it needs to get the directory for the glob to search, and find the files that meet the *.* criteria (All files in this case.)
Reply
#22
I should also mention I have tried...

$folder = 'assets/images/projects/';

it gives the path + file names, yet the IMG tags still will not echo to the page.
Reply
#23
Folders have to be full paths.

You do know the difference between urls and paths?
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#24
(2015-09-09, 12:22:12)shawn_a Wrote: Folders have to be full paths.

You do know the difference between urls and paths?

Yes.....
The problem is that on the index.php (Page loading all other pages into it.) it will not take a relative path, it must be an absolute path.
I can create the absolute path, but that does not help when it loads, and cannot find the files in the directory that is specified.

I put...


Code:
glob($folder.$filetype, GLOB_NOCHECK);

This will return the path, if there are no results....
It is returning the full path,

http://localhost/WebDesignerWebsiteCMS/theme/Innovation/assets/images/projects/*.*

as it is unable to scan the directory as intended.

The IMG tags are not being created, as the SRC is not being populated, as there is nothing being put into $image .
This only happens when I use the file in the template.php by adding <?php include('images.inc.php'); ?>
if I try the file on it's own, it will work without a problem.
Reply
#25
Code:
<img class="project" src="http://localhost/WebDesignerWebsiteCMS/theme/Innovation/assets/images/projects/*.*">

The above code is what is being echo'd, as glob($pattern, GLOB_NOCHECK)will return the full pattern when there are no results that match the pattern.

It seems that the glob function cannot read the directory? Could this be a permissions issue when it is included in another file?
Reply




Users browsing this thread: 1 Guest(s)