0

This question already has an answer here:

I'm trying to customize index.php of my theme in order to return/display only one post format (images in this case), and hide all the rest(aside, video, link...). I tried to implement this code in my index page, but I get error. I Hope someone can help.

$args = array(
    'post_type'=> 'post',
    'post_status' => 'publish',
    'order' => 'DESC',
    'tax_query' => array(
        array(
            'taxonomy' => 'post_format',
            'field' => 'slug',
            'terms' => array( 'post-format-image' ),
        )
    )
);

Code of index.php

<div class="content">

    <?php if (have_posts()) : ?>

        <?php
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $total_post_count = wp_count_posts();
        $published_post_count = $total_post_count->publish;
        $total_pages = ceil( $published_post_count / $posts_per_page );


        if ( "1" < $paged ) : ?>

            <div class="page-title">

                <h4><?php printf( __('Page %s of %s', 'fukasawa'), $paged, $wp_query->max_num_pages ); ?></h4>

            </div> <!-- /page-title -->

            <div class="clear"></div>

        <?php endif; ?>

        <div class="posts" id="posts">

            <?php while (have_posts()) : the_post(); ?>

                <?php get_template_part( 'content', get_post_format() ); ?>

            <?php endwhile; ?>

        <?php endif; ?>

    </div> <!-- /posts -->

marked as duplicate by Max Yudin, Dave Romsey, cjbj, Jack Johansson, Howdy_McGee Jun 21 '17 at 21:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • It's using wordpress core post format. You can change default post format from Setting> writing > Default Post Format. – Porosh Ahammed Jun 7 '17 at 19:13
0

I solved the problem. All I need to add is the following line of code query_posts( $args ); The result will be something like this:

<div class="content">

    <?php if (have_posts()) : ?>

        <?php
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $total_post_count = wp_count_posts();
        $published_post_count = $total_post_count->publish;
        $total_pages = ceil( $published_post_count / $posts_per_page );


        if ( "1" < $paged ) : ?>

            <div class="page-title">

                <h4><?php printf( __('Page %s of %s', 'fukasawa'), $paged, $wp_query->max_num_pages ); ?></h4>

            </div> <!-- /page-title -->

            <div class="clear"></div>

        <?php endif; ?>

        <?php 
                $args = array(
                'post_type'=> 'post',
                'post_status' => 'publish',
                'order' => 'DESC',
                'tax_query' => array(
                array(
                    'taxonomy' => 'post_format',
                    'field' => 'slug',
                    'terms' => array( 'post-format-image' ),

                )
            )
        );
                query_posts( $args );
    ?>

        <div class="posts" id="posts">

            <?php while (have_posts()) : the_post(); ?>

                <?php get_template_part( 'content', get_post_format() ); ?>

            <?php endwhile; ?>

        <?php endif; ?>

    </div> <!-- /posts -->

Not the answer you're looking for? Browse other questions tagged or ask your own question.