ThemeShaper Forums » Thematic

[closed]

thematic_postheader conditional statement for page templates

(12 posts)
  • Started 3 years ago by helgatheviking
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. i'm trying to add a new condition for the thematic_postheader based on template, but with no joy yet. i can echo things in other places conditionally based on template, so i think my logic is right. but the following function always defaults to the final ELSE statement even when the first one should trigger true. obviously i don't want it to actually say bacon :) but sometimes i like to use that while debugging. house smelled like bacon this morning so i must have bacon on the brain.

    function childtheme_override_postheader(){
    
     	   global $post;
    
     	   if (	is_page_template('template-magazine.php') ) {
    			$postheader = "bacon";
    		}
    		elseif ($post->post_type == 'page' || is_404()) {
     	       $postheader = thematic_postheader_posttitle();
     	   }
    	   else {
     	       $postheader = thematic_postheader_posttitle() . thematic_postheader_postmeta();
     	   }
    
     	   echo apply_filters( 'thematic_postheader', $postheader ); // Filter to override default post header
    	}
    Posted 3 years ago #
  2. deleted.....not going to talk about things i don't know about. Still fuzzy on the use of overrides.

    Posted 3 years ago #
  3. When setting conditionals based on templates you have to hook into WordPress at a point after the template has been chosen in order for the conditional statement to ever to return True.

    The hook for this is:template_redirect

    function childtheme_override_postheader(){
    
    	echo childtheme_postheader_init();
    
    }
    
    function childtheme_postheader_init() {
    
     	   if (	is_page_template('my-template.php') ) {
    			$postheader = "It works!!!!";
    		}
    		elseif ($post->post_type == 'page' || is_404()) {
     	       $postheader = thematic_postheader_posttitle();
     	   }
    	   else {
     	       $postheader = thematic_postheader_posttitle() . thematic_postheader_postmeta();
     	   }
    	return $postheader;
    }
    
    add_action('template_redirect','childtheme_postheader_init');
    Posted 3 years ago #
  4. Pure effing gold, Gene! The echo line caused the lightbulb to glow over my head regarding at least some of the intended uses and implementations of overrides.

    Gene has mentioned template_redirect before, but being such a noob, i find myself trying to build everything the same way...the old...."well, it worked for this...why not for that..." mentality that comes from my lack of php/wordpress experience.

    So now i'm trying to do more reading to catch up to these guru's.

    Still trying to wrap my head around it, but...

    http://codex.wordpress.org/Plugin_API/Action_Reference

    is helping me to understand when things happen, so i can better determine what hook to use. I'm finding more and more that I started using Thematic to help accelerate my theme development, but I'm finding out the hard way that you can't take shortcuts, and that until i get a solid foundation in wordpress's structure, I'll never be able to fully leverage what thematic can do to facilitate development. Argg, homework....

    Posted 3 years ago #
  5. @tarpontech - "not going to talk about things i don't know about." why not? i do it all the time. :) but i find myself falling into the same "trap" of "it worked this way that one time." and for the most part things DO work the same way. but it is apparently helpful to keep in mind that some conditionals can't be solved if the variable they test for hasn't been set yet. this is the case w/ the is_page_template, and it has bitten me in the ass before. the override functions are pure genius. no more unhooking the unwanted function and adding your new one back in. just give you function the appropriate override name and bam!

    @gene- thanks for the help as always! your code snippet is so pretty that I am sad to say I am not getting the "it works" happy dance in my postmeta.

    i feel like i've heard of this template_redirect hook before... as i said to tarpontech, i've had this issue of the is_page_template condition never being true since it was getting called before the template was even established. i figured my issue had to do w/ the template condition never being met. but i never would have thought of this work-around. i hope it can lead me to where i want to go. atleast it is something new for me to play with

    Posted 3 years ago #
  6. @ms viking

    I double checked my code against a much more layered test site and discovered that on some pages, especially nested pages, that the new postheader would not display as intended.

    Strangely I solved this by "Update"ing the pages that were problematic from the admin edit page screen. After that WordPress played nice again.

    Try testing using is_page_template() as a general condition to see on which pages this method fails.

    Posted 3 years ago #
  7. I had tried the generic is_page_template() and also is_page() and it still fails. also- i tried updating the page to no avail. i'm using 0.9.7.2 if that matters/helps. the page is a top level page that i am trying to use as a blog page (in a magazine style). i am wondering if it wouldn't just be faster to hard-code the template. is there any advantage to trying to filter the template postheaders and postfooters from the functions?

    Posted 3 years ago #
  8. I had tried the generic is_page_template() and it still fails

    Do you mean it failed for this one page or all pages? I'm assuming just this one.

    Double check for the simple things like typos or are you calling thematic_postheader(); from inside the loop in your custom template?

    If there is no resolution using the method I've tried and tested, It'd probably be easier to hardcode the template as I am obviously not seeing something that is going on here.

    Posted 3 years ago #
  9. don't know if you saw my edit (since we posted at almost the same time). i also tried is_page() and that doesn't work either. i looked at a few other pages (both w/ is_page_template and is_page and no luck w/ them either. i am leaning towards hard-coding the template, except that now i want to know! i hate it when that happens.

    Posted 3 years ago #
  10. ok- i believe the problem comes from me running that page like a blog. i checked another template page that behaves like a PAGE and it works properly w/ only the override function. no need for the echo in template_redirect.

    so the postheader i have been trying to edit is actually the individual postheaders of all the blog entries.. and in the loop all of those blog posts are POSTS and not pages using the template i've been testing for.

    SO, i guess i have no option but to either create a custom index loop (can you have multiple conditional loops) or hard-code the template itself - which as we keep pointing out is the easiest! and does have the nice benefit of being able to drop into any theme w/ only the one file.

    Posted 3 years ago #
  11. This likely has top do with how you are calling a custom query. If you are using query_posts() then you are in effect altering the query. try using an new query and stoing it and running your loops from it like:

    $custom_loop = new WP_Query('showposts=5&category_name=uncategorized');
    
    if ( $custom_loop->have_posts() ) :
    
    	while ( $custom_loop->have_posts() ) : $custom_loop->the_post();
    
    		thematic_postheader();
    
    		the_content();
    
    	endwhile;
    
    	wp_reset_query();
    
    endif;

    Sorry i dont have more time to explain gotta get on the road..

    Good luck

    Posted 3 years ago #
  12. no problem gene. safe travels. i'm working on hard-coding the template.. custom-naming the functions in the template à la magazine_postheader(). at least it is working for now. but i will definitely try your query thing later. thanks!

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.