ThemeShaper Forums » Thematic

Adding to content

(11 posts)
  • Started 4 years ago by DataGnostics
  • Latest reply from DataGnostics
  • This topic is resolved
  1. I guess I'm having a bad brain day. Help me, Obi-Wan.

    What I want to do is add a custom-field-derived element, let's call it $customstuff, before the_content for every post. $customstuff will be part (or all) of the excerpt, then at the top of the full post.

    Where do I put it? I mean, I know something goes in functions.php for my theme, but how do I structure it? Do I have to repeat function thematic_content() but stick in my $customstuff code, and if so where?

    Posted 4 years ago #
  2. Yes, I believe, you have to write your own thematic_content. That should be the best way to achieve what you want ... If I've understood the question correctly.

    Posted 4 years ago #
  3. Hi,

    a filter won't bite :)

    Something like:

    function my_content($content) {
    
        // you need to insert your get $customstuff here
    
        // once we have it we can start to build our new content
    
        $changed_content = $customstuff;
    
        // .. and now we add the real content
    
        $changed_content .= $content;
    
        // .. that's it .. but don't forget to return the changed content
    
        return $changed_content;
    
    }
    
    // .. last thing .. don't forget to add your filter to the original function
    
    add_filter('the_content', 'my_content');

    Chris

    Posted 4 years ago #
  4. Chris:

    Great so far! However, 'my stuff' isn't showing up on pages where the only part of the post that appears is the excerpt. It shows up when the post content is empty, and on the single page for posts that have content, but it's not getting put before the excerpt.

    What do I do now?

    yours in devout appreciation,

    Posted 4 years ago #
  5. Could you please explain .. step by step .. whhere you want to have the_content / the _exerpt and where the $customstuff should be added.

    The code above is just an example how to do it .. not a complete solution.

    Chris

    Posted 4 years ago #
  6. I can edit function thematic_content() within content-extensions.php to do what I want by doing this:

    if ( strtolower($content) == 'full' ) {
    		$post = get_the_content(more_text());
    		$post = apply_filters('the_content', $post);
    		$post = str_replace(']]>', ']]>', $post);
    		$post = 'my stuff' . $post;
    	} elseif ( strtolower($content) == 'excerpt') {
    		$post = get_the_excerpt();
    		$post = 'my stuff' . $post;
    	} elseif ( strtolower($content) == 'none') {
    	} else {
    		$post = get_the_content(more_text());
    		$post = apply_filters('the_content', $post);
    		$post = str_replace(']]>', ']]>', $post);
    	}
    	echo apply_filters('thematic_post', $post);

    where 'my stuff' is a placeholder for the custom field material.

    Is this enough info?

    Posted 4 years ago #
  7. Mmmh .. without testing .. I would create another filter with the same content and add it to get_the_excerpt.

    Posted 4 years ago #
  8. OK. So there's no easy way to call the same filter in two places?

    I am fumbling around stupidly and don't see how to add a filter to get_the_excerpt(). For single or empty posts, I'm using:
    'function my_content ($content) {
    $customstuff = 'my stuff';
    $changed_content = $customstuff;
    $changed_content .= $content;

    return $changed_content;

    }
    add_filter ('the_content', 'my_content');'
    How do I do the same thing for get_the_excerpt? I seem to have the dumb ...

    Posted 4 years ago #
  9. .. will do some tests later today

    Posted 4 years ago #
  10. get_the_excerpt() uses the_content() therefore $customstuff is already included.

    Posted 4 years ago #
  11. Aha, I got it to work! I had to name the function above my_post and filter thematic_post, not one of the "content" functions:
    add_filter ('thematic_post', 'my_post');
    Thanks for your help!

    Posted 4 years ago #

RSS feed for this topic

Reply

You must log in to post.