• Resolved TBRudy3

    (@tbrudy3)


    I built a custom theme and would like to have a static page on the home page and an internal page for my blog posts.

    Here is the loop on my main index.php

    <?php get_header(); ?>
    
    	<div id="contentWrap" class="group">
    
    		<?php get_sidebar(); ?>
    
    		<div id="article">
    			<?php if (have_posts()) :while (have_posts()) : the_post();?>
    			<?php endwhile; ?>
    
    			<?php endif;?>
    
    			<h2><?php the_title(); ?></h2>
    
    				<div id="entryItem">
    				<?php the_content(); ?>
    
    				</div><!--entryItem-->		
    
    		</div><!--article-->
    
    	</div><!--contentWrap-->
    
    </div><!--mainWrapper-->
    
    <?php get_footer(); ?>

    Here is the code for my blog template page.

    <?php /* Template Name: Blog */ ?>
    
    <?php get_header(); ?>
    
    	<div id="contentWrap" class="group">
    
    		<?php get_sidebar(); ?>
    
    		<div id="article">
    			<?php
    			$temp = $wp_query;
    			$wp_query= null;
    			$wp_query = new WP_Query();
    			$wp_query->query('showposts=ALL'.'&paged='.$paged);
    			while ($wp_query->have_posts()) : $wp_query->the_post();
    			?>
    
    			<?php endwhile; ?>
    
    			<?php $wp_query = null; $wp_query = $temp;?>
    
    			<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    			<p> Posted By <?php the_author(); ?></p>
    
    				<div id="entryItem">
    				<?php the_content(); ?>
    
    				</div><!--entryItem-->		
    
    		</div><!--article-->
    
    	</div><!--contentWrap-->
    
    </div><!--mainWrapper-->
    
    <?php get_footer(); ?>

    It seems to be working, but it will only show one post.

    Help please!!

Viewing 11 replies - 1 through 11 (of 11 total)
  • Is the one post that it is showing the last post?

    Have you reviewed creating a static front page?

    Thread Starter TBRudy3

    (@tbrudy3)

    It depends.

    If I change the code to this:

    <?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('posts_per_page=5'.'&paged='.$paged);
    while ($wp_query->have_posts()) : $wp_query->the_post();
    ?>

    And then change the number from 5 (to whatever) it will determine the blog post.

    The static page is not the issue. Unless that may be interfering with what I am trying to accomplish. Although I don’t think so.

    I also tried to just display all of my latest posts on the home page. And when I switch to the Twenty Twelve theme it works…switch back to my theme and it displays only one post.

    My hunch is that I need something else in my funtions.php file

    Hope this helps.

    The static page is not the issue.

    Oh – I think it is. If you configure WordPress to use a static front page, it will use the index.php template file on your nominated inner page by default

    Thread Starter TBRudy3

    (@tbrudy3)

    Hmm,

    Is there a workaround for this?

    Also seems strange because when I set the front page to the latest posts, it still is only showing one post.

    Thank you for your help.

    Looks like you endwhile is in the wrong place and you are finishing your loop before you try to do anything with an individual post. Try putting it just before you close the article div.

    Thread Starter TBRudy3

    (@tbrudy3)

    Dave Coast.

    Thank you!!!

    3 hour headache overwith!

    Thread Starter TBRudy3

    (@tbrudy3)

    Actually I take that back. Now that makes it show one post and the “blog” page itself.

    I have a post labelled blog so I thought it was working.

    Any other suggestions?

    Well one page at a time. Walk through your code and compare it to the basic loop on the loop documentation page:

    <?php if (have_posts()) : ?>
                   <?php while (have_posts()) : the_post(); ?>
                   <!-- do stuff ... -->
                   <?php endwhile; ?>
         <?php endif; ?>

    The the_content() tag must be inside the loop. The loop boundaries are the while/endwhile.

    The <?php $wp_query = null; $wp_query = $temp;?> line resets the query and needs to be after the endwhile.

    Thread Starter TBRudy3

    (@tbrudy3)

    Perfect.

    Thanks again for sticking with me. Really appreciate it!

    Thread Starter TBRudy3

    (@tbrudy3)

    resolved

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Custom theme – Only 1 post showing on the blog page’ is closed to new replies.