My favorites | Sign in
Logo
                
Search
for
Updated Dec 10, 2009 by heilemann
Labels: Documentation-Howto
K2ChildThemes  
Advanced Customization of K2 via Child Themes.

With WordPress 2.7+, it is now possible to override K2's template files by creating a child theme of K2. This allows you to customize K2 without changing the core files.

Creating a Child Theme

  1. Create a new folder in the WordPress themes folder (wp-content/themes/) to contain your child theme files. (Do not create the folder inside of K2 or the K2 Styles folder: k2/styles/.)

    For example: wp-content/themes/k2-custom/

  2. Create a style.css file with the following content:

    /*
    Theme Name: your child theme name
    Theme URI: the-theme's-homepage
    Description: a-brief-description
    Author: your-name
    Author URI: your-URI
    Template: K2
    */

    Note: Make absolutely sure whatever you have in Template: matches the folder name that K2 resides in. This is case-sensitive. For example: if K2 resides in the path wp-content/themes/kaytwo-1.0/, you would use:

    Template: kaytwo-1.0

  3. Copy K2's screenshot.jpg into your child theme folder.

    Now our example child theme contains:

    • k2-custom/
      • style.css
      • screenshot.jpg

  4. Activate your child theme via Appearance > Themes panel.

Customizing K2

Refer to K2CSSandCustomCSS on customizing css.

Now that you have a blank child theme, you can now start customizing K2. Just make a copy of the template file that you would like to modify into your child theme folder.

For example, to customize the Single Post template (single.php), make a copy of single.php into your child theme folder and edit away. Be sure to leave K2's single.php intact.

You can also include a functions.php file with your child theme. Refer to the WordPress Plugin API for more info.

Note: Please do not modify anything inside the k2/app/ folder.

K2 Blocks

Content from certain parts of K2 are now stored in the k2/blocks/ folder, and should also be stored in the blocks/ folder in the child-theme's folder.

k2-header.php contains all content in div#header, including the header menu
k2-footer.php contains all content in div#footer
k2-loop.php contains the post loop

k2-loop.php is a special case. You can target your customizations to a specific query by making a copy k2-loop.php and naming it:

Hooks

Below is a list of hooks provided by K2 and where they appear in the generated HTML source. You can insert content via your child theme's functions.php file or by using the K2 Hook Up plugin.

<?php /* K2 Hook - RC6 */ do_action('template_body_top'); ?>

<div id="page">

	<?php /* K2 Hook - RC6 */ do_action('template_before_header'); ?>

	<div id="header">
		Header content is contained in: blocks/k2-header.php

		<?php /* K2 Hook - RC6 */ do_action('template_header'); ?>
	</div>

	<hr />

	<?php /* K2 Hook - RC6 */ do_action('template_before_content'); ?>

	<div class="content">

		<div id="primary-wrapper">
			<div id="primary">
				<?php /* K2 Hook - RC8 */ do_action('template_content_head'); ?>

				<div id="notices"></div>

				<div id="current-content" class="hfeed">
					<div id="post-#" class="hentry"></div>
				</div>

				<div id="dynamic-content">
					<div id="rollingarchives"></div>

					<div id="rollingcontent" class="hfeed">
						<div id="post-#" class="hentry">
							<div class="entry-head">
								<?php /* K2 Hook - RC8 */ do_action('template_entry_head'); ?>
							</div>
							<div class="entry-content">
							</div>
							<div class="entry-foot">
								<?php /* K2 Hook - RC8 */ do_action('template_entry_foot'); ?>
							</div>
						</div>
					</div>
				</div>

				<?php /* K2 Hook - RC8 */ do_action('template_content_foot'); ?>
			</div> <!-- #primary -->
		</div> <!-- #primary-wrapper -->

		<hr />

		<div id="sidebar-1" class="secondary"></div>

		<hr />

		<div id="sidebar-2" class="secondary"></div>

		<div class="clear"></div>
	</div> <!-- .content -->

	<?php /* K2 Hook - RC6 */ do_action('template_after_content'); ?>

	<div class="clear"></div>
</div> <!-- Close Page -->

<hr />

<?php /* K2 Hook - RC6 */ do_action('template_before_footer'); ?>

<div id="footer">

	Footer content is contained in: blocks/k2-footer.php

	<?php /* K2 Hook - RC6 */ do_action('template_footer'); ?>

</div>

Hosted by Google Code