Format post content outside of loop

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Format post content outside of loop

Paul Menard-2
So dumb question I'm sure. I need to grab the post_content variable  
to include in an HTML email. Normally I call $post->the_content()  
which will echo the formatted content to the screen.

What I need to to apply the same formatting rules etc. How can this  
be done? Is there a single function that will let me assign the  
formatted content to a local variable?

P-
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Format post content outside of loop

David House
On 20/04/06, Paul Menard <[hidden email]> wrote:
> So dumb question I'm sure. I need to grab the post_content variable
> to include in an HTML email. Normally I call $post->the_content()
> which will echo the formatted content to the screen.

Actually, you never call $post->the_content(), the_content() is a
global function (not a method) which echoes $post->post_content.

If the post you want to email is one of the ones selected (i.e., it's
in $posts), then use apply_filters('the_content', $posts[n]); If it's
not, use:

$post_to_email = get_post(ID);
$content = apply_filters('the_content', $post_to_email->post_content);

--
-David House, [hidden email], http://xmouse.ithium.net
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Format post content outside of loop

Brian Layman
David House said it all when he uttered:
>$content = apply_filters('the_content', $post_to_email->post_content);

Yep.  Look at functions-formatting.php's function wp_trim_excerpt for an
example of how to include a cleaned version of the post in your email...

_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Format post content outside of loop

Paul Menard-2

On Apr 20, 2006, at 12:12 PM, Brian Layman wrote:

> David House said it all when he uttered:
>> $content = apply_filters('the_content', $post_to_email-
>> >post_content);
>
> Yep.  Look at functions-formatting.php's function wp_trim_excerpt  
> for an
> example of how to include a cleaned version of the post in your  
> email...
>
> _______________________________________________
> wp-hackers mailing list
> [hidden email]
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>

Very cool. Thanks all. And sorry for the mis-quote on the function.  
Correct 'the_content();
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...