WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom theme - Only 1 post showing on the blog page (12 posts)

  1. TBRudy3
    Member
    Posted 1 year ago #

    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!!

  2. DaveCoast
    Member
    Posted 1 year ago #

    Is the one post that it is showing the last post?

  3. esmi
    Forum Moderator
    Posted 1 year ago #

    Have you reviewed creating a static front page?

  4. TBRudy3
    Member
    Posted 1 year ago #

    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.

  5. esmi
    Forum Moderator
    Posted 1 year ago #

    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

  6. TBRudy3
    Member
    Posted 1 year ago #

    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.

  7. DaveCoast
    Member
    Posted 1 year ago #

    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.

  8. TBRudy3
    Member
    Posted 1 year ago #

    Dave Coast.

    Thank you!!!

    3 hour headache overwith!

  9. TBRudy3
    Member
    Posted 1 year ago #

    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?

  10. DaveCoast
    Member
    Posted 1 year ago #

    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.

  11. TBRudy3
    Member
    Posted 1 year ago #

    Perfect.

    Thanks again for sticking with me. Really appreciate it!

  12. TBRudy3
    Member
    Posted 1 year ago #

    resolved

Topic Closed

This topic has been closed to new replies.

About this Topic