Hook into loop templates

You can hook your content into loop templates easily. For this you need to add some code to your functions.php in your theme.

We decided to not build an extra graphical admin UI for this. There is a point where it's more difficult to learn the complexity of a new admin interface than to learn how to do it with code. It's not so difficult. If you are not a programmer, don't worry - we'll take you by the hands. ;-) It's actually very easy.  

#1 - Choose  where to add your content 

Every entry has 6 HOOKS to define where you want to add content. Now, first you have to choosewhere you want to hook your new content.  

Select one of the following 4 cases and copy the add_action to your functions.php:  

1. Hook some content before every entry
add_action('tk_loop_designer_before_loop_item','your_function', 10 );
2. Hook some content before the inner entry
add_action('tk_loop_designer_before_entry_inner','your_function', 10 );
3. Hook some content before the title:
add_action('tk_loop_designer_before_loop_title','your_function', 10 );
4. Hook some content after the title:
add_action('tk_loop_designer_after_loop_title','your_function', 10 );
5. Hook some content after the inner entry
add_action('tk_loop_designer_after_entry_inner','your_function', 10 );
6. Hook some content  after the loop item:
add_action('tk_loop_designer_after_loop_item','your_function', 10 );
#2 - Add your content 

Now you need the function to add the actual content. 

In the add_action above we named it "your_function". 
You can change this name to whatever you feel like, but just use numbers, letters and underscores. 

Copy the following example and modify it to your needs: 

<p>function your_function() { ?></p><p>    <p>Some Content</p></p><p><?php </p><p>}</p>

This small function will add the HTML "<p>Some Content</p>" to all places. 

See how it looks when we hook the same function on all 6 action hooks: 

* image is old and just shows 4 hooks - will be updated ASAP! * 

The content is also added via hooks. The Title is the only fixed information in this entry.

If you want to change the order of your hooked content, you just need to change the priority to a higher or lower level depend on if you want it up and down.

add_action('tk_loop_designer_after_loop_title','your_function', 10 );
If we want to shift the "Some Content" from  after the title to below the content, we only need to increase the priority. It's good practice to make big steps in the position numbers, in case you want to hook something in between later.

so let us increase the priority to 50 now:
add_action('tk_loop_designer_after_loop_title','your_function', 50 );

As we can see, the "Some content" text has moved  under the content.

This was a really easy example. 

These follow up post are coming soon:

How to display post content examples:
-- Display post content like Author or Create Date
-- Display custom post meta 
-- Add content only to a special template
-- Add content only to a custom post type

We hope this information was useful for you. If you miss an how to on this topic, please let us know.

Still need help? Contact Us Contact Us