This topic has 3 replies, 2 voices, and was last updated 9 years by parousia.

  • Author
  • #83982
     parousia
    Participant

    I’m trying to create a second blog loop using a template with the code below.

    The problem I’m having is when I add this line of code to the while loop.

    COPY CODE
    
    $count++;
            if ($count == 3) { ?>
                <div class="blog-sticky-post-wrapper">
                    <div class="blog-sticky-post">
                        <h3>Latest <span class="title-key-color">Photographs</span></h3>
                        <?php echo do_shortcode("[rtmedia_gallery global=\"true\" per_page=\"8\" media_title=\"false\"]"); ?>
                        <div class="homepage-btn">
                            <a href="http://www.mysite.com/photographs/"><span></span>More photographs</a>
                        </div>
                    </div>
                </div>
    
                <?php
                             }
    

    Not all the posts display and a random post that I havent created shows up. This code works fine for the main blog page index file but not on this template? What am I missing?

    Any help greatly appreciated!

    COPY CODE
    
    <?php
    /**
     * Template Name: second-blog
     *
     * Description: Template withour sidebar
     *
     * @package WordPress
     * @subpackage Kleo
     * @author SeventhQueen <themesupport@seventhqueen.com>
     * @since Kleo 1.0
     */
    
    get_header(); ?>
    
    <?php $args = array(
    	'post_type' => 'post',
        'post_status' => 'publish',
        'posts_per_page' => '10',
        'orderby' => 'ID'
        );
    
        $query = new WP_Query( $args );
    ?>
    
    <?php
    //Specific class for post listing */
    $blog_type = sq_option( 'blog_type','masonry' );
    $blog_type = apply_filters( 'kleo_blog_type', $blog_type );
    
    $template_classes = $blog_type . '-listing';
    if ( sq_option('blog_archive_meta', 1 ) == 1 ) {
        $template_classes .= ' with-meta';
    } else {
        $template_classes .= ' no-meta';
    }
    if ( $blog_type == 'standard' && sq_option('blog_standard_meta', 'left' ) == 'inline' ) {
        $template_classes .= ' inline-meta';
    }
    
    add_filter('kleo_main_template_classes', create_function( '$cls','$cls .=" posts-listing ' . $template_classes.'"; return $cls;' ));
    
    /***************************************************
    :: Title section
    ***************************************************/
    
    //title
    $title_arr['show_title'] = true;
    $page_title = kleo_title();
    
    if ( sq_option( 'title_location', 'breadcrumb' ) == 'main' ) {
    	$title_arr['show_title'] = false;
    }
    
    //breadcrumb
    $title_arr['show_breadcrumb'] = true;
    if( sq_option( 'breadcrumb_status', 1 ) == 0 ) {
    	$title_arr['show_breadcrumb'] = false;
    }
    
    //extra info
    if ( sq_option( 'title_info', '' ) == '' ) {
    	$show_info = FALSE;
    }
    else {
    	$show_info = TRUE;
    }
    
    //If we have designated a page for latest posts like Blog page
    if ( get_option( 'page_for_posts' ) ) {
    	$blogpage_id = get_option('page_for_posts');
    	$page_title = get_the_title( $blogpage_id );
    
        if ( get_cfield( 'custom_title', $blogpage_id ) && get_cfield( 'custom_title', $blogpage_id ) != ''  ) {
            $page_title = get_cfield( 'custom_title', $blogpage_id );
        }
    
    	if( get_cfield( 'title_checkbox', $blogpage_id ) == 1 ) {
    		$title_arr['show_title'] = false;
    	}	
    
    	if ( get_cfield( 'hide_info', $blogpage_id ) == 1 ) {
    		$show_info = FALSE;
    	}
    
    	if( get_cfield( 'hide_breadcrumb', $blogpage_id ) == 1 ) {
    		$title_arr['show_breadcrumb'] = false;
    	} else if ( get_cfield( 'hide_breadcrumb', $blogpage_id ) === '0' ) {
    		$title_arr['show_breadcrumb'] = true;
    	}
    }
    
    $title_arr['title'] = $page_title;
    
    if ( ( isset( $title_arr['show_breadcrumb'] ) && $title_arr['show_breadcrumb'] ) || $show_info === TRUE || $title_arr['show_title'] ) {
    	echo kleo_title_section( $title_arr );
    }
    /* END TITLE SECTION */
    ?>
    
    <div id="index-slider">
    <?php echo do_shortcode("[rev_slider alias=\"news-gallery6\"]");?>
    </div>
    
    <?php get_template_part('page-parts/general-before-wrap');?>
    
    <?php
    	if (kleo_has_featured_posts() ) {
    		// Include the featured content template.
    		get_template_part( 'featured-content' );
    	}
    ?>
    
    <?php
    if ( $query->have_posts() ) : ?>
    
        <?php if (sq_option('blog_switch_layout', 0) == 1 ) : /* Blog Layout Switcher */ ?>
    
        <?php kleo_view_switch( sq_option( 'blog_enabled_layouts' ), $blog_type ); ?>
    
        <?php endif; ?>
    
        <?php
        if ($blog_type == 'masonry') : ?>
            <div class="row responsive-cols kleo-masonry per-row-<?php echo sq_option( 'blog_columns', 3 );?>">
        <?php endif; ?>
    
    	<?php
    	// Start the Loop.
    	while ( $query->have_posts() ) : $query->the_post();
             $count++;
            if ($count == 3) { ?>
                <div class="blog-sticky-post-wrapper">
                    <div class="blog-sticky-post">
                        <h3>Latest <span class="title-key-color">Photographs</span></h3>
                        <?php echo do_shortcode("[rtmedia_gallery global=\"true\" per_page=\"8\" media_title=\"false\"]"); ?>
                        <div class="homepage-btn">
                            <a href="http://www.mysite.com/photographs/"><span></span>More photographs</a>
                        </div>
                    </div>
                </div>
    
                <?php
                             }
    		/*
    		 * Include the post format-specific template for the content. If you want to
    		 * use this in a child theme, then include a file called called content-___.php
    		 * (where ___ is the post format) and that will be used instead.
    		 */
    		?>
    		<?php
    		if ( $blog_type != 'standard' ) :
                get_template_part( 'page-parts/post-content-' . $blog_type );
    		else:
                get_template_part( 'content', get_post_format() );
    		endif;
    
    	endwhile;
    
    	if ($blog_type == 'masonry') : ?>
    
    		</div>
    	<?php endif; ?>	
    
    	<?php
    
    	// Post navigation.
    	kleo_pagination();
    
        wp_reset_postdata();
    else :
    	// If no content, include the "No posts found" template.
    	get_template_part( 'content', 'none' );
    
    endif;
    ?>
    
    <?php get_template_part('page-parts/general-after-wrap');?>
    
    <?php get_footer(); ?>
    
    #84024
     Laura
    Moderator

    Hello, will assign the ticket to a higher support level who can help and advise you in your query.
    Thanks! 🙂

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    Laura Solanes - Graphic Designer and Web Designer

    Please be patient as I try to answer each topic as fast as i can.

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Always happy to help you 🙂

    #84036
     parousia
    Participant
    This reply has been set as private.
    #84097
     parousia
    Participant

    Hi,

    I managed to solve this problem, it seems I needed to load the post templates in the if statement first before I added my own content as below.

    COPY CODE
    
    	while ( $query->have_posts() ) : $query->the_post();
             $count++;
            if ($count == 2) { 
            
    		if ( $blog_type != 'standard' ) :
            get_template_part( 'page-parts/post-content-' . $blog_type );
    		else:  
                get_template_part( 'content', get_post_format() );
    		endif;
                
                ?>
                <div class="blog-sticky-post-wrapper">
                    <div class="blog-sticky-post">
                        <h3>Latest <span class="title-key-color">Photographs</span></h3>
                        <?php echo do_shortcode("[rtmedia_gallery global=\"true\" per_page=\"8\" media_title=\"false\"]"); ?>
                        <div class="homepage-btn">
                            <a href="http://www.cultexposure.com/photographs/"><span></span>More photographs</a>                        
                        </div>
                    </div>
                </div>
                
                <?php
                              
    
                             } else {
    		/*
    		 * Include the post format-specific template for the content. If you want to
    		 * use this in a child theme, then include a file called called content-___.php
    		 * (where ___ is the post format) and that will be used instead.
    		 */
    		?>
    		<?php 
    		if ( $blog_type != 'standard' ) :
                get_template_part( 'page-parts/post-content-' . $blog_type );
    		else:  
                get_template_part( 'content', get_post_format() );
    		endif;
            }
            wp_reset_postdata(); 
    	endwhile;
    
Viewing 4 posts - 1 through 4 (of 4 total)

The forum ‘General questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?