ThemeShaper Forums » Thematic

[closed]

add PHP code to specific templates

(3 posts)
  • Started 2 years ago by PitaMaria
  • Latest reply from PitaMaria
  • This topic is resolved
  1. PitaMaria
    Member

    I'm using a Thematic child theme and I need to add a shortcode to specific template-generated pages (e.g. the archive page with the body class .category-topic). The shortcode's author says I can embed this code in my template:

    <?php
        if ( function_exists( 'nktagcloud_shortcode' ) ) {
            echo nktagcloud_shortcode( null );
        }
    
    ?>

    ... but I only want it to appear in certain pages like the one with the body class mentioned above. I'm hopeful I can achieve this by adding something to my functions.php but I don't know what to do. Any help would be much appreciated.

    Posted 2 years ago #
  2. For something like this, where do you want it to appear? By default it looks like it is already set up for a widget for sidebars (so I assume not sidebars).

    // add random div
    function snix_quick_div() {
    	if ( is_category() ) {
    		if ( function_exists( 'nktagcloud_shortcode' ) ) {
    			echo nktagcloud_shortcode( null );
    		}
    	}
    }
    add_action('thematic_abovefooter','snix_quick_div');

    The above little snippet will insert it at the bottom of "every" category. To only select certain categories, see the examples on the codex of how to take care of that.

    Also it is set to insert the action "thematic_abovefooter" or above the footer. If you wanted to move the location, view visualizing thematic which will show you some hooks to move it around (easily).

    This should work, hopefully the info from the links shows you how to get it exactly how you want.

    Posted 2 years ago #
  3. PitaMaria
    Member

    @ScottNix: Thorough and complete. Your solution worked perfectly and your links couldn't have been more helpful. Thanks for your contributions to this forum and to my issue; I really appreciate it.

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.