• Resolved MoniqueR

    (@moniquer)


    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/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Nicolas Lemoine

    (@nlemoine)

    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%

    What file do you past the code?

    Thread Starter MoniqueR

    (@moniquer)

    You have to put the code in your functions.php

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

    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

    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.

    Plugin Author Nicolas Lemoine

    (@nlemoine)

    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();
    }

    That´s it !! : )

    Thank you very much, it works like a charm!

    Best regards

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Adding own tags’ is closed to new replies.