WordPress.org

Ready to get started?Download WordPress

Forums

WP Better Emails
[resolved] Adding own tags (9 posts)

  1. MoniqueR
    Member
    Posted 6 months ago #

    On the FAQ page there is an example of taking sponsored links as an additinonal content. It also states that it can be used to include latest posts. I can not get it to work. My goal is to display the most recent posts in a list in the email being send.
    Maybe some-one can help me out?

    Regards,
    Monique

    http://wordpress.org/plugins/wp-better-emails/

  2. hellonico
    Member
    Plugin Author

    Posted 6 months ago #

    Hi Monique,

    You can add the lastest posts this way :

    add_filter('wpbe_tags', 'add_my_tags');
    function prefix_add_my_tags( $tags ) {
    	if( $latest_posts = prefix_get_posts() )
        	$tags['latest_posts'] = $latest_posts;
        return $tags;
    }
    function prefix_get_posts() {
    	$posts = get_posts();
    	if( empty($posts) )
    		return false;
    	?>
    	<?php foreach($posts as $post) { ?>
    	<div>
    		<h2><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></h2>
    	</div>
    	<?php }
    }

    And then add this tag in your template : %latest_posts%

  3. Lisa Sauro
    Member
    Posted 5 months ago #

    What file do you past the code?

  4. MoniqueR
    Member
    Posted 5 months ago #

    You have to put the code in your functions.php

  5. Lisa Sauro
    Member
    Posted 5 months ago #

    Thanks so much for your help. I'm using twenty ten theme, tried it but didn't work.

  6. BBIndikator
    Member
    Posted 4 months ago #

    Hello,

    here, too. Insert it as a snippet, but it don´t work. It shows just %latest_posts% in a sent E-Mail.

    I also have noticed that %blog_description% does not work, if the snippet is active.. That means in a sent mail you see %blog_description%, and not the description itself..

    Best regards

  7. Lisa Sauro
    Member
    Posted 4 months ago #

    Hi BBindikator, Did you get latest post to work? Love this plugin and would be great if I could add latest post. Right now I have to cut and paste them into email for every send.

  8. hellonico
    Member
    Plugin Author

    Posted 4 months ago #

    Hi everyone,

    There's a mistake in the piece of code I wrote. The following code has been tested and works:

    add_filter('wpbe_tags', 'prefix_add_my_tags');
    function prefix_add_my_tags( $tags ) {
    	if( $latest_posts = prefix_get_posts() )
        	$tags['latest_posts'] = $latest_posts;
        return $tags;
    }
    function prefix_get_posts() {
    	$posts = get_posts();
    	if( empty($posts) )
    		return false;
    
    	ob_start();
    	?>
    	<?php foreach($posts as $post) { ?>
    	<div>
    		<h2><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></h2>
    	</div>
    	<?php }
    	return ob_get_clean();
    }
  9. BBIndikator
    Member
    Posted 4 months ago #

    That´s it !! : )

    Thank you very much, it works like a charm!

    Best regards

Reply

You must log in to post.

About this Plugin

About this Topic