Tag Archives: condition

Different widget in sidebar for different post and page

Add required widget in sidebar

Create Sidebar


register_sidebar(array(
'name' => __('Contact Attorny', 'legal'),
'id' => 'contact-attorny',
'description' => __('Contact Attorny sidebar that appears on the right.', 'legal'),
'before_widget' => '<aside id="%1$s" class="sidebar-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<div class="sidebar-widget"><h3>',
'after_title' => '</h3></div>',
));

register_sidebar(array(
'name' => __('Twitter', 'legal'),
'id' => 'twitterfids',
'description' => __('Twitter that appears on the right.', 'legal'),
'before_widget' => '<aside id="%1$s" class="sidebar-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<div class="sidebar-widget"><h3>',
'after_title' => '</h3></div>',
));

register_sidebar(array(
'name' => __('Blog Category', 'legal'),
'id' => 'bcats',
'description' => __('Blog Category that appears on the right.', 'legal'),
'before_widget' => '<aside id="%1$s" class="sidebar-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<div class="sidebar-widget"><h3>',
'after_title' => '</h3></div>',
));
register_sidebar(array(
'name' => __('Practice Area', 'legal'),
'id' => 'practicearea',
'description' => __('Practice Area that appears on the right.', 'legal'),
'before_widget' => '<aside id="%1$s" class="sidebar-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<div class="sidebar-widget"><h3>',
'after_title' => '</h3></div>',
));

Sidebar.php


<?php
$legal_options = get_option('legal_theme_options');
?>
<?php if ( is_singular('practice-areas') ) { ?>
<div class="sidebar-box">
<?php if (is_active_sidebar('contact-attorny')) {
dynamic_sidebar('contact-attorny'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('twitterfids')) {
dynamic_sidebar('twitterfids'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('practicearea')) {
dynamic_sidebar('practicearea'); }?>
</div>
<?php } ?>

<?php if ( is_singular('post') ) { ?>
<div class="sidebar-box">
<?php if (is_active_sidebar('contact-attorny')) {
dynamic_sidebar('contact-attorny'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('twitterfids')) {
dynamic_sidebar('twitterfids'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('bcats')) {
dynamic_sidebar('bcats'); }?>
</div>
<?php } ?>

<?php if(is_home()) { ?>
<div class="sidebar-box">
<?php if (is_active_sidebar('contact-attorny')) {
dynamic_sidebar('contact-attorny'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('twitterfids')) {
dynamic_sidebar('twitterfids'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('bcats')) {
dynamic_sidebar('bcats'); }?>
</div>
<?php } ?>

<?php if (is_page_template('page-template/testimonials.php')) { ?>
<div class="sidebar-box">
<?php if (is_active_sidebar('contact-attorny')) {
dynamic_sidebar('contact-attorny'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('twitterfids')) {
dynamic_sidebar('twitterfids'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('practicearea')) {
dynamic_sidebar('practicearea'); }?>
</div>
<?php } ?>

<?php if (is_page_template('page-template/case-results.php')) { ?>
<div class="sidebar-box">
<?php if (is_active_sidebar('practicearea')) {
dynamic_sidebar('practicearea'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('twitterfids')) {
dynamic_sidebar('twitterfids'); }?>
</div>
<?php } ?>

<?php if (is_page(204)) { ?>
<div class="sidebar-box">
<?php if (is_active_sidebar('contact-attorny')) {
dynamic_sidebar('contact-attorny'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('twitterfids')) {
dynamic_sidebar('twitterfids'); }?>
</div>
<?php } ?>

<?php if (is_page(269)) { ?>
<div class="sidebar-box">
<?php if (is_active_sidebar('contact-attorny')) {
dynamic_sidebar('contact-attorny'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('twitterfids')) {
dynamic_sidebar('twitterfids'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('bcats')) {
dynamic_sidebar('bcats'); }?>
</div>
<?php } ?>

<?php if (is_page(206)) { ?>
<div class="sidebar-box">
<?php if (is_active_sidebar('contact-attorny')) {
dynamic_sidebar('contact-attorny'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('twitterfids')) {
dynamic_sidebar('twitterfids'); }?>
</div>
<div class="sidebar-box">
<div class="address_info">
<h4> <?php echo esc_attr($legal_options['contacttitles']); ?> </h4>
<div class="textwidget">
<ul>
<li>
<?php echo esc_attr($legal_options['contactaddresses']); ?><br>
Phone: <?php  echo esc_url($legal_options['pnumbers']); ?><br>
Fax: <?php  echo esc_attr($legal_options['faxnumbs']); ?><br>
E-mail: <a href="mailto:<?php echo sanitize_email($legal_options['cemails']); ?>"><?php echo sanitize_email($legal_options['cemails']); ?></a><br>
Website: <a href="<?php echo esc_url($legal_options['cweb']); ?>"><?php echo esc_url($legal_options['cweb']); ?></a> </li>
</ul>
</div>
</div>
</div>

<?php } ?>

Advertisements

Condition with Ternary Operator

$var = 5;

echo $var_is_greater_than_two = ($var > 5 ? ‘ok’ : ‘notok’);

Condition for only home page

if(is_home() || is_front_page())
{
code here
}

Condition for count to display

<?php
$count = 0;
$my_query = new WP_Query(‘post_type=Event&posts_per_page=-1’);
while ($my_query->have_posts()) : $my_query->the_post();
$count++;
endwhile;
wp_reset_query();
//echo $count;
if($count <= 5){?>
<div class=”info-text”>
<?php if(!empty($seltop_options[‘welcometext’])) {?>
<h1><?php echo $seltop_options[‘welcometext’]; ?></h1>
<?php } ?>
</div>
<?php } ?>

Condition for value exist in variable

<?php if ($digital_options[‘social-fb’]!=””) {?>
<a href=”<?php echo $digital_options[‘social-fb’]; ?>” class=”fb_socialIcon”></a>
<?php } ?>

Condation for post without image

if ( has_post_thumbnail() )
{
the_post_thumbnail();
}
else
{
?><img width=”184″ height=”115″ alt=”No Image” class=”attachment-post-thumbnail wp-post-image” src=”<?php   echo get_template_directory_uri();?>/images/noimage.png”><?php
}
?>

%d bloggers like this: