ThemeShaper Forums » Thematic

[closed]

Conditional template changes

(5 posts)
  • Started 7 years ago by fwunder
  • Latest reply from fwunder
  • This topic is resolved
  1. fwunder
    Member

    I'm having a problem making custom changes to templates based on is_page_template and/or template_redirect.

    Following a discussion from a year or so ago, I've been messing with various incarnations of this:

    function my_stuff_before_content() {
    	echo new_stuff_before_content();
    add_action('thematic_abovecontent', 'my_stuff_before_content');
    
    function stuff_before_content() {
     	 if (is_page_template('template-page-fullwidth.php') ) { ?>
               <!-- custom stuff for this template   -->
         <?php }else{ ?>
              <!-- custom stuff for everything else   -->
         <?php }
    	return $new_stuff;
    }
    add_action('template_redirect','new_stuff_before_content');

    It ain't working. I would prefer to make the change(s) in functions.php rather than register a new template.

    Posted 7 years ago #
  2. ummm... your function names don't match. surprised you didn't get a major error.

    function stuff_before_content() {
    }
    add_action('template_redirect','
    new_stuff_before_content');

    but why do you have 2 functions in the first place?

    function kia_stuff_before_content() {
        if (is_page_template('template-page-fullwidth.php') ) {
    		echo "we're on the full-width template";
        } else {
            echo "we're NOT on the full-width template";
    	}
    }
    add_action('thematic_abovecontent', 'kia_stuff_before_content');

    as a heads up: the full-width template is being deprecated.

    Posted 7 years ago #
  3. fwunder
    Member

    Realizing I never stuck anything in $new_stuff in the above code, I tried something like this:


    function my_stuff_before_content() {
    echo new_stuff_before_content();
    add_action('thematic_abovecontent', 'my_stuff_before_content');

    function new_stuff_before_content() {
    if (is_page_template('template-page-fullwidth.php') ) {
    $new_stuff = " <div id='full'></div> ";
    }else{
    $new_stuff = " <div id='the_rest'></div> ";
    }
    return $new_stuff;
    }
    add_action('template_redirect','new_stuff_before_content');

    Still...a no go. Thanks!

    Posted 7 years ago #
  4. fwunder
    Member

    Thanks HTG. I thought I did try that already, but I probably wrote something wrong. Will try again. Thanks

    Posted 7 years ago #
  5. fwunder
    Member

    Yep! It was that stupid typo. There was a magnet next to my compass. This works perfectly:

    function new_stuff_before_content() {
     	 if (is_page_template('template-page-fullwidth.php') ) {?>
           <!-- custom stuff for this template   -->
          <?php }else{ ?>
           <!-- custom stuff for everything else   -->
           <?php }
       }
    add_action('thematic_abovecontent', 'new_stuff_before_content');

    And thanks for the heads up about template-page-fullwidth.

    Posted 7 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.