• In my theme I have a blog page and a homepage (without blog loop). Now I would like to add some blog posts on my homepage (like most recent).

    I am using the blog page as a template for the homepage ( I copied and renamed the original), wich works good. But I can’t make any changes to it without changing the original blog page (the loop is called in an external php).

    I Have no idea were to start.

    This is the piece on the homepage calling the blog loop:

    <!-- wrap start --><div class="content-wrap">
    
    		<?php if(have_posts()) : the_post(); ?>
    
    			<div id="main">
    				<div class="central-wrapper clearfix">
    					<div id="center" class="fullwidth">
    
    						<div id="content">
    							<?php if($gallery_select && $gallery_position == 1) : ?>
    								<?php codeus_gallery($gallery_select, $gallery_size, $gallery_style); ?>
    							<?php endif; ?>
    
    							<div class="inner">
    								<?php the_content(); ?>
    								<?php wp_link_pages( array( 'before' => '<div class="pagination"><div class="page-links-title">' . __( 'Pages:', 'codeus' ) . '</div>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
    <div class="bloghome">
    <?php codeus_blog_list(); ?>
    </div>
    								<?php if($quickfinder_position == 2) : ?>
    									<?php codeus_quickfinder($quickfinder_select); ?>
    								<?php endif; ?>
    
    								<?php if($portfolio_position == 2) : ?>
    									<?php codeus_portfolio(implode(',',$portfolio_select), $portfolio_size, $portfolio_count, $portfolio_filter, $portfolio_title); ?>
    								<?php endif; ?>
    
    								<?php if($gallery_select && $gallery_position == 3) : ?>
    									<?php codeus_gallery($gallery_select, $gallery_size, $gallery_style); ?>
    								<?php endif; ?>
    
    							</div>
    						</div><!-- #content -->
    					</div><!-- #center -->
    				</div><!-- .central-wrapper -->
    			</div><!-- #main -->
    
    		<?php endif; ?>
    
    	</div><!-- wrap end -->

    And this is the piece in the external php called blog.php

    <?php
    
    function codeus_blog_list() {
    	$page_num = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	$items_per_page = codeus_get_option('post_per_page') ? codeus_get_option('post_per_page') : 5;
    	$blog_loop = new WP_Query(array(
    		'post_type' => 'post',
    		'posts_per_page' => $items_per_page,
    		'paged' => $page_num
    	));
    	$pages_count = ceil($blog_loop->found_posts/$items_per_page);
    	global $post;
    	$portfolio_posttemp = $post;
    ?>
    <?php if($blog_loop->have_posts()) : ?>
    	<div class="blog_list">
    		<ul class="styled">
    			<?php while ( $blog_loop->have_posts() ) : $blog_loop->the_post(); ?>
    				<li class="clearfix">
    					<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    						<?php $image_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'codeus_post_list_image'); ?>
    						<div class="comment-info">
    							<a href="<?php echo get_permalink($post->ID); ?>" class="date-day"><?php echo get_the_date('d'); ?></a>
    							<div class="date-month"><?php echo get_the_date('M'); ?></div>
    						</div>
    						<div class="post-info">
    							<h3><a href="<?php echo get_permalink($post->ID); ?>"><?php the_title(); ?></a></h3>
    							<?php if($image_url[0]) : ?>
    								<div class="post-image">
    									<div class="image wrap-box shadow middle">
    										<div class="shadow-left"></div><div class="shadow-right"></div>
    										<a href="<?php echo get_permalink($post->ID); ?>"><img src="<?php echo $image_url[0]; ?>" alt="<?php the_title(); ?>" /></a>
    									</div>
    								</div>
    							<?php endif; ?>
    							<div class="text clearfix"><?php the_excerpt(); ?></div>
    							<?php codeus_author_info(get_the_ID()); ?>
    						</div>
    					</div>
    				</li>
    				<?php $post = $portfolio_posttemp; wp_reset_postdata(); ?>
    			<?php endwhile; ?>
    		</ul>
    		<?php codeus_pagination($page_num, $pages_count); ?>
    	</div>
    <?php endif; ?>

    Help would be so welcome!!

Viewing 1 replies (of 1 total)
  • Thread Starter vipete

    (@vipete)

    Remember, I don’t want to make changes in the original blog.php, because the normal blog page needs to work as it is now. I would like to make the blog work on the homepage also, but just with a maximum of 3 posts showing, perhaps of a certain category.

Viewing 1 replies (of 1 total)
  • The topic ‘Adding blog loop on homepage’ is closed to new replies.