[wp-hackers] post id in custom template

ml_wordpress at copperleaf.org ml_wordpress at copperleaf.org
Sun Jun 5 12:46:05 GMT 2005

I have a plugin that modifies "the_content" with a registered content 
filter. I'd like to be able to have the part being modified be defined 
with an optional template file but need to know the post id and misc 
data in the template page. Let me try and illustrate.


    the post id is <?php echo $post-ID; ?><br />
    my tag key is <?php echo $mymatches; ?><br />

in the content filter, I do something like:

preg_replace_callback('/<!--\s*mytag(.*)-->/iU', callback, $content);

function callback($mymatches)
    $buf =ob_get_content();
    return $buf; 

What is the best way to pass in the post id as well as $mymatches to the 
template file? I know I can use the global $post to get the post id, but 
is that the best way? Or would I be better off defining a function in 
the mytemplatefile.php. Something like:

function mytemplatefile($postid, $mymatches){
    the post id is <?php echo $postid; ?><br />
    my tag key is <?php echo $mymatches; ?><br />
<?php } ?>


More information about the wp-hackers mailing list