Programatically changing template of a page

Looking at the wp_postmeta table, you can see the page template is stored there. Therefore, a simple call to update_post_meta (codex) should do the trick : update_post_meta( $post_id, ‘_wp_page_template’, ‘my_template.php’ ); The filename and extension is necessary, as per my example.

WPML in custom page templates

For the language filter from WPML to take effect you have to allow filters in get_posts. Default this is off. You can add suppress_filters=0 to your get_posts args and it should work. See: http://codex.wordpress.org/Template_Tags/get_posts#Parameters <ul id=”archive-list”> <?php $args = array( ‘suppress_filters’ => false, ‘numberposts’ => ‘-1’, ‘post_type’ => ‘post’, ); $myposts = get_posts($args); foreach($myposts as … Read more

How do I find if a page has a template?

This should do the trick for you. This shows what template file is stored in post_meta, if one has been selected in the admin panel: $template_name = get_post_meta( $the_query->post->ID, ‘_wp_page_template’, true ); If you want to see if the page is the homepage, use is_home() or is_front_page(). If you want to see what files are … Read more

Export csv and force download in template page

Put all the code that handles the output of the CSV before your get_header() call, then exit: <?php /** * CSV page template * */ if($_SERVER[‘REQUEST_METHOD’] == “POST”) { $fileName = date(“d-m-y”) . ‘-bv-directory.csv’; $content = “”; // content added below // Title of the CSV $content = “Name,Address,Age,Phone \n”; // Data in the CSV … Read more

is_page_template returning false

I think your problem is how your function is constructed and not your condition as such. You should not be wrapping your function and your action in a condition like this. Page templates are selected really late in the query by the main query, and I probably think that this is way to late for … Read more

Editable content on a Custom Archive page

You can use Options API or Setting API to store the data in the database. Write a plugin to create a meta box for the introduction text and show that text on the archive-unicorn.php. Or you can utilize the description parameter when you register_post_type and print it in the archive-unicorn.php like this: $unicorn_obj = get_post_type_object(‘unicorn’); … Read more