WordPress.org

Ready to get started?Download WordPress

Forums

Blog Listings Template - Used for multiple parent blogs (2 posts)

  1. Cathalmb
    Member
    Posted 9 months ago #

    Hi,

    I'm setting up a blog listings template for a site, and I need this template to be used across the site, various sections using there own blog listings page. Calling posts depending on the Parent category.

    i.e:

    Fruit (Parent)
    - Fruit Blog (Listings page for all Fruit related posts)

    Veg (Parent)
    - Veg Blog (Listings page for all Veg related posts)

    I've set my args up like this:

    $args = array(
                        'post_type'      => 'parent',
                        'paged'          => $paged,
                        'posts_per_page' => 6,
                        'order'          => 'DESC',
                        'orderby'        => 'date',
                        'category'       => 'parent',
                        );

    Is there anything else I'm missing that I should have added?

  2. Cathalmb
    Member
    Posted 9 months ago #

    My full code is:

    <div id="bloglistings">
    
                        <?php wp_reset_query(); ?>
    
                        <?php
    
                        $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    
                        $args = array(
                        'post_type'      => 'post',
                        'paged'          => $paged,
                        'posts_per_page' => 6,
                        'post_parent'    => $pagename,
                        'order'          => 'DESC',
                        'orderby'        => 'ID',
                        );
    
                        $wp_query = new WP_Query( $args );
    
                        if ( $wp_query->have_posts() ) : ?>
    
                        <div class="row">
    
                                <?php $count=0; ?>
                                <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
    
                                <div class="span6">
                                    <div class="media feature one">
                                        <a class="pull-left" href="<?php the_permalink(); ?>">
    									<?php echo get_the_post_thumbnail($page->ID, 'thumbnail', array('class' => 'img-circle')); ?>
                                        <img class="hoverimage" src="<?php echo get_template_directory_uri(); ?>/img/icon-read-bloglistings.png" alt="">
                                        </a>
                                        <div class="media-body">
                                            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                            <p class="date"><?php the_time('F j, Y'); ?></p>
                                            <p><?php
                                                $my_excerpt = get_the_excerpt();
                                                if ( $my_excerpt != '' ) {
                                                    // Some string manipulation performed
                                                }
                                                echo $my_excerpt; // Outputs the processed value to the page
                                                ?>
                                            </p>
                                        </div>
                                    </div>
                                    </div>
    
                                    <?php $count++; ?>
    
                                        <?php if ($count==2 ||$wp_query->found_posts==0) : 
    
                                            echo '</div><div class="row">';
    
                                        ?>
    
                                    <?php $count=0; ?>
    
                                        <?php endif; ?>
                                        <?php endwhile; ?>
    
                                    <?php else : ?>
                                        <h2>Sorry but there are no posts.</h3>
                                    <?php endif; ?>
    
                                    <!-- PAGINATION -->
    
                                <div class="pagination">
                                    <ul>
                                        <li>
                                            <?php
                                                        $big = 999999999; // need an unlikely integer
    
                                                        echo paginate_links( array(
                                                        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big
                                                ) ) ),
                                                        'format' => '?paged=%#%',
                                                        'current' => max( 1, get_query_var('paged') ),
                                                        'total' => $wp_query->max_num_pages,
                                                ) );
                                            ?>
                                        </li>
                                    </ul>
                                </div>
    
                                <?php wp_reset_query(); ?>
    
                        </div><!-- /.row -->
    
                      </div><!--/bloglistings-->

Reply

You must log in to post.

About this Topic