ThemeShaper Forums » Thematic

[closed]

Conditional childtheme_override

(10 posts)
  • Started 13 years ago by ridgely
  • Latest reply from ridgely
  • This topic is not resolved
  1. (Building from 0.9.7.4 rev709)
    If you want a conditional childtheme_override, for example, you want to use the childtheme_override_category_loop only on certain category pages, where does the condition need to occur. I tried inserting the condition within the childtheme_override but that didn't work entirely as intended, i.e. it affected ALL my category pages:

    /*Custom Category Loop for certain Categories*/
    function childtheme_override_category_loop() {
    		if (is_category('drawing')|| is_category('painting')) {
    	 	while ( have_posts()	)	:	the_post()	// Start the loop:
    ?>
    		<div id="post-<?php	the_ID() ?>" class="<?php	thematic_post_class()	?>">
    				<?php	thematic_postheader(); ?>
    				<?php	get_the_image( array(	'custom_key' =>	array( 'Thumbnail',	'thumbnail'	), 'default_size'	=> 'thumbnail' ) );	?>
    				<div class="entry-content">
    		<?php	thematic_content();	?>
    				</div>
    				<?php	thematic_postfooter(); ?>
    		</div><!-- .post -->
    		<?php	endwhile;	// loop	done,	go back	up
    		}
    	}
    Posted 13 years ago #
  2. Hi Ridgley,

    The very existence of an override function removes the parent function. If you want to use the override conditionally then you will need the condition to precede the child override function like so:

    if ( is_category('drawing') ) {
    	function childtheme_override_category_loop() {
    	  // do something
    	}
    }

    Depending on which parent function you are overriding and the point of that parent function is executed, you may or may not need to load a global variable such as global $post. So generally it may be best to wrap the whole condition in a function and call the global variable that you might need.

    function my_conditional_*() {
    	global $post;
    
    	if ( is_*() ) ) {
    		function childtheme_override_*() {
    	 	 // do something
    		}
    	}
    }
    Posted 13 years ago #
  3. Cool! Thank you! Do I need to build an "out" for this? I.e.

    function my_conditional_category_loop() {
    	global $post;
    
    	if ( is_category('drawing') ) {
    		function childtheme_override_category_loop() {
    	 	 while ( have_posts()) : the_post() // Start the loop:
    ?>
    		<div id="post-<?php the_ID() ?>" class="<?php thematic_post_class()?>">
    		<?php thematic_postheader(); ?>
    		<?php get_the_image( array('custom_key' => array( 'Thumbnail','thumbnail'	),'default_size' => 'thumbnail' ) ); ?>
    		<div class="entry-content">
    		<?php	thematic_content();?>
    		</div>
    		<?php thematic_postfooter(); ?>
    		</div><!-- .post -->
    		<?php endwhile; // loop done, go back up
    		} else {
                    return thematic_categoryloop();
    		}
    }
    
    add action (my_conditional_category_loop, thematic_categoryloop);

    Or am I wayy offtrack?

    Posted 13 years ago #
  4. In case you check back. I updated some errors in the code above.

    Posted 13 years ago #
  5. If by "out" you mean:

    add_action (my_conditional_category_loop, thematic_categoryloop);

    No, the add action is not necessary.

    Posted 13 years ago #
  6. By out I was thinking more of
    ...`else {
    return thematic_categoryloop();
    }`

    If the else statememt is necessary, then good to know. If the add_action is *not* necessary, then how/where does one insert my_conditional_category_loop? Or does the global $post; take care of that problem?

    You guys are great - so patient with the baby who learns by cut-and-paste. :)

    Posted 13 years ago #
  7. The else is not necessary either.

    The override won't come into play if the condition is not met. So in that case we will fall back to the parent function regardless.

    Test it out :)

    Posted 13 years ago #
  8. So I put this in my functions file:

    function my_conditional_category_loop() {
    	global $post;
    	if (is_category('drawing') || is_category('painting')) {
    		function childtheme_override_category_loop() {
    	 	while ( have_posts()) : the_post() // Start the loop:
    		?>
    		<div id="post-<?php the_ID() ?>" class="<?php thematic_post_class()?>">
    		<?php thematic_postheader(); ?>
    		<?php get_the_image( array('custom_key' => array( 'Thumbnail','thumbnail'	),'default_size' => 'thumbnail' ) ); ?>
    		<div class="entry-content">
    		<?php	thematic_content();?>
    		</div>
    		<?php thematic_postfooter(); ?>
    		</div><!-- .post -->
    		<?php endwhile; // loop done, go back up
    		}
    	}
    }

    While the category pages that *aren't* drawing or painting came out ok, the category-drawing and category-painting pages came up with the page-title and archive-meta, period. These category posts are set with css to hide everything but the thumbnail, which should have been created per the function above. But no luck. What am I missing?

    Posted 13 years ago #
  9. TAKE 2
    This, however, worked:

    function my_conditional_category_loop() {
    	if (is_category('drawing') || is_category('painting')) {
    	 	while ( have_posts()	)	:	the_post();
    
    		thematic_abovepost(); ?>
    
    		<div id="post-<?php	the_ID() ?>" class="<?php	thematic_post_class()	?>">
    				<?php	thematic_postheader(); ?>
    				<?php	get_the_image( array(	'custom_key' =>	array( 'Thumbnail',	'thumbnail'	), 'default_size'	=> 'thumbnail' ) );	?>
    				<div class="entry-content">
    		<?php	thematic_content();	?>
    				</div>
    				<?php	thematic_postfooter(); ?>
    		</div><!-- .post -->
    		<?php 
    
    				thematic_belowpost();
    
    		endwhile;
    	} else {
    		while (have_posts()) : the_post(); 
    
    				thematic_abovepost(); ?>
    
    				<div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class(); ?>">
    	    			<?php thematic_postheader(); ?>
    					<div class="entry-content">
    				<?php thematic_content(); ?>
    					</div><!-- .entry-content -->
    					<?php thematic_postfooter(); ?>
    				</div><!-- #post -->
    			<?php 
    
    				thematic_belowpost();
    
    		endwhile;
    	}
    } // end category_loop
    
    function childtheme_override_category_loop() {
    		echo my_conditional_category_loop();
    }
    Posted 13 years ago #
  10. This mysteriously caused my "blog" page to go blank. Wonder why?

    Posted 13 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.