Jump to content

[SOLVED] Can somebody figure out the problem with this code?


beg-inner

Recommended Posts

Hi everyone,

 

Sorry, I'm a beginner in PHP, the following code is from archive.php file of a wordpress site.

 

when runs, it returns parse error, unexpected $end in the last line.

 

When I remove the if and the while statements those locates just beneath <!--content--> the error goes

 

But should I remove them or keep them and add another line to complete the code?

 

Thanks in advance.

 

<?php get_header(); ?>
    <div id="right">
        <?php     /* Widgetized sidebar, if you have the plugin installed. */
                    if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
        
<?php if (function_exists('dynamic_sidebar')) dynamic_sidebar('right_menu'); ?><?php endif; ?>

    </div>

    


        

        <!--page content-->


<!--Content -->


<div id="content">    <?php if (have_posts()) : ?>

        <?php while (have_posts()) : the_post(); ?>
<?php if (have_posts()) : ?>

       <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
       <?php /* If this is a category archive */ if (is_category()) { ?>
        <h2 class="pagetitle">أرشيف تصنيف ‘<?php single_cat_title(); ?>‘</h2>
       <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
        <h2 class="pagetitle">أرشيف الوسم ‘<?php single_tag_title(); ?>’</h2>
       <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
        <h2 class="pagetitle">أرشيف يوم <?php the_time('j F Y'); ?></h2>
       <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
        <h2 class="pagetitle">أرشيف شهر <?php the_time('F Y'); ?></h2>
       <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
        <h2 class="pagetitle">أرشيف عام <?php the_time('Y'); ?></h2>
      <?php /* If this is an author archive */ } elseif (is_author()) { ?>
        <h2 class="pagetitle">أرشيف الكاتب</h2>
       <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
        <h2 class="pagetitle">أرشيف المدونة</h2>
       <?php } ?>


    <div class="clear"></div>
<div id="navigation-tab">
<span class="right"><?php next_posts_link('« المواضيع السابق') ?></span>
<span class="left"><?php previous_posts_link('المواضيع اللاحقة »') ?></span>
</div>


        <?php while (have_posts()) : the_post(); ?>
        <div class="post">
                <h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
                <small><?php the_time('j F Y') ?></small>

                <div class="entry">
                    <?php the_content() ?>
                </div>

                <p class="postmetadata"><?php the_tags('الوسوم: ', ', ', '<br />'); ?> ضمن تصنيف <?php the_category(', ') ?> | <?php edit_post_link('تحرير', '', ' | '); ?>  <?php comments_popup_link('لا تعليقات »', '1 تعليق »', '% عدد التعليقات »'); ?></p>

            </div>

        <?php endwhile; ?>

<div class="clear"></div>
<div id="navigation-tab">
<span class="right"><?php next_posts_link('« المواضيع السابق') ?></span>
<span class="left"><?php previous_posts_link('المواضيع اللاحقة »') ?></span>
</div>


    <?php else : ?>

        <h2 class="center">غير موجود</h2>
        <?php include (TEMPLATEPATH . '/searchform.php'); ?>

    <?php endif; ?>

</div>


          
<!--post end-->



</div>
    <div id="left">

<?php if (function_exists('dynamic_sidebar')) dynamic_sidebar('left_menu'); ?>
    </div>
    



<?php get_footer(); ?> 

Most likely you have missing } somewhere

 

I haven't found any missing } ; nor "

 

like I said It works when I remove those lines:

 

<?php if (have_posts()) : ?>

        <?php while (have_posts()) : the_post(); ?>

 

Just beneath this:

 

<div id="content">

 

I would like to know what's wrong with those lines.. and if there's a solution without deleting them.

 

thanks :)

THe syntax you're using for if and while requires that you put endif and endwhile respectively when you close their blocks.

 

I would recommend that you do not use this syntax however, and stay with curly braces

if(condition) {
  while(condition) {
  }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.