views:

108

answers:

3

Hi, I am trying to customise a Wordpress theme. I have a function in themes/functions.php that I would like to run on some pages.

I need to be to:

  1. Detect the page ID to determine whether the function should execute
  2. Determine which hook to attach the function to (preferably something like page load.

Cheers

A: 

The file functions.php is for theme specific functions called inside your theme. If this is a theme specific function then the function call should be in the header (or wherever you want the output of the function to appear) via <?php my_function() ?>.

Hooks are for plugins, not template specific code.

WarrenB
<?php the_ID(); ?> will get you the post/page ID as well, since that was also part of the question.
WarrenB
A: 

If you are inside The Loop, then you can call <?php the_ID(); ?> as WarrenB said. If you are outside of the loop, then <?php echo $post->ID?> will print the page ID.

iangraham
A: 

To the questions you posed, given you want to select on id #9, run your loop like this:

<?php
 query_posts('page_id=9');
   if (have_posts()) : while (have_posts()) : the_post();
      // Do whatever on post id #9
?>
<?php endwhile; else: ?>
      // Do whatever on all the other posts
<?php endif; ?>

If this isn't the answer you're looking for, please add more information to your question.

Dave Doolin