- Posts: 12
COMMUNITY FORUM
- Forum
- K2 Community Forum
- English K2 Community
- Adding PHP Function to category_item.php breaks site template.
Adding PHP Function to category_item.php breaks site template.
- Dave Smith
-
Topic Author
- Offline
- New Member
Less
More
13 years 9 months ago #99258
by Dave Smith
Adding PHP Function to category_item.php breaks site template. was created by Dave Smith
I'm not sure what the issue here is, hope someone can help, I am trying to add a PHP function to my category_item.php
When I add the function, the site doesn't display correctly anymore.
The function can be stripped down as far as the following, and yet still breaks the site:
<?phpfunction myfunction($test){ return($test);}?>
Anyone help ?
thanks.
When I add the function, the site doesn't display correctly anymore.
The function can be stripped down as far as the following, and yet still breaks the site:
<?phpfunction myfunction($test){ return($test);}?>
Anyone help ?
thanks.
Please Log in or Create an account to join the conversation.
- Dave Smith
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 12
13 years 8 months ago #99259
by Dave Smith
Replied by Dave Smith on topic Adding PHP Function to category_item.php breaks site template.
Well, it appears that I have something dodgy in my category_item.php, as I added the same code to item.php and this works fine. Looks like a long debugging session is in order!
Please Log in or Create an account to join the conversation.
- Dave Smith
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 12
13 years 8 months ago #99260
by Dave Smith
Replied by Dave Smith on topic Adding PHP Function to category_item.php breaks site template.
Weird. Now it's all working. Never mind. Sorry to have bothered you.
Please Log in or Create an account to join the conversation.
- Dave Smith
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 12
13 years 8 months ago #99261
by Dave Smith
Replied by Dave Smith on topic Adding PHP Function to category_item.php breaks site template.
No, still not working, I'm fairly sure it is a missing closing tag somewhere (possibly a ?> ), but strange. It works fine if there is only one item in the category, but any more and it breaks...
Please Log in or Create an account to join the conversation.
- Dave Smith
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 12
13 years 8 months ago #99262
by Dave Smith
Replied by Dave Smith on topic Adding PHP Function to category_item.php breaks site template.
Right. Been through the W3C validator (at validator.w3.org) and removed 15 errors. The remaining 8 errors are caused by googlemaps scripts and Google/Facebook/Twitter buttons. These can be left alone. I did however add a missing </div> in my google map script output for the map label. This did not solve my problem. I also ran the "broken" page through the validator and it shed some light, it turns out the page is giving a 500 error which is being hidden by my template somehow - so I am not seeing it.
Please Log in or Create an account to join the conversation.
- Dave Smith
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 12
13 years 8 months ago #99263
by Dave Smith
Replied by Dave Smith on topic Adding PHP Function to category_item.php breaks site template.
SOLVED:
After getting the 500 error, I managed to get my Apache2 Error log working again by restarting apache2 on the server. (If it isn't one thing it's another!)
Error log showed me an interesting error: cannot re-declare function.
If anyone else has a similar problem, changing the original function above to read:
<?phpif (!function_exists("myfunction")){
function myfunction($test) {
return($test); }
}
?>
Solves this problem.
The problem is caused because the function is inside the category_item.php file, which is repeated each time an item is shown on the category page, therefore the second and subsequent time the item is shown the function is re-declared (which is not allowed!)
Hope this helps someone in future.
After getting the 500 error, I managed to get my Apache2 Error log working again by restarting apache2 on the server. (If it isn't one thing it's another!)
Error log showed me an interesting error: cannot re-declare function.
If anyone else has a similar problem, changing the original function above to read:
<?phpif (!function_exists("myfunction")){
function myfunction($test) {
return($test); }
}
?>
Solves this problem.
The problem is caused because the function is inside the category_item.php file, which is repeated each time an item is shown on the category page, therefore the second and subsequent time the item is shown the function is re-declared (which is not allowed!)
Hope this helps someone in future.
Please Log in or Create an account to join the conversation.
- Forum
- K2 Community Forum
- English K2 Community
- Adding PHP Function to category_item.php breaks site template.