• Resolved omgitsalisa

    (@omgitsalisa)


    I’m trying to edit my template so that only posts from a specified category will show up on the main page. I’ve read every page I can find about how to do it and it always ends up with a parse error. I don’t fully understand php syntax, so it’s impossible for me to go troubleshooting and I am at my wit’s end ’cause I’m sure it’s something simple. So can anyone point out why this code gets me this error: Parse error: syntax error, unexpected T_ELSE in /home/.dinny/unoriginal/fuzzystars.net/wp-content/themes/fuzzystars/index.php on line 37

    <?php get_header(); ?>
    <?php get_sidebar(); ?>
    	<div id="content">
    
    <?php
       if (is_home()) {
          query_posts("cat=12");
       }
    ?>
    
    <?php while (have_posts()) : the_post(); ?>
    
    			<div class="post">
    				<h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    				<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
    
    				<div class="entry">
    					<?php the_content('Read the rest of this entry &raquo;'); ?>
    				</div>
    
    				<p class="postmetadata"><img src="<?php bloginfo('template_directory'); ?>/images/folder_edit.png" alt="category"></img>  <?php the_category(', ') ?>  <img src="<?php bloginfo('template_directory'); ?>/images/comments.png" alt="comments"></img>  <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> <?php edit_post_link('//Edit'); ?></p> 
    
    				<!--
    				<?php trackback_rdf(); ?>
    				-->
    			</div>
    
    		<?php endwhile; ?>
    
    		<div class="navigation">
    			<div class="alignleft"><?php posts_nav_link('','','&laquo; Previous Entries') ?></div>
    			<div class="alignright"><?php posts_nav_link('','Next Entries &raquo;','') ?></div>
    		</div>
    
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center"><?php _e("Sorry, but you are looking for something that isn't here."); ?></p>
    		<?php include (TEMPLATEPATH . "/searchform.php"); ?>
    
    	<?php endif; ?>
    
    <?php get_footer(); ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The_Loop – look for the line that says: the Loop starts here… and compare it with your first line.

    Thread Starter omgitsalisa

    (@omgitsalisa)

    I get that it’s not the same, but I was using the example from the Template Tags/query posts page to edit it so that I will get the desired results and the only place I could find where someone explicitly told me where to copy the code said to replace the first line the Loop with it. If that’s not right, can you tell me what is?

    You can replace the first line… just be careful to remove other lines, too.

    You see the first line is
    if have_post...
    ….do this and that, show this and that
    …. and goes on and on – and at certain point says
    <?php else : ?>
    do this
    then finally,
    endif

    Now if you took out the first if – the “else” code is “unexpexted” as your error says, because there was no condition set up initially for it. So, bring back the initial IF or remove the whole ELSE (do this) part.

    And next time just use a plugin, like Advanced Category Excluder – and your day will be easier ??

    Thread Starter omgitsalisa

    (@omgitsalisa)

    Ah, I think I understand it now. I was confused because I thought that since there was an if, it was all covered. I didn’t recognize that the only if statement I had was just telling it whether it needed to do the query or not, not what to do with stuff after that. I thank you for your help and have gotten it sorted out. ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Parse error when trying to exclude categories from home page’ is closed to new replies.