• So I’m trying to create a loop on a page template but the very same loop I use on my main blog page doesn’t work on a page template.

    can someone tell me what I’m doing wrong?

    <?php
    /*
    Template Name: Blog_Template
    */
    ?>
    
    <?php get_header(); ?> <!-- gets header.php. open html, wrapper div open. header div closed -->
    
    <div id="container">
    	<?php if(have_posts()) : ?>
    		<?php while(have_posts()) : the_post(); ?>  <!-- Begining of "The Loop" -->
    
    			 <!-- If the post is in the category 4 (News), we simply pass to the next post. -->
    			<?php if (in_category('3')) continue; ?>
    
    			<div class="post" id="post-<?php the_ID(); ?>"> <!-- Start of Each Post -->
    				<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <!-- Title for Posts -->
    				<div class="entry">
    					<?php the_content(); ?>
    					<p class="postmetadata"> <!-- Metadata for posts (Category, comments author etc) -->
    						<?php _e('Categories:'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
    						<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?> <?php edit_post_link('Edit', ' | ', ''); ?>
    					</p>
    				</div>
    			</div>
    		<?php endwhile; ?>
    		<div class="navigation"> <?php posts_nav_link("|","<<","&#187"); ?> </div> <!-- posts_nav_link('in between','before','after') -->
    	<?php else: ?>
    		<div class="post">
    			<h2><?php _e('Not Found'); ?></h2> <!-- only displays if no posts are found -->
    		</div>
    	<?php endif; ?>
    </div>
    
    <?php get_sidebar(); ?> <!-- gets sidebar.php completely closed. -->
    
    <?php get_footer(); ?> <!-- gets footer.php div wrapper closed also closes html and body -->
Viewing 1 replies (of 1 total)
  • Pages don’t have categories:
    <?php if (in_category('3')) continue; ?>
    <?php _e('Categories:'); ?> <?php the_category(', ') ?>

    <?php posts_nav_link("|","<<","&#187"); ?> won’t work on Pages.

    Use <div <?php post_class() ?> not <div class="post" to ensure that your Pages end up with the right classes.

    Check out the page.php file in the default template for further ideas for page templates. If you want to create a page of posts, see:

    http://codex.ww.wp.xz.cn/Pages#A_Page_of_Posts

Viewing 1 replies (of 1 total)

The topic ‘My loop appears to be broken’ is closed to new replies.