views:

172

answers:

5

I've tried so many combinations of php to get wordpress to output $post->post_content as formatted text (as opposed to the raw formatting that echo $post->post_content gives me. This combination seems to be the most promising, but it isn't outputting anything. Any ideas?

(it's this line: <?php $content = apply_filters('the_content', $s->post_content); ?>)

<?php query_posts('orderby=menu_order&order=asc&posts_per_page=-1&post_type=page&post_parent='.$post->ID); if(have_posts()) { while(have_posts()) { the_post(); ?>
    <div class="page">
        <?php
            global $wpdb;
            $subs = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent='$post->ID' AND post_type='page' AND post_status='publish'");
            if($subs) {
        ?>
        <div class="navi"></div>
        <a class="naviNext"><img src="<?php bloginfo('template_url'); ?>/images/navi-next.png" alt="" /></a>
        <div class="scrollable">
            <div class="items">
                <?php foreach($subs as $s) { ?>
                <div class="item">
                    <h2><?php echo $s->post_title; ?></h2>
                    <?php $content = apply_filters('the_content', $s->post_content); echo $content; ?>
                </div>
                <?php } ?>
            </div>
        </div>
        <?php } else { the_content(); } ?>
    </div>
    <?php } } wp_reset_query(); ?>
A: 

You need to echo the results of the apply_filters call:

<?php echo apply_filters('the_content', $s->post_content); ?>

Or, as you've got it coded:

<?php 
    $content = apply_filters('the_content', $s->post_content); 
    echo $content;
?>
Pat
yeah... I tried that earlier– still doesn't output anything!
j-man86
crap! Didn't notice that you were already doing that in your original example. If you just `echo $s->post_content;` do you get the raw formatting of the post?
Pat
yes– echo $s->post_content gives me raw formatting, but echoing the filter does not.
j-man86
A: 

Sorry if this is too basic, but it might help if you echoed the content:

<?php
$content = apply_filters('the_content', $s->post_content);
echo $content;
?>
John P Bloch
A: 

How are you adding the filter? You can use add_filter that specifies a function that will receive $content. You can do any filtering that you need via this function.

http://codex.wordpress.org/Plugin_API#Create_a_Filter_Function

Adam Tootle
This looks like a step in the right direction... I'm not adding the filter anywhere, just applying it. How would I add it in this instance? Thanks!
j-man86
you should be able to just add it via your theme's functions.php file
Adam Tootle
I just looked back at your original post and you could also probably use setup_postdata($s) inside you for loop and use the_content().You can see that used here - http://codex.wordpress.org/Template_Tags/get_posts#Posts_list_with_offset
Adam Tootle
A: 

hmm.. for some reason, i can get content to display when I removed the top line and bottom line.

maybe the problem is the query_posts call .. and not the apply_filters() call.

i can switch display mode depending on whether or not I use apply_filters() or not. which i believe is what you are after.

kenzaraque
just doing <?php echo $s->post_content; ?> gives me unformatted content (the p tags and all formatting are stripped) so I am trying to use "the_content_ filter to get rich text back.
j-man86
sorry, i wasn't clear. I removed the call to query_posts().. and that solved the problem for me. i was able to use the_content_filter with the desired result after that. that's why i wanted to see if you can get the same results I can by modifying or removing the call to query_posts().
kenzaraque
I initally thought that query_posts could be the issue. If removing it does fix the problem, then I think the most likely explanation is that the $post global has been filled with 'other' data, and one of the hooked filters is reading content from the global variable. Wordpress seems to do this fine, so it's probably a poorly written plugin/functions.php file at fault. Reading from the DB always causes problems. Use Wordpress's API -- it's easier, and it'll make sure necessary globals are filled and necessary filters/actions are fired.
Brendon
A: 

As far as I know, the function that applies the main 'formatting' to the content body is wpautop(). That function should be hooked into 'the_content' by wordpress. The function does do annoying things (like mess up embed code) though and there are a lot of plugins that will unhook it from the filter stack. Try replacing your line:

<?php $content = apply_filters('the_content', $s->post_content); echo $content; ?>

with

<?php $content = wpautop($s->post_content); echo $content; ?>

If that helps then you probably have an issue of the wpautop getting unhooked somewhere.

spuriousdata