How to hide a div is function doesn't exist? - php

I am adding a custom layout for Genesis that will place the blubrry player. I got it correctly but my problem is the wrapping div. It is visible if no Podcast is added.
This is the code for the player:
<?php if function_exists('the_powerpress_content') the_powerpress_content(); ?>
Here is my complete code:
add_action('genesis_entry_header', 'the_powerpress_player');
function the_powerpress_player(){
if( is_single() || in_category('5') ){
?>
<div class="podcast-div"><?php if function_exists('the_powerpress_content') the_powerpress_content(); ?></div>
<?php
}
else {
echo "<div class="no-podcast">";
echo "<div>";
}
}
Is there other way where the div wrapper will show only if if the podcast attachment is added? I tried the above code but I got critical error. With no 'else' clause the div is rendered but I wanted it invisible if no podcast in the post.
TIA

Replace
echo "<div class="no-podcast">";
With
echo "<div class='no-podcast'>";
-----------^----------^---

<?php function the_powerpress_player(){
if( is_single() || in_category('5') ){ ?>
<div class="podcast-div">
<?php if function_exists('the_powerpress_content') the_powerpress_content();?>
</div>
<?php } else { ?>
<div class="no-podcast" style="display:none;">
</div>
<?php }?>

Related

Php echo printing html tags as it is in wordpress

I'm displaying description on a page which has html tags in it but it is printing html tags as it is. I want html tags to work. As you can see in screenshot http://prntscr.com/9tqply .
My code is below. This project is in wordpress and I've made custom templete to display record.
<div>
<?php foreach ($result as $row) { ?>
<?php if (isset($_GET['id']) && $row->id == $_GET['id']) { ?>
<h1><?php echo $row->name; ?></h1>
<?php echo $row->description; ?>
<?php } ?>
<?php } ?>
</div>

template content won't show in opencart

I'm having an issue with open cart(v2.0.3.1) and the journal template (v2.4.9).
The issue: when I add a journal module like the Carousel, Banners etc. and try to place the module in the content section (either column_right, column_left or content_top, content_bottom) it won't show up on the site (not only home but all other pages aswell) However if I cange the position to "top" or "bottom" it does show up!
I've checked the file catalog/view/theme/journal2/template/common/home.tpl
to check if the columns are printed and saw this:
<div id="container" class="container j-container"><div class="row"><?php echo $column_left; ?> <?php echo $column_right; ?>
<?php if ($column_left && $column_right) { ?>
<?php $class = 'col-sm-6'; ?>
<?php } elseif ($column_left || $column_right) { ?>
<?php $class = 'col-sm-9'; ?>
<?php } else { ?>
<?php $class = 'col-sm-12'; ?>
<?php } ?>
<div id="content" class="<?php echo $class; ?>"><?php echo $content_top; ?><?php echo $content_bottom; ?></div>
</div>
So they seem to be echoed however they don't show up on the website.
Actualy they do show up but only with the opencart elements not the custom elements made by the template.
I could use some help because i've been searching for 2 whole days and I can't seem to find a propper solution.
Need to figure this out for a client.
The problem was in the template after I updated it to a newer version the issue resolved!

If statement to not show div / h2

This for each / if statement displays changes, and then right below it it displays the changes made.
I am trying to write an if statement that tells it not to show the h2 and the #change_box if there are no changes.
Help would be greatly appreciated.
<h2 class="changes"> Changes: </h2>
<div id="change_box">
<? foreach ($audit['Events'] as $event):?>
<?if ( $event['Type'] != 'Comment'):?>
<span class="field">
<?= $event['Field']?>
</span>:
<?= $event['Value'] ?>
<?=($event['Previous'])?>
<?endif?>
<?endforeach?>
</div>
<?php
if ($changes) { // You'll have to set this variable
//Echo all of your HTML
else {
//Echo the stuff you'd rather show if they didn't change anything
}
?>
To give you an idea of how I'd write your code
<?php
if ($changes) {
echo '<h2 class="changes">Changes:</h2>';
echo '<div id="change_box">';
foreach ($audit['Events'] as $event) {
if ($event['Type'] != 'Comment') {
echo $event['Field'] . </span> . $event['Value'] . $event['Previous'];
}
}
echo "</div>"
}
?>
You could wrap your code with an if like
if(count($audit['Events'])>0)
{
//Your code
}
Wny do you open and close php tags every time? Would be better to make everything in PHP and echo whenever you want to print HTML code.
<?php
echo "<h2 class=\"changes\"> Changes: </h2>";
echo "<div id=\"change_box\">";
foreach ($audit['Events'] as $event) {
if ( $event['Type'] != 'Comment') {
echo "<span class=\"field\">".$event['Field']."</span>";
echo $event['Value'];
echo "(".$event['Previous'] .")";
}
}
echo "</div>";
?>
please make space after each <? and make sure you enabled short tags
<?php if(is_array($audit['Events']) && $audit['Events']):?>
<h2 class="changes"> Changes: </h2>
<div id="change_box">
<?php foreach ($audit['Events'] as $event):?>
<?php if ( $event['Type'] != 'Comment'):?>
<span class="field">
<?php echo $event['Field'];?>
</span>:
<?php echo $event['Value']; ?>
<?php echo $event['Previous'];?>
<?php endif;?>
<?php endforeach;endif;?>
</div>

PHP conditional statement to show a field

I have inserted a code to display product attribute in view.phptml, which works fine. But it shows a empty box, even when the field is empty.
The code I used to display is like this
<div class="add-to-box">
<div class="add-to-cart"><div>image path</div>
<h3><?php
echo $_helper->productAttribute($_product, $_product->getFreeGift(), 'free_gift')
?></h3></div></div>
How I can add a condition to above statement to hide the empty box from display when the field is empty.!
Use either empty or is_null, like so:
<?php
if( !empty( $_product->getFreeGift() ) ){
?>
... HTML here ...
<?php
}
?>
or
<?php
if( !is_null( $_product->getFreeGift() ) ){
?>
... HTML here ...
<?php
}
?>
Hi may be you can use this
<?php
if (isset($_helper->productAttribute($_product, $_product->getFreeGift(), 'free_gift'))) {
echo('<div class="add-to-box">
<div class="add-to-cart">
<div>image path</div>
<h3>'.$_helper->productAttribute($_product, $_product->getFreeGift(), 'free_gift').'</h3>
</div>
</div>');
} else {
..... // other stuff
}
The isset function here help to know if a variable contain something usefull.
good work !

Ad block won't place correctly

Basically, I need for the image at the bottom of the page with no text wrapped around it to be in the place of test post 4 (it's going to be a Google Adsense block but I am using images as a placeholder for now). I'm not sure how to do this, right now the code is the following:
<div class="google_ad_post">
<?php if ($count == 3) { ?>
<br /><img src="****" alt="post ad">
<?php } ?>
<?php $count++; ?>
</div>
Yet, the image is still at the bottom of the page. How can I fix this?
Here is the image:
I can't post pictures just yet so the URL to the image is http://i.imgur.com/7rw5B.jpg
I have to see your code to help you better with the Scripting Part, but something logical like this should work:
<?php
$count = 0;
foreach( $posts as $post ) : ?>
<?php if ($count == 3) { ?>
<div class="google_ad_post">
<img src="****" alt="post ad">
</div>
<?php } else { ?>
<div class="post" id="post-<?php the_ID(); ?>><div class="content"><?php the_content(); ?></div>
<?php } ?>
<?php $count++; ?>
<?php endforeach; ?>

Categories