Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a site that requires a lot of styling for post formats, I have never dealt with formats before but essentially what I want is : if post format is image... do this loop, if format is standard show

The problem is that I am using a filter in the loop on single.php to pick out the image posted and show it as a header. This seems to be getting in the way of the showing standard content mark up if the format is 'standard' function

Here is the single.php

                <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting">




                    <div class="content-img">


                        <?php
                        preg_match_all("/(<img [^>]*>)/",get_the_content(),$matches,PREG_PATTERN_ORDER);
                        for( $i=0; isset($matches[1]) && $i < count($matches[1]); $i++ ) {
                        echo $beforeEachImage . $matches[1][$i] . $afterEachImage;}?>

                    </div>      
                    <div class="content-text span8 pull-left">
                        <?php
                           ob_start();
                           the_content('Read the full post',true);
                           $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
                           ob_end_clean();
                           echo $postOutput;
                        ?>



                    </div>  
                    <div class="content-sidebar"><?php get_sidebar(); // sidebar 1 ?></div>
                </article> <!-- end article -->


                                                        <a class="fb-stamp" href="http://www.facebook.com/CreativeCardona"><img src="http://clients.kevinhowbrook.com/creativecardona/wp-content/uploads/2013/03/fb_stamp.png" /></a>

                <?php else : ?>

                  <?php the_content(); ?>

                <?php endif; ?>
share|improve this question
    
I'm pretty sure you'd define the custom post formats in functions.php, then they'd reference their own PHP file which contains the loop you'd need. So for example, Text format would go to post-text.php, Image format post-image.php, etc. Some info here: en.blog.wordpress.com/2013/01/15/post-formats and a how-to is here: wp.tutsplus.com/tutorials/proof-using-post-formats. If this helps, let me know and I'll put it into an answer. –  Pat Mar 24 '13 at 21:54
    
I have looked into the formats support but I have a feeling my match filters are getting in the way of it... Although that said your 2nd link looks like a place I need to look (the loop) so I will check that out. Thanks. Would you suggest I put my filters in the functions.php and call them from there? –  user29450 Mar 24 '13 at 22:09
    
I would say that's the best idea. Centralize your match filters into functions within functions.php, then call the function from within your post format PHP file. I'll add this to an official answer. –  Pat Mar 24 '13 at 22:19
add comment

1 Answer 1

up vote 0 down vote accepted

I'm pretty sure you'd define the custom post formats in functions.php, then they'd reference their own PHP file which contains the loop you'd need.

So for example, Text format would go to post-text.php, Image format post-image.php, etc.

You could add your match filters into a function within functions.php, and then call the function from within the post format PHP files.

Some info here: http://en.blog.wordpress.com/2013/01/15/post-formats

How-to is here: http://wp.tutsplus.com/tutorials/proof-using-post-formats.

share|improve this answer
    
Thanks for your help with this pat, managed to get it working, I think the problem was the the filters being in the loop, maybe forcing them to be applied no matter what. In the end I modded the functions.php to inlude my filters with markup, then called it from the loop eg... –  user29450 Mar 25 '13 at 16:01
    
<?php if ( has_post_format( 'image')){ image_post(); } else { the_content(); } ?> –  user29450 Mar 25 '13 at 16:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.