WordPress Templates Cookbook

From Littledamien Wiki
Revision as of 17:00, 24 January 2013 by 66.214.144.90 (talk) (Created page with "== Overview == Documentation on how to set up various common features in WordPress. == Inserting a custom content template in a page == * Within the top-level WordPress tem...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Overview

Documentation on how to set up various common features in WordPress.

Inserting a custom content template in a page

  • Within the top-level WordPress template (e.g. page.php)
<?php get_template_part( 'modules-sidebar-donate-link' ); ?>
  • The string passed as the argument to get_template_part() corresponds to a WordPress template in the themes directory. So 'modules-sidebar-donate-link' means there should be a template named modules-sidebar-donate-link.php.
  • Template markup goes in the template file (modules-sidebar-donate-link.php in this case).
    • Content can be retrieved within the template using WP_Query().
<?php $query = new WP_Query("post_parent=123&post_type='page'&orderby=order&order=ASC"); /* 123 = "landing page slideshow" page */ ?>
    • Then a loop would be created within the template:
<?php if ($query->have_posts()) while($query->have_posts()): $query->the_post(); ?>
<div><!--// Content inserted here using markup and WP content retrieval methods. //--></div>
<?php endwhile; ?>


Sub-navigation using sub-pages

When landing on a content section page, load a sub-navigation menu dynamically using pages that have that top-level content section page as their parent.

Example: http://rsrt.dbarchowsky.com/about-rsrt/

  • Create the top-level page (as a WordPress "page", not a WP "post"). The page can have any sort of content.
  • Create 2nd-level pages and assign the top-level page as their parent.