Parse error: syntax error, unexpected ‘else’ (T_ELSE) [duplicate]

This question already has an answer here:

I am trying to display news on a page. now using acf i have set a custom field of date picker which is to display only any news added on that date on home page . But am getting an else error. This is my code

<?php
get_header()
?>
<h3><a href="<?php echo site_url().'/news'?>">News</a></h3>

<?php
global $post;
$args = array(
    'post_type' => 'news',
    'post_status' => 'publish',
    );

    $news = wp_get_recent_posts($args,false);

    foreach( $news as $row)
    {
      $newsid=$row->ID;
      $main = get_post_meta($newsid,'main_story',true);
      if($main)
        {
          $flag=1;
          $id=$newsid;
        }
     }

     if($flag==1)
     {
      $type='Ymd';
      $time=current_time($type);
      $enddate=get_post_meta($id,'enddate',true);
      if($time <= $enddate)
      {

        echo "<div class='row'>";
        $image = get_post_meta($newsid,'_thumbnail_id',true);

        echo "<div class= 'col-lg-4'><table style='width:200px;'><tr><td><img src='". wp_get_attachment_image_src($image)[0]."'style='width:100px;'></td></tr>";

        $postname=$id->post_name;
          $newstitle=get_the_title($id);
          $post_content = get_the_title($id);
          $newsbrief = $post_content->post_content;

          echo "<div class= 'col-lg-4'><table style='width:250px;'><tr><td style ='font-weight:bold'><a href = '".get_the_guid($newsid)."'>" .$newstitle. "</a></td></tr>";
      $author=get_post_meta( $newsid, 'Author',true);
      echo "<tr><td>".$author."</td>";
      $newsbrief=$row->post_content;
      echo "<tr><td>".$newsbrief."</td></tr></table></div>";
      echo "<div class='row'>";

      $args1 = array(

        'post_type' => 'news',
        'post_status' => 'publish',
        'exclude' =>$post_content->ID);

      $news1 = get_posts($args,fasle);
      foreach( $news1 as $row)
      {
        $type='Ymd';
      $time=current_time($type);
      $newsid=$row->ID;
      $newstitle=$row->post_title;
      $enddate=get_post_meta($newsid,'End Date',true);

      if($time <= $enddate)
      {
        $image = get_post_meta($newsid,'_thumbnail_id',true);

        echo "<div class= 'col-lg-4'><table style='width:200px;'><tr><td><img src='". wp_get_attachment_image_src($image)[0]."'style='width:100px;'></td></tr>";  

        $postname=$row->post_name;
        echo "<div class= 'col-lg-4'><table style='width:250px;'><tr><td style ='font-weight:bold'><a href = '".get_the_guid($newsid)."'>" .$newstitle. "</a></td></tr>";

         $author=get_post_meta( $newsid, 'Author',true);
           echo "<tr><td>".$author."</td>";
           $newsbrief=$row->post_content;
           echo "<tr><td>".$newsbrief."</td></tr></table></div>";


      }

      }

     }

      else{
          echo "<div class='row'>";
          $args = array(

        'post_type' => 'news',
        'numberposts' => '1',
        'post_status' => 'publish',
    );
          $news = wp_get_recent_posts($args,false);

          foreach( $news as $row)
           {
              $newsid=$row->ID;
              $newstitle=$row->post_title;
              $image = get_post_meta($newsid,'_thumbnail_id',true);

            echo "<div class= 'col-lg-4'><table style='width:200px;'><tr><td><img src='". wp_get_attachment_image_src($image)[0]."'style='width:100px;'></td></tr>";

            echo "<div class= 'col-lg-4'><table style='width:250px;'><tr><td style ='font-weight:bold'><a href = '".get_the_guid($newsid)."'>" .$newstitle. "</a></td></tr>";

            $author=get_post_meta( $newsid, 'Author',true);
              echo "<tr><td>".$author."</td>";
              $newsbrief=$row->post_content;
              echo "<tr><td>".$newsbrief."</td></tr></table></div>";

      }

        echo "<div class='row'>";
        $args1 = array(

            'post_type' => 'news',
            'post_status' => 'publish',
            'exclude' =>$newsid);

        $news1 = get_posts($args1,fasle);
          foreach( $news1 as $row)
      {
        $type='Ymd';
      $time=current_time($type);
      $newsid=$row->ID;
      $newstitle=$row->post_title;
      $enddate=get_post_meta($newsid,'End Date',true);

      if($time <= $enddate)
      {
        $image = get_post_meta($newsid,'_thumbnail_id',true);

        echo "<div class= 'col-lg-4'><table style='width:200px;'><tr><td><img src='". wp_get_attachment_image_src($image)[0]."'style='width:100px;'></td></tr>";  

        $postname=$row->post_name;
        echo "<div class= 'col-lg-4'><table style='width:250px;'><tr><td style ='font-weight:bold'><a href = '".get_the_guid($newsid)."'>" .$newstitle. "</a></td></tr>";

         $author=get_post_meta( $newsid, 'Author',true);
           echo "<tr><td>".$author."</td>";
           $newsbrief=$row->post_content;
           echo "<tr><td>".$newsbrief."</td></tr></table></div>";

          }
        } 
      }
    } 
    else
    {
      echo "<div class='row'>";
          $args = array(

        'post_type' => 'news',
        'numberposts' => '1',
        'post_status' => 'publish',
    );
          $news = wp_get_recent_posts($args,false);

          foreach( $news as $row)
           {
              $newsid=$row->ID;
              $newstitle=$row->post_title;
              $image = get_post_meta($newsid,'_thumbnail_id',true);

            echo "<div class= 'col-lg-4'><table style='width:200px;'><tr><td><img src='". wp_get_attachment_image_src($image)[0]."'style='width:100px;'></td></tr>";

            $postname=$row->post_name;

            echo "<div class= 'col-lg-4'><table style='width:250px;'><tr><td style ='font-weight:bold'><a href = '".get_the_guid($newsid)."'>" .$newstitle. "</a></td></tr>";

            $author=get_post_meta( $newsid, 'Author',true);
           echo "<tr><td>".$author."</td>";
           $newsbrief=$row->post_content;
           echo "<tr><td>".$newsbrief."</td></tr></table></div>";


    }

    echo "<div class='row'>";
        $args1 = array(

            'post_type' => 'news',
            'post_status' => 'publish',
            'exclude' =>$newsid);

        $news1 = get_posts($args1,fasle);
          foreach( $news1 as $row)
      {
        $type='Ymd';
      $time=current_time($type);
      $newsid=$row->ID;
      $newstitle=$row->post_title;
      $enddate=wp_post_meta($newsid,'End Date',true);

      if($time <= $enddate)
      {
        $image = get_post_meta($newsid,'_thumbnail_id',true);

        echo "<div class= 'col-lg-4'><table style='width:200px;'><tr><td><img src='". wp_get_attachment_image_src($image)[0]."'style='width:100px;'></td></tr>";  

        $postname=$row->post_name;
        echo "<div class= 'col-lg-4'><table style='width:250px;'><tr><td style ='font-weight:bold'><a href = '".get_the_guid($newsid)."'>" .$newstitle. "</a></td></tr>";

         $author=get_post_meta( $newsid, 'Author',true);
           echo "<tr><td>".$author."</td>";
           $newsbrief=$row->post_content;
           echo "<tr><td>".$newsbrief."</td></tr></table></div>";

          }
        } 
}

}

?>
<?php
get_footer();
?>

Read more here: Parse error: syntax error, unexpected ‘else’ (T_ELSE) [duplicate]

Leave a Reply

Your email address will not be published. Required fields are marked *