Advanced Custom Fields else if - php

I am trying to display store hours for 3 different locations with Advanced Custom Fields in WordPress. When I take out the entire middle section with the else if statement, it works correctly for the other 2 locations. As soon as I add in the section with the else if statement, the store hours go blank for all pages. Any help would be greatly appreciated. Here is what I have so far:
First section
<?php if (is_single( 3823 ) ){ ?>
<section class="hours">
<h3>Outlet Hours:</h3>
<section class="hours-section">
<?php if(get_field('store_hours')): ?>
<?php while(has_sub_field('store_hours')): ?>
<p class="days"><b><?php the_sub_field('store_hours_day'); ?>: </b></p>
<?php if (get_sub_field( 'store_hours_closed') == "open") { ?>
<p class="hours-hours">
<?php the_sub_field('store_hours_morning_time'); ?> am
-
<?php the_sub_field('store_hours_evening_time'); ?> pm
</p>
<?php } ?>
<?php if (get_sub_field( 'store_hours_closed') == "closed") { ?>
<b>Closed</b>
<?php } ?>
<br/>
<?php endwhile; ?>
<?php endif; ?>
</section>
</section><!-- .sidebar -->
Second Section
<?php else if (is_single( 2284) ){ ?>
<section class="hours">
<h3>Builder Hours:</h3>
<section class="hours-section">
<?php if(get_field('store_hours')): ?>
<?php while(has_sub_field('store_hours')): ?>
<p class="days"><b><?php the_sub_field('store_hours_day'); ?>: </b></p>
<?php if (get_sub_field( 'store_hours_closed') == "open") { ?>
<p class="hours-hours">
<?php the_sub_field('store_hours_morning_time'); ?> am
-
<?php the_sub_field('store_hours_evening_time'); ?> pm
</p>
<?php } ?>
<?php if (get_sub_field( 'store_hours_closed') == "closed") { ?>
<b>Closed</b>
<?php } ?>
<br/>
<?php endwhile; ?>
<?php endif; ?>
</section>
</section><!-- .sidebar -->
Third Section
<?php }
else { ?>
<?php $other_page = 47; ?>
<section class="hours">
<h3>Retail Hours:</h3>
<section class="hours-section">
<?php if(get_field('store_hours', $other_page)): ?>
<?php while(has_sub_field('store_hours', $other_page)): ?>
<p class="days"><b><?php the_sub_field('store_hours_day', $other_page); ?>: </b></p>
<?php if (get_sub_field( 'store_hours_closed', $other_page) == "open") { ?>
<p class="hours-hours">
<?php the_sub_field('store_hours_morning_time', $other_page); ?> am
-
<?php the_sub_field('store_hours_evening_time', $other_page); ?> pm
</p>
<?php } ?>
<?php if (get_sub_field( 'store_hours_closed', $other_page) == "closed") { ?>
Closed
<?php } ?>
<br/>
<?php endwhile; ?>
<?php endif; ?>
</section>
</section><!-- .sidebar -->

It looks like you forgot a curly bracket or two in your code. I went ahead and changed your if/else statements to use the alternative syntax, which you used in some places in the code block, but not consistently throughout.
<?php if (is_single( 3823 ) ) : ?>
<section class="hours">
<h3>Outlet Hours:</h3>
<section class="hours-section">
<?php if(get_field('store_hours')): ?>
<?php while(has_sub_field('store_hours')): ?>
<p class="days"><b><?php the_sub_field('store_hours_day'); ?>: </b></p>
<?php if (get_sub_field( 'store_hours_closed') == "open") : ?>
<p class="hours-hours">
<?php the_sub_field('store_hours_morning_time'); ?> am
-
<?php the_sub_field('store_hours_evening_time'); ?> pm
</p>
<?php endif; ?>
<?php if (get_sub_field( 'store_hours_closed') == "closed") : ?>
<b>Closed</b>
<?php endif; ?>
<br/>
<?php endwhile; ?>
<?php endif; ?>
</section>
</section><!-- .sidebar -->
<?php elseif (is_single( 2284) ) : ?>
<section class="hours">
<h3>Builder Hours:</h3>
<section class="hours-section">
<?php if(get_field('store_hours')): ?>
<?php while(has_sub_field('store_hours')): ?>
<p class="days"><b><?php the_sub_field('store_hours_day'); ?>: </b></p>
<?php if (get_sub_field( 'store_hours_closed') == "open") : ?>
<p class="hours-hours">
<?php the_sub_field('store_hours_morning_time'); ?> am
-
<?php the_sub_field('store_hours_evening_time'); ?> pm
</p>
<?php endif; ?>
<?php if (get_sub_field( 'store_hours_closed') == "closed") : ?>
<b>Closed</b>
<?php endif; ?>
<br/>
<?php endwhile; ?>
<?php endif; ?>
</section>
</section><!-- .sidebar -->
<?php else : ?>
<?php $other_page = 47; ?>
<section class="hours">
<h3>Retail Hours:</h3>
<section class="hours-section">
<?php if(get_field('store_hours', $other_page)): ?>
<?php while(has_sub_field('store_hours', $other_page)): ?>
<p class="days"><b><?php the_sub_field('store_hours_day', $other_page); ?>: </b></p>
<?php if (get_sub_field( 'store_hours_closed', $other_page) == "open") : ?>
<p class="hours-hours">
<?php the_sub_field('store_hours_morning_time', $other_page); ?> am
-
<?php the_sub_field('store_hours_evening_time', $other_page); ?> pm
</p>
<?php endif; ?>
<?php if (get_sub_field( 'store_hours_closed', $other_page) == "closed") : ?>
Closed
<?php endif; ?>
<br/>
<?php endwhile; ?>
<?php endif; ?>
</section>
</section><!-- .sidebar -->
<?php endif; ?>

You should mention type like option, page ,theme
Example:
$other_page ='2';//pageid
<?php if(get_field('store_hours', $other_page)): ?>

Related

splitting the paragraph into 2 sections in wordpress

I'm building a property section in WordPress that leaves me with a long and excruciating list of information when the code draws the data. This list should be divided into 2 sections to save more space on the page when on desktops, etc.
<a name="rooms"></a>
<h3><?php echo __("Property Details", "wppf"); ?></h3>
<?php foreach ($paragraphs as $paragraph) : ?>
<div class="clearfix">
<?php if ($paragraph['name'] != '') : ?>
<h4><?php echo $paragraph['name'] ?></h4>
<?php endif; ?>
<?php if ($paragraph['filesortorder'] != '') : ?>
<?php echo ($paragraph['filesortorder']); ?>
<?php endif; ?>
<p>
<?php if ($paragraph['dimensions'] != "") : ?>
<em><?php echo $paragraph['dimensions'] ?></em>
<br />
<?php endif; ?>
<?php echo $paragraph['description'] ?>
</p>
</div>
<?php endforeach; ?>
<?php foreach ($links as $link) : ?>
<div class="clearfix">
<a href="<?php echo $link['url']; ?>" target="_blank">
<?php echo (empty($link['name'])) ? $link['url'] : $link['name']; ?>
</a>
</div>
<?php endforeach; ?>
There is a maximum of 10 sections that it fills in and I want to split that into 2 groups of 5.
Something like...
if(count($paragraphs) > 5) {
$paragraphs2 = array_splice($paragraphs, 5);
}
Would let you split the paragraphs > 5 into another array.
You'd then just need to output those in your code as you see fit - something like:
<?php foreach ($paragraphs2 as $paragraph2) :?>
<div class="clearfix">
<?php if ($paragraph2['name']!=''):?>
<h4>
<?php echo $paragraph2['name'] ?>
</h4>
<?php endif; ?>
<?php if ($paragraph2['filesortorder']!=''):?>
<?php echo ($paragraph2['filesortorder']); ?>
<?php endif; ?>
<p>
<?php if ($paragraph2['dimensions']!=""):?>
<em>
<?php echo $paragraph2['dimensions'] ?>
</em>
<br />
<?php endif;?>
<?php echo $paragraph2['description'] ?>
</p>
</div>
<?php endforeach;?>
Should get you started to loop through and repeat the relevant display code.

Screaming frog sees a link to a page which is not there but shows

This is the selector script I believe below so what should happen is as you select a product then you select if its your an individual or couple or family then you click show me and it takes you to the correct link
<div class="finder__selector">
<?php /* Set first option as the default option */ ?>
<?php $count = 1; while ( have_rows('links') ) : the_row(); ?>
<?php $link_url = get_sub_field('link_url'); ?>
<?php if($product_name): ?>
<?php //echo $product_name; ?>
<?php //echo $link_url; ?>
<?php if(strpos($link_url, $product_name) !== false): ?>
<?php the_sub_field('link_title'); ?><i class="down-arrow"></i>
<?php endif; ?>
<?php else: ?>
<?php if($count == 1) : ?>
<?php the_sub_field('link_title'); ?><i class="down-arrow"></i>
<?php endif; ?>
<?php endif; ?>
<?php $count++; ?>
<?php endwhile; ?>
<div class="finder__options">
<?php $count = 1; ?>
<?php while ( have_rows('links') ) : the_row(); ?>
<?php $link_url_select = get_sub_field('link_url'); ?>
<?php $link_title_select = get_sub_field('link_title'); ?>
<?php if($product_name): ?>
<?php if(strpos($link_url_select, $product_name) !== false): ?>
<?php echo $link_title_select; ?><i class="down-arrow"></i>
<?php else: ?>
<?php echo $link_title_select; ?><i class="down-arrow"></i>
<?php endif; ?>
<?php else: ?>
<?php echo $link_title_select; ?><i class="down-arrow"></i>
<?php endif; ?>
<?php $count++; ?>
<?php endwhile; ?>
</div>
So the above works but whats its actually showing on view source and what creaming frog is 404 is
href="&audience=couples" class=finder__option>
my partner and I <i
class=down-arrow></i>
</a>
<a
href="&audience=families" class=finder__option>
my family <i
class=down-arrow></i>

Using getChildHtml to display product attributes not working

I have added a to my catalog.xml file, created a specifications.phtml file to be used as the template, and I’m calling echo $this->getChildHtml(’specifications’); in my view.phtml file.
However it’s not displaying anything at all. I’ve basically mirrored everything after the same type of thing for the product description (which works) but I’m not having any luck.
The content that I’m trying to pull in is under the product page and I think a custom section that is labeled “Specifications Tab”. Not sure if the space in the field name is causing issues or what.
Here is what I have in my view.phtml file:
<div id="product-tabs" class="tabs">
<ul class="tabs-nav">
<li><?php echo $this->__('Description'); ?></li>
<?php
$specificationsTabContent = $_product->getSpecificationsTab();
$videoTabContent = $_product->getVideoTab();
$faqTabContent = $_product->getFaqTab();
$howitworksTabContent = $_product->getHowitworksTab();
$awardsTabContent = $_product->getAwardsTab();
?>
<?php #if ($this->getChildHtml('specifications_tab')): #($this->getChildHtml('product_attributes')): ?>
<?php if (!empty($specificationsTabContent)) : ?>
<li><?php echo $this->__('Specs'); ?></li>
<?php endif; ?>
<?php if (!empty($videoTabContent)) : ?>
<li><?php echo $this->__('Videos14'); ?></li>
<?php endif; ?>
<?php if (!empty($faqTabContent)) : ?>
<li><?php echo $this->__('FAQs'); ?></li>
<?php endif; ?>
<?php if (!empty($howitworksTabContent)) : ?>
<li><?php echo $this->__('How It Works'); ?></li>
<?php endif; ?>
<?php if (!empty($awardsTabContent)) : ?>
<li><?php echo $this->__('Awards'); ?></li>
<?php endif; ?>
<!-- <li><?php #echo $this->__('Tags'); ?></li> -->
<?php if ($this->getChildHtml('snippet_product_view_tab_1')): ?>
<li><?php echo $this->__('Custom 1'); ?></li>
<?php endif; ?>
<?php if ($this->getChildHtml('snippet_product_view_tab_2')): ?>
<li><?php echo $this->__('Custom 2'); ?></li>
<?php endif; ?>
</ul>
<div class="tabs-content">
<div id="tab-description">
<?php echo $this->getChildHtml('description'); ?>
</div>
<div id="tab-details">
<?php #echo $this->getChildHtml('specifications'); ?>
<?php echo $specificationsTabContent; ?>
</div>
<div id="tab-faq">
<?php echo $faqTabContent; ?>
</div>
<div id="tab-video">
<?php echo $videoTabContent; ?>
</div>
<div id="tab-howitworks">
<?php echo $howitworksTabContent; ?>
</div>
<div id="tab-awards">
<?php echo $awardsTabContent; ?>
</div>
<!-- <div id="tab-tags">
<?php echo $this->getChildHtml('product_additional_data') ?>
</div> -->
<?php if ( $this->getChildHtml('snippet_product_view_tab_1') ): ?>
<div id="tab-custom-1">
<div class="snippet snippet-product-view-tab-1"><?php echo $this->getChildHtml('snippet_product_view_tab_1') ?></div>
</div>
<?php endif; ?>
<?php if ( $this->getChildHtml('snippet_product_view_tab_2') ): ?>
<div id="tab-custom-2">
<div class="snippet snippet-product-view-tab-2"><?php echo $this->getChildHtml('snippet_product_view_tab_2') ?></div>
</div>
<?php endif; ?>
</div>
</div>
This is the XML I added to my catalog.xml:
<!-- specifications -->
<block type="catalog/product_view_specifications" name="product.specifications.tab" as="specifications" template="catalog/product/view/specifications.phtml"/>
And this is the template file specifications.phtml:
<?php $_specifications = $this->getProduct()->getSpecificationsTab(); ?>
<?php if ($_specifications): ?>
<h2><?php echo $this->__('Specifications') ?></h2>
<div class="long-description std">
<?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_specifications, 'specifications') ?>
</div>
<?php endif; ?>
Any help would be greatly appreciated! I’m not overly familiar with Magento or PHP.
Thanks,
JUst change
<?php #echo $this->getChildHtml('specifications'); ?>
to
<?php echo $this->getChildHtml('specifications'); ?>

Wordpress Parse error: syntax error, unexpected T_STRING

I am getting the following error message when I try to access one of the links on the blog on my Wordpress site:
Parse error: syntax error, unexpected T_STRING in /home/insuranc/public_html/wp-content/themes/inovado/single.php on line 118
<?php get_header(); ?>
<!-- Title Bar -->
<?php if ( $data['select_blogtitlebar'] == 'Image' ) { ?>
<div id="alt-title" class="post-thumbnail" style="background-image: url( <?php echo $data['media_blogtitlebar']; ?> );">
<div class="grid"></div>
<div class="container">
<h1><?php echo $data['text_blogtitle']; ?><?php if($data['text_titledivider'] != "") { echo $data['text_titledivider']; } ?></h1>
<?php if($data['text_blogsubtitle']){ echo '<h2>'.$data['text_blogsubtitle'].'</h2>'; } ?>
</div>
</div>
<?php if($data['check_blogbreadcrumbs'] == 0){ ?>
<div id="alt-breadcrumbs">
<div class="container">
<?php minti_breadcrumbs(); ?>
</div>
</div>
<?php } ?>
<?php if($data['check_stripedborder']) { ?><div class="hr-border"></div><?php } ?>
<?php } elseif ($data['select_blogtitlebar'] == 'No Titlebar') { ?>
<?php if($data['check_blogbreadcrumbs'] == 0){ ?>
<div id="no-title">
<div class="container">
<div id="breadcrumbs" class="sixteen columns <?php if(get_post_meta( get_option('page_for_posts'), 'minti_subtitle', true )){ echo 'breadrcumbpadding'; } /* to align middle */ ?>">
<?php minti_breadcrumbs(); ?>
</div>
</div>
</div>
<?php if($data['check_stripedborder']) { ?><div class="hr-border"></div><?php } ?>
<?php } else { ?>
<div id="no-title-divider"></div>
<?php if($data['check_stripedborder']) { ?><div class="hr-border"></div><?php } ?>
<?php } ?>
<?php } else { ?>
<div id="title">
<div class="container">
<div class="ten columns">
<h1><?php echo $data['text_blogtitle']; ?><?php if($data['text_titledivider'] != "") { echo $data['text_titledivider']; } ?></h1>
<?php if($data['text_blogsubtitle']){ echo '<h2>'.$data['text_blogsubtitle'].'</h2>'; } ?>
</div>
<?php if($data['check_blogbreadcrumbs'] == 0){ ?>
<div id="breadcrumbs" class="six columns <?php if($data['text_blogsubtitle']){ echo 'breadrcumbpadding'; } /* to align middle */ ?>">
<?php minti_breadcrumbs(); ?>
</div>
<?php } ?>
</div>
</div>
<?php if($data['check_stripedborder']) { ?><div class="hr-border"></div><?php } ?>
<?php } ?>
<!-- End: Title Bar -->
<div id="page-wrap" class="container">
<div id="content" class="<?php echo $data['select_blogsidebar']; ?> twelve columns single">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part( 'framework/inc/post-format/single', get_post_format() ); ?>
<?php if($data['check_sharebox'] == true) { ?>
<?php get_template_part( 'framework/inc/sharebox' ); ?>
<?php } ?>
<?php if($data['check_authorinfo'] == true) { ?>
<div id="author-info" class="clearfix">
<div class="author-image">
<?php echo get_avatar( get_the_author_meta('user_email'), '35', '' ); ?>
</div>
<div class="author-bio">
<h4><?php _e('About the Author', 'minti'); ?></h4>
<?php the_author_meta('description'); ?>
</div>
</div>
<?php } ?>
<?php if($data['check_relatedposts'] == true) { ?>
<div id="related-posts">
<?php
//for use in the loop, list 5 post titles related to first tag on current post
$tags = wp_get_post_tags($post->ID);
if ($tags) {
?>
<h3 class="title"><span><?php _e('Related Posts', 'minti'); ?></span></h3>
<ul>
<?php $first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
'showposts'=>3
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><?php the_title(); ?> <span>(<?php the_time(get_option('date_format')); ?>)</span></li>
<?php
endwhile;
wp_reset_query();
}
}
?>
</ul>
</div>
<?php } ?>
<div class="comments"><? php comments_template(); ?></div>
<div class="post-navigation">
<div class="alignleft prev"><?php previous_post_link('%link', 'Prev Post', FALSE); ?></div>
<div class="alignright next"><?php next_post_link('%link', 'Next Post', FALSE); ?> </div>
</div>
<?php endwhile; endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
There is a space between the <? and the php .. Remove it on Line 118
<? php comments_template(); ?></div>.
^----- Remove this.

