Override global post id with page template. (2 posts)

  1. Darrell Schauss
    Posted 6 years ago #

    I have a custom page template and I will assign it to a page.

    I need to, for the whole page template, hard code a specific page id. So even if I assign the template to page 1 I would like page 1 to be treated like page 2, because page 2 will the the hard coded ID in the template. Then when any loops or sidebars using Widget Logic, etc are loaded in that page they are passed along page 2 as the ID.

    I tried doing this at the top of my file global $post; $post->ID=2; but when the loop happens it still loads as ID 1.

  2. wprelief
    Posted 6 years ago #

    Change the query before your loop (just put it at the top) to have the id of 2. You can do this using WP_Query. (http://codex.wordpress.org/Function_Reference/WP_Query and http://codex.wordpress.org/Template_Tags/query_posts)

    once you do this, WordPress should set up the variables you need hardcoded.

Topic Closed

This topic has been closed to new replies.

About this Topic