ThemeShaper Forums » Thematic

[closed]

insert custom content after each post

(6 posts)
  • Started 3 years ago by soren
  • Latest reply from soren
  • This topic is not resolved
  1. Hello!

    I am using an "Hr" horisontal line (image) on every single post, but sometimes I would like to change the Hr line depending on the subject, I am also trying to get some text below or above (not sure yet where).

    Is it also possible to have a variety of hr lines, like if I use hr_3, hr_4 etc so it can search for ID that starts with "hr" is this possible?

    Here is a code that does not do much for me right now..

    Thanks
    Soren

    function add_post_content($content) {
    if(is_single()) {
    	$custom_content = get_post_meta($post->ID, 'hr_2');
    	if(is_empty($custom_content)) {
    	$content .= ‘<img src="http://mydomian/wp-content/uploads/images/hr_1.gif" style="margin: 60px auto 30px auto;" width="555" height="12" class="aligncenter" />';
    		$content .= ‘This article is copyright © ‘.date(‘Y’).’ ’.author(‘name’).”;
    }else{
    	$content .= $custom_content;
    }
    return $content;
    }
    add_filter(‘the_content’, ‘add_post_content’);
    Posted 3 years ago #
  2. This is the code I use today in my function.php, but this one is not giving me much flexibility...

    function add_post_content($content) {
    if(is_single()) {
    		$content .= '<img src="http://mydomain/wp-content/uploads/images/hr_1.gif" style="margin: 60px auto 30px auto;" alt="" title="" width="555" height="12" class="aligncenter" />';
    	}
    	return $content;
    }
    add_filter('the_content', 'add_post_content');
    Posted 3 years ago #
  3. why not add an action to thematic_belowpost() ?

    function add_post_content() {
    if(is_single()) {
    		$content .= '<img src="http://mydomain/wp-content/uploads/images/hr_1.gif" style="margin: 60px auto 30px auto;" alt="" title="" width="555" height="12" class="aligncenter" />';
    	}
    	echo $content;
    }
    add_action('thematic_belowpost', 'add_post_content');
    Posted 3 years ago #
  4. Please can you elaborate more? Is this better? But still seems to not give me flexibility to use different hr lines depending on post by using custom fields!

    Thanks

    Happy New Year everyone!

    Soren

    Posted 3 years ago #
  5. i guess i didn't understand what you meant when you originally said your code "wasn't doing much". i took that to mean it wasn't working- tho looking again, it seems that it should be successful at applying 1 graphic to the end of your post.

    now i see that you want to apply different graphics conditionally depending on a meta value, so why not call your custom field hr and then assign it different values... like 2, 3, 4, etc. then you can use a conditional based on the meta value, similar to what you wrote in your original post.

    function add_post_content($content) {
    if(is_single()) {
    	$custom_content = get_post_meta($post->ID, 'hr');
    	if($custom_content==1) {
    	$content .= ‘<img src="http://mydomian/wp-content/uploads/images/hr_1.gif" style="margin: 60px auto 30px auto;" width="555" height="12" class="aligncenter" />';
    		$content .= ‘This article is copyright © ‘.date(‘Y’).’ ’.author(‘name’).”;
    }elseif($custom_content==2) {
    	$content .= ‘<img src="http://mydomian/wp-content/uploads/images/hr_2.gif" style="margin: 60px auto 30px auto;" width="555" height="12" class="aligncenter" />';
    		$content .= ‘This article is copyright © ‘.date(‘Y’).’ ’.author(‘name’).”;
    } else {
    	//nothing
    }
    return $content;
    }
    add_filter(‘the_content’, ‘add_post_content’);
    Posted 3 years ago #
  6. OK,

    If I understand correctly, "elseif" for each different graphics you will use with the url included. So if I have 10 different graphics I need to have 10 rows with "elseif" statement?

    Thanks

    Soren

    function add_post_content($content) {
    if(is_single()) {
    	$custom_content = get_post_meta($post->ID, 'hr');
            if($custom_content==1) {
      $content .=
           }elseif($custom_content==2) {
      $content .=
           }elseif($custom_content==3) {
      $content .=
           }elseif($custom_content==4) {
      $content .=
           }elseif($custom_content==5) {
      $content .=
    etc...
    
    } else {
    	//nothing
    }
    return $content;
    }
    add_filter(‘the_content’, ‘add_post_content’)
    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.