Editing
WordPress Templates Cookbook
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Inserting a custom content template in a page == * Within the top-level WordPress template (e.g. `page.php`) <syntaxhighlight lang="php"> <?php get_template_part( 'modules-sidebar-donate-link' ); ?> </syntaxhighlight> * 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()`. <syntaxhighlight lang="php"> <?php $query = new WP_Query("post_parent=123&post_type='page'&orderby=order&order=ASC"); /* 123 = "landing page slideshow" page */ ?> </syntaxhighlight> ** Then a loop would be created within the template: <syntaxhighlight lang="php"> <?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; ?> </syntaxhighlight>
Summary:
Please note that all contributions to Littledamien Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Littledamien Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information