mpeesel 0 Report post Posted April 13, 2011 Hi, I'd very much like to create a hook that inserts a piece of short code into the template IF the category is defined as "homework". And I don't want it to show up anywhere else in the site. I have the hook defined so it shows a test in the site, but I don't know enough php to create this simple If/then statement. Essentially, it should say: If Category = "homework" Print "[short_code]" And if there is no category, then it also shouldn't appear. Of course, the short code also has to work here which is doesn't if you just stick it in there... Anyone have any ideas for this? Or am I trying to do this the wrong way? Thanks!! Mark Share this post Link to post Share on other sites
Simon 248 Report post Posted April 13, 2011 Hi Mark. `if ( is_category( 'homework' ) ) do_shortcode( '[short_code]' );` - or - `echo ( ( is_category( 'homework' ) ) ? do_shortcode( '[short_code]' ) : 'nothing happening!';` Couple of examples to get you started Share this post Link to post Share on other sites
mpeesel 0 Report post Posted April 13, 2011 Thanks Simon, these look like they would work, but it isn't rendering the php. It's just displaying the code as is. Seems like it needs something to get the php running... Here's what I have in functions.php: // add_action('hook_name','function name'); add_action('pagelines_after_theloop', 'homework_tags'); function homework_tags(){ ?> if ( is_category( 'homework' ) ) do_shortcode( '[tagcloud]' ); <?php } // end function Share this post Link to post Share on other sites
Simon 248 Report post Posted April 13, 2011 Ahh well you have put the code between the php tags `function homework_tags(){` `if ( is_category( 'homework' ) ) do_shortcode( '[tagcloud]' );` `}` `// end function` Share this post Link to post Share on other sites
mpeesel 0 Report post Posted April 13, 2011 That would make sense, wouldn't it... I *think* we're getting closer. Maybe. Now nothing shows and I don't see anything in the source either. Here's what I have: // add_action('hook_name','function name'); add_action('pagelines_after_theloop', 'homework_tags'); function homework_tags(){ if ( is_category( 'homework' ) ) do_shortcode( '[tagcloud]' ); } // end function Share this post Link to post Share on other sites
cmunns 16 Report post Posted April 13, 2011 Usually caused by a PHP syntax error. Any errors showing? Share this post Link to post Share on other sites
mpeesel 0 Report post Posted April 13, 2011 Nope. Nada. I wish. Nothing appears, no error... Share this post Link to post Share on other sites
Simon 248 Report post Posted April 14, 2011 Try this: `if ( is_category( 'homework' ) ) echo do_shortcode( '[tagcloud]' );` rest is the same Share this post Link to post Share on other sites
mpeesel 0 Report post Posted April 14, 2011 Hey that's starting to work! It's working on the main category page, but not on posts that are categorized as 'homework'. Probably my fault for not specifying that, but I *assumed* it would work on posts AND the category landing page. Thanks for everyone's help! I'd love a bit more if possible. Thanks! Share this post Link to post Share on other sites
timlinson 3 Report post Posted April 14, 2011 Try: `if ( is_category('homework') || in_category('homework') ) echo do_shortcode'[tagcloud]');` Share this post Link to post Share on other sites