Change Layout of Joomla article list with custom php

Having spent a few days banging my head against a brick wall with this I need some help. I basically want to change the code here:
<div class="itemList">
<?php if(isset($this->leading) && count($this->leading)): ?>
<!-- Leading items -->
<div id="itemListLeading">
<?php foreach($this->leading as $key=>$item): ?>
<?php
// Define a CSS class for the last container on each row
if( (($key+1)%($this->params->get('num_leading_columns'))==0) || count($this->leading)<$this->params->get('num_leading_columns') )
$lastContainer= ' itemContainerLast';
else
$lastContainer='';
?>
<div class="itemContainer<?php echo $lastContainer; ?>"<?php echo (count($this->leading)==1) ? '' : ' style="width:'.number_format(100/$this->params->get('num_leading_columns'), 1).'%;"'; ?>>
<?php
// Load category_item.php by default
$this->item=$item;
echo $this->loadTemplate('item');
?>
</div>
<?php if(($key+1)%($this->params->get('num_leading_columns'))==0): ?>
<div class="clr"></div>
<?php endif; ?>
<?php endforeach; ?>
<div class="clr"></div>
</div>
<?php endif; ?>
<?php if(isset($this->primary) && count($this->primary)): ?>
<!-- Primary items -->
<div id="itemListPrimary">
<?php foreach($this->primary as $key=>$item): ?>
<?php
// Define a CSS class for the last container on each row
if( (($key+1)%($this->params->get('num_primary_columns'))==0) || count($this->primary)<$this->params->get('num_primary_columns') )
$lastContainer= ' itemContainerLast';
else
$lastContainer='';
?>
<div class="itemContainer<?php echo $lastContainer; ?>"<?php echo (count($this->primary)==1) ? '' : ' style="width:'.number_format(100/$this->params->get('num_primary_columns'), 1).'%;"'; ?>>
<?php
// Load category_item.php by default
$this->item=$item;
echo $this->loadTemplate('item');
?>
</div>
<?php if(($key+1)%($this->params->get('num_primary_columns'))==0): ?>
<div class="clr"></div>
<?php endif; ?>
<?php endforeach; ?>
<div class="clr"></div>
</div>
<?php endif; ?>
<?php if(isset($this->secondary) && count($this->secondary)): ?>
<!-- Secondary items -->
<div id="itemListSecondary">
<?php foreach($this->secondary as $key=>$item): ?>
<?php
// Define a CSS class for the last container on each row
if( (($key+1)%($this->params->get('num_secondary_columns'))==0) || count($this->secondary)<$this->params->get('num_secondary_columns') )
$lastContainer= ' itemContainerLast';
else
$lastContainer='';
?>
<div class="itemContainer<?php echo $lastContainer; ?>"<?php echo (count($this->secondary)==1) ? '' : ' style="width:'.number_format(100/$this->params->get('num_secondary_columns'), 1).'%;"'; ?>>
<?php
// Load category_item.php by default
$this->item=$item;
echo $this->loadTemplate('item');
?>
</div>
<?php if(($key+1)%($this->params->get('num_secondary_columns'))==0): ?>
<div class="clr"></div>
<?php endif; ?>
<?php endforeach; ?>
<div class="clr"></div>
</div>
<?php endif; ?>
<?php if(isset($this->links) && count($this->links)): ?>
<!-- Link items -->
<div id="itemListLinks">
<h4><?php echo JText::_('K2_MORE'); ?></h4>
<?php foreach($this->links as $key=>$item): ?>
<?php
// Define a CSS class for the last container on each row
if( (($key+1)%($this->params->get('num_links_columns'))==0) || count($this->links)<$this->params->get('num_links_columns') )
$lastContainer= ' itemContainerLast';
else
$lastContainer='';
?>
<div class="itemContainer<?php echo $lastContainer; ?>"<?php echo (count($this->links)==1) ? '' : ' style="width:'.number_format(100/$this->params->get('num_links_columns'), 1).'%;"'; ?>>
<?php
// Load category_item_links.php by default
$this->item=$item;
echo $this->loadTemplate('item_links');
?>
</div>
<?php if(($key+1)%($this->params->get('num_links_columns'))==0): ?>
<div class="clr"></div>
<?php endif; ?>
<?php endforeach; ?>
<div class="clr"></div>
</div>
<?php endif; ?>
</div>
So that 'leading' displays a certain number of articles, then 'primary' displays the next two, 'secondary' the next four and so on.
Any help on how to do that would be great
The file is located here:
/layouts/joomla/content/category_default.php
To override it place a copy here:
[YOUR_TEMPLATE]/html/layouts/joomla/content/
You can read more about Joomla layouts here:
Sharing layouts across views or extensions with JLayout

Categories