Support » Fixing WordPress » php help – syntax errors?

  • Resolved jboepple

    (@jboepple)


    Hi! I don’t know if this is ok to ask on the forum, but my programmer is out of town and this designer needs a little help.

    I have an ecommerce store, and one of the post IDs needs to operate different than the rest. Here’s the code for that specific product:

    <?php if ( $postID == "2352" ) { ?>
          <div class="row closing-cta">
            <div class="col-md-9">
              Alphabet Energy <?php echo roots_title(); ?>
          		<p class="purchase_price">$<?=$purchase_price?></p>
            </div>
            <div class="col-md-3">
              <a href="/product/powermodule-developer-kit/?add-to-cart=2352" rel="nofollow" data-product_id="2352" data-product_sku="" data-quantity="1" class="btn btn-blue btn-lg">Buy Now</a>
            </div>
          </div>

    Now I need to do the same to a second product. The links will change, so I know I can’t just change it to this:

    <?php if (in_array($postID, array(“2352”, “xxx”)) ?>

    So I duplicated the whole string of code and changed the product number and links to this:

    <?php if ( $postID == "2352" ) { ?>
          <div class="row closing-cta">
            <div class="col-md-9">
              Alphabet Energy <?php echo roots_title(); ?>
          		<p class="purchase_price">$<?=$purchase_price?></p>
            </div>
            <div class="col-md-3">
              <a href="/product/powermodule-developer-kit/?add-to-cart=2352" rel="nofollow" data-product_id="2352" data-product_sku="" data-quantity="1" class="btn btn-blue btn-lg">Buy Now</a>
            </div>
          </div>
                <?php if ( $postID == "2397" ) { ?>
          <div class="row closing-cta">
            <div class="col-md-9">
              Alphabet Energy <?php echo roots_title(); ?>
          		<p class="purchase_price">$<?=$purchase_price?></p>
            </div>
            <div class="col-md-3">
              <a href="/product/powermodule-dev-kit/?add-to-cart=2397" rel="nofollow" data-product_id="2397" data-product_sku="" data-quantity="1" class="btn btn-blue btn-lg">Buy Now</a>
            </div>
          </div>

    but then I got a syntax error at the bottom of my php file:

    </div><!-- /.main -->
    <?php endwhile; ?>

    Is there something else I need to add since I added the second product’s code at the top? I just don’t know what to do! Thanks in advance. (I’d give a link to the site but it is all password protected so I can’t!)

    Here’s the whole page in case it makes a difference:

    <?php while (have_posts()) : the_post(); ?>
    <?php
    	$postID = get_the_ID();
    	$postmeta = get_post_meta($postID);
    	$subtitle = (isset($postmeta['subtitle']))?$postmeta['subtitle'][0]:'';
    	$features = (isset($postmeta['features']))?$postmeta['features'][0]:'';
    	$youtube = (isset($postmeta['youtube']))?$postmeta['youtube'][0]:'';
      $quote = (isset($postmeta['quote']))?$postmeta['quote'][0]:'';
      $product_intro = (isset($postmeta['product_intro']))?$postmeta['product_intro'][0]:'';
      $buy_subtitle = (isset($postmeta['buy_subtitle']))?$postmeta['buy_subtitle'][0]:'';
      $buy_product_intro = (isset($postmeta['buy_product_intro']))?$postmeta['buy_product_intro'][0]:'';
      $purchase_price = (isset($postmeta['purchase_price']))?$postmeta['purchase_price'][0]:'';
    ?>
    <? /* <div class="main col-sm-8 col-sm-offset-1" role="main"> */?>
    <div class="main col-sm-12" role="main">
    	<article <?php post_class(); ?>>
    
    		<?php if($buy_subtitle) { ?>
    		<h2 class="subtitle"><?=$buy_subtitle?></h2>
    		<?php } ?>
    
    		<?php if($buy_product_intro) { ?>
        <div class="product-intro">
          <p><? echo $buy_product_intro?></p>
        </div>
        <?php } ?>
    
    		<?php if($youtube) { ?>
    		<div class="video-container">
    			<iframe width="100%" src="//www.youtube.com/embed/<?=$youtube?>?rel=0" frameborder="0" allowfullscreen></iframe>
    		</div>
    		<?php } ?>
    
          <?php if ( $postID == "2352" ) { ?>
          <div class="row closing-cta">
            <div class="col-md-9">
              Alphabet Energy <?php echo roots_title(); ?>
          		<p class="purchase_price">$<?=$purchase_price?></p>
            </div>
            <div class="col-md-3">
              <a href="/product/powermodule-developer-kit/?add-to-cart=2352" rel="nofollow" data-product_id="2352" data-product_sku="" data-quantity="1" class="btn btn-blue btn-lg">Buy Now</a>
            </div>
          </div>
                <?php if ( $postID == "2397" ) { ?>
          <div class="row closing-cta">
            <div class="col-md-9">
              Alphabet Energy <?php echo roots_title(); ?>
          		<p class="purchase_price">$<?=$purchase_price?></p>
            </div>
            <div class="col-md-3">
              <a href="/product/powermodule-dev-kit/?add-to-cart=2397" rel="nofollow" data-product_id="2397" data-product_sku="" data-quantity="1" class="btn btn-blue btn-lg">Buy Now</a>
            </div>
          </div>
           <?php } else { ?>
           <div class="row">
    
          		<?php if($subtitle) { ?>
          		<h2 class="subtitle"><?=$subtitle?></h2>
          		<?php } ?>
    
          		<?php if($product_intro) { ?>
          		<div class="product-intro">
                <p><? echo $product_intro?></p>
    
                <?php if ( $postID == "2103" ) {
                	echo '<p><a href="http://www.alphabetenergy.com/products/powermodule-pre-order-form/" class="btn btn-blue btn-lg" data-title="PRE-ORDER NOW" role="button">Pre-order Now</a></p>';
                 } else {
                  echo '<p><a href="#" class="btn btn-blue btn-lg request-info-link" data-title="REQUEST A BROCHURE" data-item="Request a Brochure: <? the_title(); ?>" role="button">Request Brochure</a></p>';
                   } ?>
    
              </div>
            </div>
        		<?php } ?>
    
          <?php } ?>
    
        <?php the_content(); ?>
    
        <div class="row closing-cta">
          <div class="col-md-9">
            Alphabet Energy <?php echo roots_title(); ?>
        		<?php if($purchase_price) { ?>
        		<p class="purchase_price">$<?=$purchase_price?></p>
        		<?php } ?>
          </div>
          <div class="col-md-3">
            <?php if ( $postID == "2103" ) {
            	echo '<a href="http://www.alphabetenergy.com/products/powermodule-pre-order-form/" class="btn btn-blue btn-lg" data-title="PRE-ORDER NOW" role="button">Pre-order Now</a>';
             } elseif( $postID == "2352") {
              echo '<a href="/product/powermodule-developer-kit/?add-to-cart=2352" rel="nofollow" data-product_id="2352" data-product_sku="" data-quantity="1" class="btn btn-blue btn-lg">Buy Now</a>';
             } else {
              echo '<a href="#" class="btn btn-blue btn-lg request-info-link" data-title="REQUEST A BROCHURE" data-item="Request a Brochure: <? the_title(); ?>" role="button">Request Brochure</a>';
            } ?>
    
          </div>
        </div>
    
    	</article>
    </div><!-- /.main -->
    <?php endwhile; ?>
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘php help – syntax errors?’ is closed to new replies.