How do I pass data from page content to the underlying PHP template

If you want to produce a page in WordPress whose structure and content are dynamically generated independent of the regular posts handling mechanism then: Create a new page with title “My Custom Page“. This generates the page slug ‘my-custom-page‘ by default. In the root of your active theme folder eg. \wp-content\themes\twentyeleven\ create a page template … Read more

Extending body classes in front- and backend

Your snippet adds the following classes to the body tag on the front end, someText someText Your snippet adds the following classes to the body tag on the back end, someClassA someClassB If that is you intended result, then yes that works and is correct. You could also do, function add_custom_body_classes($classes) { $someClassA = ‘someText’; … Read more

How do I add a new template to my site

You can install a File Manager within WordPress, Search the Plugins. Or the easyist way to be honest is simply login via FTP to your web host locate the template folder within wp-content/themes/yourtheme/ and create a file with the name you want to have it. i.e wp-content/themes/yourtheme/mycustom.php just insert in the empty file. and then … Read more

Remove template drop down for certain pages

The “How?” To get rid of a meta box, you got several hooks straight after they were added inside ~/wp-admin/edit-form-advanced.php. The one you need it ‘dbx_post_advanced’. The you just need to remove the meta box with remove_meta_box(). <?php defined( ‘ABSPATH’ ) or exit; /** Plugin Name: (#90253) Remove Page Template Drop Down */ add_action( ‘dbx_post_advanced’, … Read more

Generate Catalog Of Posts Based On Template

To get all posts ordered by their template you need two functions: one for the query, and one to add a custom order. Get the posts function get_posts_by_template() { add_filter( ‘posts_orderby’, ‘orderby_template’ ); $query = new WP_Query( array( //’meta_key’ => ‘_wp_page_template’, ‘post_type’ => ‘any’, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ‘posts_per_page’ => -1, // dangerous … Read more

Programatically create a page

You can try // add a new page $args = array ( ‘post_type’ => ‘page’, ‘post_title’ => ‘My New Page’, ‘post_status’ => ‘publish’, ); $pid = wp_insert_post( $args ); // add a custom template file to the newly created page if( $pid > 0 ) add_post_meta( $pid, ‘_wp_page_template’, ‘custom-template.php’ ); where we set the page … Read more

Valid HTML in Template Part

Of course there is. Just do it like this: $sticky = get_option( ‘sticky_posts’ ); $args = array( ‘post_type’ => ‘mission’, ‘ignore_sticky_posts’ => 1, ‘orderby’ => ‘date’, ‘post__not_in’ => $sticky, ‘posts_per_page’ => $count ); $latest_missions = new WP_Query( $args ); if ( $latest_missions->have_posts() ) { echo ‘<ul>’; // prints opening ul tag before list items while … Read more