Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Damir Pristav
Damir Pristav
23,048 Points

What is the best way to use post formats ?

Is it better to create custom fields for each post format and show them when appropriate radio field is selected or some other way( using shortcodes, featured image...) ?

It would be nice to have a workshop or some project for this.

2 Answers

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Hi,

I'm a little confused by your question, can you try explaining again what you're trying to do. We do have several videos on working with custom post types and custom fields. Custom formats are something else though and usually you would just run a conditional statement in your code, check what post format it is, and then style the post accordingly.

Damir Pristav
Damir Pristav
23,048 Points

I am using this in home.php file

<?php 

        if( have_posts() ): while( have_posts() ): the_post();

                if( !get_post_format() ){

                    get_template_part('format', 'standard');

                }else{

                    get_template_part('format', get_post_format());

                }

            endwhile;endif;
?>

and this in format-video.php file:

<?php 

<article>
        <div class="post-video">
            <div class="post-heading">
                <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            </div>

            <div class="video-container">

            </div>
        </div>

        <?php the_excerpt(); ?>

        <div class="bottom-article">
            <ul class="meta-post">
                <li><i class="icon-calendar"></i><a href="<?php echo get_day_link('', '', ''); ?>"> <?php echo get_the_date(); ?></a></li>
                <li><i class="icon-user"></i><a href="<?php the_author_link(); ?>"> <?php the_author(); ?></a></li>
                <li><i class="icon-folder-open"></i><a href="<?php get_category_link(); ?>"> <?php the_category(); ?></a></li>
                <li><i class="icon-comments"></i><a href="<?php echo get_comments_link(); ?>"><?php echo get_comments_number(); ?> Comments</a></li>
            </ul>
            <a href="<?php the_permalink(); ?>" class="pull-right">Continue reading <i class="icon-angle-right"></i></a>
        </div>
</article>

Now i want the video to appear in .video-container div, but i don't know how to take the video url from the post content, how to extract video src from [video src="http://www.youtube.com/watch?v=_k3Rpfyi7nc&list=UUqHktcPJV7C7T3e9Cg4T4iw"] shortcode.

What code should be in video-container div ?

I've looked at some themes and almost all themes have custom fields for video embeded code and then they use the_field function. But i have read on the internet that this is not the best way to do this.

In format-gallery.php file i have this code:

<article>
    <div class="post-slider">
        <div class="post-heading">
            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        </div>
        <!-- start flexslider -->
        <div id="post-slider" class="flexslider">
            <ul class="slides">
                <?php 

                    $attachments = get_children( array(
                        'post_parent'    => get_the_ID(),
                        'post_status'    => 'inherit',
                        'post_type'      => 'attachment',
                        'post_mime_type' => 'image',
                        'numberposts'    => -1,
                        'order'          => 'ASC',
                        'orderby'        => 'menu_order',
                    ) );

                    if( $attachments ){
                        foreach( $attachments as $attachment ){
                            echo '<li>' . wp_get_attachment_image( $attachment->ID, $image_size ) . '</li>';
                        }
                    }

                ?>
            </ul>
        </div>
        <!-- end flexslider -->
    </div>

    <?php the_excerpt(); ?>

    <div class="bottom-article">
        <ul class="meta-post">
            <li><i class="icon-calendar"></i><a href="<?php echo get_day_link('', '', ''); ?>"> <?php echo get_the_date(); ?></a></li>
            <li><i class="icon-user"></i><a href="<?php the_author_link(); ?>"> <?php the_author(); ?></a></li>
            <li><i class="icon-folder-open"></i><a href="<?php get_category_link(); ?>"> <?php the_category(); ?></a></li>
            <li><i class="icon-comments"></i><a href="<?php echo get_comments_link(); ?>"><?php echo get_comments_number(); ?> Comments</a></li>
        </ul>
        <a href="<?php the_permalink(); ?>" class="pull-right">Continue reading <i class="icon-angle-right"></i></a>
    </div>
</article>

And this is ok, but i don't know what code to use in video post and audio post.