ThemeShaper Forums » Thematic

[closed]

Hooks Inside Loops

(9 posts)
  • Started 7 years ago by em hr
  • Latest reply from janis
  • This topic is not a support question
  1. I keep finding myself removing and rebuilding thematic_index_loop, thematic_single_post(),and thematic_archive_loop(). I'm basically copying the code and adding custom field calls either before or after thematic_content(). I would think that this is a pretty common practice. In these cases it would be a benefit to have action hooks before and after the content.

    Does anyone else see the value in this?

    -Gene

    Posted 7 years ago #
  2. meredith
    Member

    I'm trying to do as you described and can't seem to figure out how to disable the default thematic_single_post? i feel like it should be easy!

    Posted 7 years ago #
  3. Hi Meredith -

    I think this is what your looking for:

    function remove_single_post() {
      remove_action('thematic_singlepost','thematic_single_post');
    }
    add_action('init','remove_single_post');
    
    function isley_single_post() {
      // Its your thing. Do What you wanna do.
     }
    add_action('thematic_singlepost', 'isley_single_post');

    I've got my fingers crossed for the hooks inside loops feature making it into the next release.

    -Gene

    Posted 7 years ago #
  4. janis
    Member

    Thanks for the pointers Gene. I agree hooks within the loop would be very helpful.

    Unfortunately, until then I am still having trouble with adding in custom fields.

    I have unhooked single_post and re-inserted an exact clone of the original thematic_single_post using the method you have shown above.

    but when I attempt to add in under the thematic_content()

    <?php echo get_post_meta($post->ID,'PostHeader', true); ?>

    nothing appears.

    I know the values and keys were added correctly as the_meta(); does return the right information.

    Is there something in the way thematic_single_post() is set up that is breaking the custom field code?

    Posted 7 years ago #
  5. janis
    Member

    I am probably missing something really basic here, as I am just starting to learn php and WP in general. If anyone could help me find out why I am not getting anything returned from get_post_meta I would be really grateful. Thanks In advance.
    Here is my full code.

    <?php
    function remove_thematic_single_post(){
    	remove_action('thematic_singlepost','thematic_single_post');
    	}
    add_action('init', 'remove_thematic_single_post');
    
    // The Single Post
    
    function jc_thematic_single_post() {?>
    	<div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class(); ?>">
        	<?php thematic_postheader(); ?>
    			<div class="entry-content">
    			<?php thematic_content(); ?>
    
    			<?php echo get_post_meta($post->ID,'PostHeader', true); ?>
    
    			<?php wp_link_pages('before=<div class="page-link">' .__('Pages:', 'thematic') . '&after=</div>') ?>
    </div>
    		<?php thematic_postfooter(); ?>
    	</div><!-- .post -->
    <?php
    
    }
    add_action('thematic_singlepost', 'jc_thematic_single_post');
    
    ?>
    Posted 7 years ago #
  6. Try changing the beginning of jc_thematic_single_post to call the global variable $post. It is in that variable that WordPress stores the post meta.

    function jc_thematic_single_post() {
    	global $post;	?>
    Posted 7 years ago #
  7. janis
    Member

    I tried adding global $post; But I am still only getting "Array" outputted.
    I get the same result when I try to add the code into the index_loop as well. (I even placed it right into to the content-extensions.php to see if it would work there too. And I get ARRAY outputted every time.)

    I'm super lost as to why get_post_meta isn't working.

    Do you know why get_post_meta is acting like it is operating outside the loop.

    Thanks for the help. I really appreciate it.

    j

    Posted 7 years ago #
  8. The global $post and get_post_meta() are working otherwise you wouldn't be echoing anything at all.

    If you have the boolean value for the parameter $single set to true in :
    <?php echo get_post_meta($post->ID,'PostHeader', true); ?>
    Then you should not be returned "Array" check to make sure that you have set the $single parameter correctly. Double check to see.

    From the Codex:

    $single
    (boolean) (optional) If set to true then the function will return a single result, as a string. If false, or not set, then the function returns an array of the custom fields. This is not intuitive. For example, if you fetch a serialized array with this method you want $single to be true to actually get an unserialized array back. If you pass in false, or leave it out, you will have an array of one, and the value at index 0 will be the serialized string.
    Default: false

    Posted 7 years ago #
  9. janis
    Member

    Yeah it works! Thank you so much for the help. For this and for all the other things I learned from you on this forum.

    Posted 7 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.