Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Center area post/pages (http://forum.bytesforall.com/forumdisplay.php?f=32)
-   -   How to add php code to a 'single' page (http://forum.bytesforall.com/showthread.php?t=5787)

JakeThePeg Feb 9, 2010 07:53 AM

How to add php code to a 'single' page
 
Howdy,

I am hacking a plugin to fit in with my Atahualpa theme. It requires me to add some PHP code to the 'single posts' page...most other themes have a simple 'single.php' file, however I'm not sure this is the case with Atahualpa is it?

Where abouts would I slot in this PHP code so that it only appears on the single post pages?

Rashell Feb 15, 2010 06:23 AM

in the "center column---> inside the loop" with a conditional statement like

Code:

<?php if is_single() AND "then add the rest of your php code">
Rashell

JakeThePeg Mar 14, 2010 01:27 AM

Sorry to ask a really basic question....but I don't know how the IF statements work in PHP.

This is the PHP code I want to insert....

PHP Code:

$post_cats get_the_categories(); 
$post_coordinates GeoMashup::post_coordinates(); 
if ( 
$post_coordinates ) { 
  echo 
GeoMashup::map'map_content=global&map_cat='$post_cats[0]->cat_ID 
'&center_lat' $post_coordinates['lat'] . '&center_lng=' 
$post_coordinates['lng'] ); 


How do I incorporate that into the IF statement you mentioned above?

juggledad Mar 15, 2010 05:27 AM

try this
HTML Code:

<?php if is_single() {
$post_cats = get_the_categories(); 
$post_coordinates = GeoMashup::post_coordinates(); 
if ( $post_coordinates ) { 
  echo GeoMashup::map( 'map_content=global&map_cat='. $post_cats[0]->
cat_ID 
. '&center_lat' . $post_coordinates['lat'] . '&center_lng=' . 
$post_coordinates['lng'] ); 
} } ?>


JakeThePeg Mar 17, 2010 08:09 AM

Quote:

Originally Posted by juggledad (Post 27667)
try this
HTML Code:

<?php if is_single() {
$post_cats = get_the_categories(); 
$post_coordinates = GeoMashup::post_coordinates(); 
if ( $post_coordinates ) { 
  echo GeoMashup::map( 'map_content=global&map_cat='. $post_cats[0]->
cat_ID 
. '&center_lat' . $post_coordinates['lat'] . '&center_lng=' . 
$post_coordinates['lng'] ); 
} } ?>


Thanks, I tried pasting the above code at the end of the "The Loop" section in the Centre Column tab of the Athualpa theme options, and the following error came up on the front end.

Parse error: syntax error, unexpected T_STRING, expecting '(' in /home/jake13/public_html/shackn/wp-content/themes/atahualpa/functions.php(389) : eval()'d code on line 22

Any ideas why?

juggledad Mar 17, 2010 02:17 PM

try putting a () around the 'is_single()' so it would be 'if (is_single() )'

JakeThePeg Mar 18, 2010 02:04 AM

Thanks, I tried what you said, and now I get another error :)

Fatal error: Call to undefined function get_the_categories() in /home/jake13/public_html/shackn/wp-content/themes/atahualpa/functions.php(389) : eval()'d code on line 23

juggledad Mar 18, 2010 04:27 AM

well that is from your original code you wanted to insert. That error says that the function 'get_the_categories()' doesn't exist.

Where did you get this code from? if it is a plugin, it should have had that function in it. If you were doing this properly, the code snippet should test to see if the function exists then display a notice on the page to that effect.

But you need to go back and look at the original plugin, you are missing something

JakeThePeg Mar 21, 2010 01:21 AM

Ok, cool, thanks for the advice, I'll speak to the plugin creator and report back with my findings :)


All times are GMT -6. The time now is 03:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.