Jump to content


Photo

Add Php function to Page Template


  • Please log in to reply
5 replies to this topic

#1 cdhphoenix

cdhphoenix

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 04 March 2011 - 01:01 AM

Hi Guys,

I am trying to install a carousel gallery on this one page, which I have created in base theme for platform pro. This is the link to see what plugin it is if you require: [http://wordpress.org...l/installation/

It asks to place this code in my page template (which in this case, is the child functions.php? AM i correct in this assumption?:
 
	<?php wp_carousel(CAROUSEL'S ID); ?>

I m trying to understand hooks so I can add this on my own without having to ask everytime. I think i had it, but then i got an error, this is my interrpretation of it:
 
	add_action('pagelines_after_theloop','wp_carousel')
	function wp_carousel(){
	if (is_page('114')):
	wp_carousel('0');
	endif;
	}

But of course, that didn't work? Which line is incorrect so I can learn from my mistakes to do this own my own and add php functions on my own (I would like to add more than one gallery on this page)?

My page is called page.114.php for your reference.

Any suggestions of how I can add this to the page template would be greatly appreciated. thank you kindly.

Carolyn

#2 bryan-hadaway

bryan-hadaway

    Advocate

  • Members
  • PipPipPipPipPip
  • 3697 posts

Posted 04 March 2011 - 02:28 AM

Marking for developer review. Thanks, Bryan

#3 cmunns

cmunns

    Advocate

  • Members

  • 6537 posts
  • Country: Country Flag

Posted 04 March 2011 - 07:25 PM

Did it return an error or is simply not working? The hook and code you used look fine unless of course it doesn't allow "0" as an ID.

#4 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 04 March 2011 - 07:45 PM

Try some debugging 101 ;)

`add_action('pagelines_after_theloop','wp_carousel');`
`function wp_carousel(){`
`if (is_page('114')):`
`echo 'this is page 114 and my carousel should be here!';`
`endif;`
`}`
You did forget the ; at the end of your add_action line, but that should have thrown a php error.

#5 cdhphoenix

cdhphoenix

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 06 March 2011 - 05:49 AM

Hey Guys,

Thanks for your input; so this is code i ended up tweaking, after fixing my typo:

 
	add_action('pagelines_after_theloop','wp_carousel');
	function wp_carousel(){
	if (is_page('114')):
	wp_carousel('1');
	endif;
	}

*note, line 110 is the very last "}" in the code.

But then i get this error:

Fatal error: Cannot redeclare wp_carousel() (previously declared in /home/thewood2/public_html/www.criterioninedit.com/wp-content/plugins/wp-carousel/wp-carousel.php:451) in /home/thewood2/public_html/www.criterioninedit.com/wp-content/themes/platformbase/functions.php on line 110


AHhhhh. It never ends! Once again, this is the code the plugin asks to input in the page template:
 <?php wp_carousel(CAROUSEL'S ID); ?>

If anyone knows how to litigate this error, i would greatly appreciate it.

#6 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 06 March 2011 - 11:22 AM

Your nearly there, your function must be unique: `add_action('pagelines_after_theloop','my_wp_carousel');` `function my_wp_carousel(){` `if (is_page('114')):` `wp_carousel('1');` `endif;` `}`