WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Using the_id outside of single.php (4 posts)

  1. allanlegree
    Member
    Posted 3 years ago #

    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=the_ID

    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?

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    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

  3. allanlegree
    Member
    Posted 3 years ago #

    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.

  4. allanlegree
    Member
    Posted 3 years ago #

    Nevermind, I figured this out.

Topic Closed

This topic has been closed to new replies.

About this Topic