Community Forums › Forums › Archived Forums › Design Tips and Tricks › Change page template – page meta
Tagged: _wp_page_template, update_post_meta
- This topic has 4 replies, 3 voices, and was last updated 11 years ago by cehwitham.
-
AuthorPosts
-
March 25, 2013 at 3:55 pm #31187ZeroGravityMember
I am dynamically creating a page and trying to change the template to the Genesis page_archive.php template. The page creates and I can update the content. I have tried everything I can find but cannot change the page's template. Can someone tell me where I am going wrong?
$archive_page_id = wp_insert_post( add_magic_quotes( $data ), $wp_error ); update_post_meta( $archive_page_id, '_wp_page_template', get_theme_root() . '/genesis/page_archive.php' );
Many Thanks!
Darren Burns
Zero Gravity Web WorksApril 25, 2013 at 3:55 pm #37739cehwithamMemberWhat have you called the page template?
Have you selected the template under Page Attributes on the right hand side of the editing screen?
Chris
Twitter: cehwitham Web: cehwitham.com
April 26, 2013 at 12:40 pm #37899ZeroGravityMemberThe page template I am trying to set it the standard Genesis Archive template. From the template file this is "Archive." I can set the template under page attributes but I am trying to set it dynamically.
I am creating pages dynamically when a user signs up in a multi-site system. I am able to create a page for the archive but I cannot set the template to the Archive template when the template file is in the Genesis folder. If I copy page_archive.php to the child theme folder it works.
I would much rather set it to the standard template in the Genesis folder than a copy in the theme folder.
Darren
Darren Burns
Zero Gravity Web WorksApril 26, 2013 at 10:03 pm #38000Brad DaltonParticipantApril 28, 2013 at 1:49 am #38167cehwithamMemberHi Darren,
This article suggests you're using the correct code. I think it is the path to your page template that is letting you down.
http://wordpress.stackexchange.com/questions/40161/set-page-template-for-all-pages
I think you probably want to use the TERMPLATEPATH constant as this refers to the parent theme:
Defined in /wp-includes/default-constants.php.
This constant is used to get the path to where your theme files are. A template path is something like /home/username/public_html/wp-content/themes/your-theme/, and it is set by WordPress automatically, you should never define a different value for this one (just use and love it).
This constant is useful when you want to check if certain template files exist (such as custom.css, comments.php, etc.) or carry out some tasks when they do. For example:
// If the template file exists
if (file_exists(TEMPLATEPATH . '/comments.php'))
// do something useful
Note that TEMPLATEPATH refers to the parent theme’s directory7. In case you’re developing a child theme, you should use STYLESHEETPATH (described below) instead8.From http://betterwp.net/282-wordpress-constants/
Twitter: cehwitham Web: cehwitham.com
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.