WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] Using the_id outside of single.php

[Resolved] Using the_id outside of single.php

  • I’ve been trying to find a way to pass the_id variable through my external links in order to track which clicks come from which post, but I’m having trouble making it work properly.

    Using the Template Tag Shortcodes plugin, I’m able append the post id to the end of my url as such:

    http://www.example.com/?kw=%5Bthe_ID%5D

    The problem is that I’ve been unable to make this work for ads that are placed in the sidebar or other locations.

    I figured this was due to the fact that the posts are actually a collection of PHP files, like single.php, sidebar.php, header.php, etc., but it seems like there should be a way to use the post id outside of the single.php file (in a widget on the sidebar, for example).

    Anyone have suggestions how to make this work?

Viewing 3 replies - 1 through 3 (of 3 total)
  • esmi

    @esmi

    Forum Moderator

    I figured this was due to the fact that the posts are actually a collection of PHP files, like single.php, sidebar.php, header.php, etc.,

    No. Your posts are a collection of records in your database. The files are templates for their display only.

    Anyone have suggestions how to make this work?

    http://codex.wordpress.org/Function_Reference/get_posts

    I need to clarify – the posts aren’t a collection of the code from those files, but the resultant pages that load on my site are.

    After a little more investigation, I’ve understand that the_id doesn’t function outside the post loop. I’ve seen suggestions as to how to make the $post value global, but I’ve not been able to recreate this. It seems like it may be an old technique.

    Does anyone know how to achieve this effect, or something similar?

    esmi, I don’t think you’ve understood my question.

    Nevermind, I figured this out.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Using the_id outside of single.php’ is closed to new replies.