Jump to content


Md Template Overview (With Example Template File)

  • Please log in to reply
3 replies to this topic

#1 Alex


    Kolakube Staff

  • Kolakube Admin
  • 3,484 posts

Posted 03 February 2016 - 04:02 PM

Here is a walkthrough of customizing a template with a Child Theme. For a full sample of a template page in MD, download the following a file and upload to your child theme:


(template last updated 3/27/16)


When it comes to building advanced landing pages like the Marketers Delight page, I generally code them as template files. You should at least have a basic understanding oh how a web page is structured before going into this, but working in template files gives you unlimited freedom to design your page however you want.


Let's start by opening up index.php from the MD theme:

<?php get_header(); ?>

<?php if ( md_has_content_box() ) : ?>

    <?php md_content_box(); ?>

<?php endif; ?>

<?php get_footer(); ?>

Both the get_header() and get_footer() functions are native WordPress functions and each load the header.php and footer.php files respectively. I'm sure you know this part though, it's the md_content_box() function that is a little more complex.

The file build.php (/theme/build/build.php) is a file that reveals a lot about MD's structure. At the top you'll see hooks being fired that build a lot of MD's layout. You'll also find the md_content_box() function in there, which loads another native WordPress function, get_template_part(), which loads the content box template file from /theme/content/content-box.php.

(I know this feels like a maze right now, but it has a sweet ending)

In the content-box.php file there's HTML that looks like this:

<div id="content-box" class="content-box block-double-tb<?php md_content_box_classes(); ?>">
    <main class="content format-text-main" role="main" itemprop="mainContentOfPage">
        <?php md_hook_content(); ?>

    <?php get_sidebar(); ?>


This is the default content box loaded on every single page. This is especially useful to have because it has the <main> tag, which the page content (the <article> tag, headline, post body, etc.) go into.

...but you'll also see the md_hook_content() function in there. Since this function is designated as a hook, there are templates within MD that are being loaded here.

We can see in build.php that the following templates are being added to that hook:

add_action( 'md_hook_content', 'md_archives_title', 10 );
add_action( 'md_hook_content', 'md_loop', 10 );
add_action( 'md_hook_content', 'md_pagination', 90 );
add_action( 'md_hook_content', 'md_comments', 80 );
add_action( 'md_hook_content', 'md_post_nav', 90 );

...all of these functions that load into md_hook_content can be found in the list of functions also in this file, just like before. Each function will direct you to a template file, and you can edit those template files individually.

To stay consistent with your original question, we'll explore the Loop, as called in the above code with:

add_action( 'md_hook_content', 'md_loop', 10 );

Keep in mind The Loop template is also fired on every page, post, etc., so if you wanted to make changes to this (or any of the things mentioned prior) for specific kinds of pages only you'll need to use conditionals as outlined in Build With MD Part 2.

(hopefully by now you're making the connection to what I'm explaining in this forum post and that article)

The Loop file loads content from /content/content-item.php with the code below. In your child theme you can create a custom file of this for any post type by creating files like /content/content-single.php or /content/content-page.php, etc. etc.

<?php get_template_part( 'content/content-item', get_post_format() ); ?>

This file is just like the other ands loads yet another hook that builds out what's *inside* the content column. To keep things modular, the headline and content text are loaded in with hooks as well from build.php:

add_action( 'md_hook_content_item', 'md_content_headline', 5 );
add_action( 'md_hook_content_item', 'md_content_text', 10 );

...in which you can edit the template for the headline and content text from /content/headline.php and /content/text.php in your child theme.


I think I'll end it here. My main point with this longwinded explanation was to show you the different levels MD works at and deconstruct the layout piece by piece so you can add your content in accordingly (though it looks like you're figuring it out on your own).

I reconstructed the sample index.php file you can use as a base for your custom templates you can download below. Load this into your child theme as your template and you can add in your own code.


Let me know if you have any questions or would like to see more code examples.


(template last updated 3/27/16)

Attached Files

- Alex
Check out the Kolakube blog or follow me on Twitter.

#2 fonemstr



  • MD Customer
  • Pip
  • 1 posts

Posted 27 March 2016 - 05:04 PM

Hey Alex,


I'm using this example template to customize a page and it works but if I try to enable a page lead to appear after post it doesn't show up. Does something need to be added to the template to hook into this.

#3 Alex


    Kolakube Staff

  • Kolakube Admin
  • 3,484 posts

Posted 27 March 2016 - 05:42 PM

Thanks for reporting that, there is a fix you can add into the template file.


Paste this function immediately before the closing </main> tag towards the bottom of the file:

<?php md_hook_content(); ?>

That's the hook a Page Lead will be fired to when set to 'After Post'. I've also updated the template file in the original post, so you can download that if you want to start fresh.

- Alex
Check out the Kolakube blog or follow me on Twitter.

#4 poripa



  • MD Customer
  • Pip
  • 6 posts

Posted 27 January 2017 - 10:42 PM

Hello! I'm also trying to create and modify a template file for my own custom post type. 


Do you have the updated version for the example-template.php file that you uploaded above (that one was uploaded in Feb 2016, do you have one for MD 4.6 version?)  

I'd appreciate it! 

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users