• I keep getting errors with this piece of code.
    I know for a fact that the header, footer, and sidebar are clean because I use them in a “page.php” and they work just fine.

    Here’s my code:

    <?php
    /*
    Template Name: Main
    */
    ?>
    <?php get_header(); ?>
    <div id="left">
    <div id="home-postit">
        <div id="twitter">
                <h2 >Twitter Updates</h2>
                <a href="https://twitter.com/mrmunozteacher" target="_blank"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/latest-tweet-link.png" width="274" height="23" border="0px"/></a>
                <ul id="twitter_update_list"></ul>
              <script type="text/javascript" src="https://twitter.com/javascripts/blogger.js"></script>
              <script type="text/javascript" src="https://twitter.com/statuses/user_timeline/mrmunozteacher.json?callback=twitterCallback2&count=1"></script>
        </div><!-- end id="twitter"-->
    </div><!-- end id="home-postit"-->
    <div id="latest-post">
    <?php query_posts('showposts=1'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="latest-date"><span class="month"><?php the_time('M') ?></span><br /><span class="day"><?php the_time('j') ?></span><br /><span class="year"><?php the_time('Y') ?></span></div>
    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    <div class="latest-entry">
    <?php the_excerpt(); ?>
    <a href="<?php the_permalink() ?>"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/read-more.png" alt="Read more of <?php the_title(); ?>" width="87" height="50" class="read-more"/></a></div>
    <div class="latest-thumb"><?php the_post_thumbnail(); ?></div>
    <div class="clear"></div>
    <?php endwhile; else: ?>
        <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
    </div><!-- end id="latest-entry"-->
    </div><!-- end id="left"-->
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

Viewing 11 replies - 1 through 11 (of 11 total)
  • Well, first of all you are missing the <?php if ( ! have_posts() ) : ?> which should be placed right before <?php while (have_posts()) : the_post(); ?>.

    Moderator James Huff

    (@macmanx)

    Can you quote the errors?

    Thread Starter hoss9009

    (@hoss9009)

    Parse error: syntax error, unexpected $end in /public_html/testmu/wp-content/themes/mr-munoz/home.php on line 32

    thanks a ton guys!
    I threw in the <?php if ( ! have_posts() ) : ?> and it didn’t change anything.

    Moderator James Huff

    (@macmanx)

    Line 32 is <?php get_sidebar(); ?> so I’m going to guess that something is wrong with either your sidebar or the sidebar template.

    macmanx may be right but perhaps try this, forget the if have posts and this these:

    <?php } ?>
    <?php wp_reset_query(); ?>

    in place of:

    <?php endwhile; else: ?>

    And remove:

    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
    Thread Starter hoss9009

    (@hoss9009)

    @jameslaws
    like this?:

    <?php } ?>
    <?php wp_reset_query(); ?>
    <div class="latest-date"><span class="month"><?php the_time('M') ?></span><br /><span class="day"><?php the_time('j') ?></span><br /><span class="year"><?php the_time('Y') ?></span></div>
    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    <div class="latest-entry">
    <?php the_excerpt(); ?>
    <a href="<?php the_permalink() ?>"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/read-more.png" alt="Read more of <?php the_title(); ?>" width="87" height="50" class="read-more"/></a></div>
    <div class="latest-thumb"><?php the_post_thumbnail(); ?></div>
    <div class="clear"></div>
    </div><!-- end blog-->
    
    <?php } ?>
    <?php wp_reset_query(); ?>
    <?php else : ?>

    I still have the same error ??

    No. You still want to keep the:

    <?php query_posts('showposts=1'); ?>
    <?php while (have_posts()) : the_post(); ?>

    in place of the top:

    <?php } ?>
    <?php wp_reset_query(); ?>
    Thread Starter hoss9009

    (@hoss9009)

    New error:
    Parse error: syntax error, unexpected '}' in /public_html/testmu/wp-content/themes/mr-munoz/home.php on line 19

    Here’s my loop:

    <div id="latest-post">
    <?php } ?>
    <?php wp_reset_query(); ?>
    <?php query_posts('showposts=1'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="latest-date"><span class="month"><?php the_time('M') ?></span><br /><span class="day"><?php the_time('j') ?></span><br /><span class="year"><?php the_time('Y') ?></span></div>
    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    <div class="latest-entry">
    <?php the_excerpt(); ?>
    <a href="<?php the_permalink() ?>"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/read-more.png" alt="Read more of <?php the_title(); ?>" width="87" height="50" class="read-more"/></a></div>
    <div class="latest-thumb"><?php the_post_thumbnail(); ?></div>
    <div class="clear"></div>
    <?php endwhile; else: ?>
        <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
    </div><!-- end id="latest-entry"-->

    I guess you aren’t getting my instructions so I apologize if I am unclear. Replace the above with:

    <div id="latest-post">
    <?php query_posts('showposts=1'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="latest-date"><span class="month"><?php the_time('M') ?></span><br /><span class="day"><?php the_time('j') ?></span><br /><span class="year"><?php the_time('Y') ?></span></div>
    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    <div class="latest-entry">
    <?php the_excerpt(); ?>
    <a href="<?php the_permalink() ?>"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/read-more.png" alt="Read more of <?php the_title(); ?>" width="87" height="50" class="read-more"/></a></div>
    <div class="latest-thumb"><?php the_post_thumbnail(); ?></div>
    <div class="clear"></div>
    <?php } ?>
    <?php wp_reset_query(); ?>
    </div><!-- end id="latest-entry"-->

    Don’t forget your opening <div id="latest-post"> div right before that though.

    Thread Starter hoss9009

    (@hoss9009)

    Still not working. ??
    Here’s the error Parse error: syntax error, unexpected '}' in /public_html/testmu/wp-content/themes/mr-munoz/home.php on line 28

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘What am I doing wrong?’ is closed to new replies.