WordPress.org

Support

Support » Plugins and Hacks » [Plugin: PHP Code Widget] Trying to access the $post-ID for a single page and not happening…

[Plugin: PHP Code Widget] Trying to access the $post-ID for a single page and not happening…

  • Been trying for quite some time to get a simple one-liner to work on my site.

    http://www.theinfopro.com/cloud-computing-flash-page/

    Basic framework for the page template:

    <?php get_header(); ?>
    THE LOOP
    <?php include (TEMPLATEPATH . '/flash-sidebar.php'); ?>
    <?php get_footer(); ?>

    In the flash_sidebar, I have three widgets and each are doing the same function:

    <?php $key="FlashTech"; echo get_post_meta($post->ID, $key, true); ?>

    Looks easy, right? The sidebar is not running inside the loop which created the page, and I have been scouring how to make the $post-ID come up in the execphp widget. I could get the_meta() function to work in the widget (which I assume is because it runs outside TheLoop, but nothing else. I even tried some other ideas out there such as:

    <?php function tempfunct() {
    	global $post;
    	$thePostID = $post->ID;
    	echo $thePostID;
    } tempfunct(); ?>

    And the widget does not run. Any ideas why? Feedback very much appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’ve made this work at times by setting a variable within the loop
    $post_id = $post->ID;

    then within the function

    <?php function tempfunct() {
    	global $post_id;
    	echo $post_id;
    } ?>

    Thank mate! That fixed it. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: PHP Code Widget] Trying to access the $post-ID for a single page and not happening…’ is closed to new replies.