• I really hope someone can help me out!

    I’m trying to implement code that I found on a blog, everyone says it works and everyone loves it. Here’s the code:

    <?php while(have_posts()) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <ul>
        <?php $totalposts = get_posts('numberposts=200&offset=0');
              foreach($totalposts as $post) :
        ?>
        <li>
              <?php the_time('M j') ?> : <a href="<?php the_permalink(); ?>"><? php the_title(); ?></a>
    		  Posted in: <?php the_category(', ') ?>
    		  <?php comments_number('No Comments', 'One Comment', '% Comments' );?>
        </li>
    
        <? php endforeach; ?>
    </ul>
    
    <?php endwhile; ?>

    Here’s my template with the code in the (I think) correct spot:

    <?php
    /*
    Template Name: Archives
    */
    ?>
    
      <?php get_header(); ?> 
    
    	<?php if (have_posts()) : ?>
    
    	   <?php while(have_posts()) : the_post(); ?>  
    
    	<!-- content starts here -->
    
    	<div id="content">
    
    		<!-- posts starts here -->
    
    		<div id="content_posts_wrapper">
    
    				<!-- individual post starts there -->
    
    				<div class="post">
    
    				<!-- begin content of post -->
    
    				<div class="page_content_post">	
    
    					<h2><?php the_title(); ?></h2>
    
    				<div class="actual_post">
    
    <ul>
        <?php $totalposts = get_posts('numberposts=200&offset=0');
               foreach($totalposts as $post) :
         ?>
         <li>
               <?php the_time('M j') ?> : <a href="<?php the_permalink(); ?>"><? php the_title(); ?></a>
               Posted in: <?php the_category(', ') ?>
               <?php comments_number('No Comments', 'One Comment', '% Comments' );?>
         </li>  
    
         <? php endforeach; ?>
     </ul>  
    
    				</div>
    
                    </div>
    
    				<!-- end contet of post -->
    
    				<div class="clear"></div>
    				</div>
    
    				<!-- individual posts end here -->
    
    				<?php endwhile; ?>
    
    	<?php endif; ?>
    
    		</div>
    
    		<!-- posts end here -->
    
    		<?php get_sidebar(); ?> 
    
    <?php get_footer(); ?>

    But I’m getting this error:

    Parse error: parse error, unexpected T_STRING in /home/content/c/o/l/collegemovie/html/wp-content/themes/dreamworks_redux1.4/archives.php on line 38

    Any help anyone can provide I would be very much appreciative. Thanks so much in advance.

Viewing 8 replies - 1 through 8 (of 8 total)
  • This line is the problem…

    foreach($totalposts as $post) :

    Try..

    foreach($totalposts as $post);

    Thread Starter mr_director

    (@mr_director)

    That line didn’t fix the problem.

    Should I change it back or keep it to what you suggested?

    Thread Starter mr_director

    (@mr_director)

    If it helps anyone, the error says that it’s on line 38. This is line 38:

    <?php the_time('M j') ?> : <a href="<?php the_permalink(); ?>"><? php the_title(); ?></a>

    It’s not that line that has the issue, it’s the one mentioned but it carries over to the next PHP line because of the unexpected T_STRING…. it’s a PHP error…

    I’m not use to foreach loops so much….

    Try using…

    foreach(stuff) {
    
    your other stuff
    
    }

    Obviously with your code inside the foreach loop though…

    Just plonking it inside the curly brackers…

    Failing that drop the ; or : , whichever you have…

    I’m just suggesting without testing, so forgive me if it’s not perfect first time… 😉

    Thread Starter mr_director

    (@mr_director)

    When you say “your other stuff” where would that stop? AKA, where would I put the closing bracket?

    After <? php endforeach; ?> or before? Somewhere else?

    <?php } endforeach; ?>

    Not sure you even need the endforeach in there either, try it with the endforeach and without if that fails.

    Thread Starter mr_director

    (@mr_director)

    Unfortunately, that didn’t help. I ended up going with a different code. I’m having another problem, but it’s CSS related, so I won’t post it here.

    Thanks so much for trying. Anyone interested I ended up using this code and it works great: http://wpguy.com/articles/an-archives-page-with-all-the-posts-in-cronological-order/comment-page-1/#comment-530

    I’m sure with testing it could work….

    Glad you found something suited..

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘unexpected T_STRING error when trying to create archives loop’ is closed to new replies.