When field is empty it outputs a blank line - php

I am using Kirby for my CMS. I setup a custom field and when I have nothing inside it, it still outputs a blank line.
Backend screenshot showing no field value: http://cloud.chrisburton.me/LSyR
View Source showing blank line (52): http://cloud.chrisburton.me/LSW0
My Code:
<ul class="credits">
<?php
if($page->client() != '')
echo '<li><span>Client: </span>'.$page->client().'</li>';
?>
<?php
if($page->art_direction() != '')
echo '<li><span>Client: </span>'.$page->art_direcion().'</li>';
?>
<?php
if($page->typeface() != '')
echo '<li><span>Typeface: </span>'.$page->typeface().'</li>';
?>
</ul>
How can I remove that?

WYSIWYG.
I'd suggest different approach...
<ul class="credits">
<?php
foreach(array('Client' => $page->client(), 'Direction' => $page->art_direction(), 'Typeface' => $page->typeface()) as $key => $value)
if($value != '') echo "\t<li><span>{$key}: </span>{$value}</li>\n";
?>
</ul>
Also, make sure you don't indent <?php and that it starts from position 0.
http://ideone.com/MBWLU0

<ul class="credits">
<?php
if($page->client() != '')
echo '<li><span>Client: </span>'.$page->client().'</li>';
if($page->art_direction() != '')
echo '<li><span>Client: </span>'.$page->art_direcion().'</li>';
if($page->typeface() != '')
echo '<li><span>Typeface: </span>'.$page->typeface().'</li>';
?>
</ul>

Related

worpress custom taxonomy title display also shows description

In my theme it gets the title of the custom taxonomy here
<div class="<?php echo $filters_id . ' '; echo $filters_width; if($layout == 'constrained_fullwidth') echo ' fullwidth-constrained '; if($span_num != 'elastic-portfolio-item' || $layout == 'constrained_fullwidth') echo 'non-fw'; ?>" data-alignment="<?php echo $filter_alignment; ?>" data-color-scheme="<?php echo strtolower($filter_color); ?>">
<div class="container">
<?php if($filter_alignment != 'center' && $filter_alignment != 'left') { ?> <span id="current-category"><?php echo __('All', NECTAR_THEME_NAME); ?></span> <?php } ?> <
<ul>
<?php if($filter_alignment != 'center' && $filter_alignment != 'left') { ?> <li id="sort-label"><?php echo (!empty($options['portfolio-sortable-text'])) ? $options['portfolio-sortable-text'] : __('Sort Portfolio',NECTAR_THEME_NAME); ?>:</li> <?php } ?>
<li><?php echo __('All', NECTAR_THEME_NAME); ?></li>
<?php wp_list_categories(array('title_li' => '', 'taxonomy' => 'project-type', 'show_option_none' => '', 'walker' => new Walker_Portfolio_Filter())); ?>
</ul>
<div class="clear"></div>
</div>
</div>
however whilst it displays the title great, if I add a description, the plugin also displays this here too
I want to make it only show the title...
I am using Salient Visual Composer plugin and showing the Projects "widget" in my page
The page in questions is http://www.jonnyrossmusic.com/acts-2/ where if you click Acoustic for example it also shows the description
I am assuming the problem lies at <?php echo __('All', NECTAR_THEME_NAME); ?>
Thanks

Embedded HTML in if... elseif... else... PHP Code Not Working

I'm brand new to PHP and don't have the first clue about what I'm doing. I found the way to embed HTML in PHP by looking around this site.
However, I can't make this work. My code is:
<?php do { ?>
<?php if ($row_rsMore['contentID'] = 35) : ?>
<li><h4><?php echo $row_rsMore['contentTitle']; ?></h4></li>
<?php elseif ($row_rsMore['contentID'] = 37) : ?>
<li><h4><?php echo $row_rsMore['contentTitle']; ?></h4></li>
<?php elseif ($row_rsMore['contentID'] = 38) : ?>
<li><h4><?php echo $row_rsMore['contentTitle']; ?></h4></li>
<?php else : ?>
<li><h4><?php echo $row_rsMore['contentTitle']; ?></h4></li>
<?php endif ?>
<?php } while ($row_rsMore = mysql_fetch_assoc($rsMore)); ?>
I've tried surrounding the number (35, 37 and 38) with single quotes, double quotes, brackets and variations on these themes.
What happens is that the 'contentTitle' for each of the statements displays correctly but each href shows the same link (that of the first 'if' ie: 'aboutus.php').
What have I got wrong?
try
if ($row_rsMore['contentID'] == 35) :
instead of single =
change all single = to ==

How to hide/show text content using PHP?

I am confused and not sure why this code is not working.
Here is the original code :
//start date to end date
<?php if($show5 < $show6) { ?>
<a>show content</a>
<?php }?>
If 'start date' and 'end date' values are empty then I want to remove or hide <?php if($show5 < $show6) { ?> <?php }?> and 'show content'.
And if 'start date' and 'end date' values are not empty then I want to remove or hide <?php if($show5 != '' && $show6 != '') { ?> <?php }?> and show content. If start to end date are not expired and if start to end date are expired then hide the content.
<?php if($show5 != '' && $show6 != '') { ?>
//start date to end date
<?php if($show5 < $show6) { ?>
<?php } ?>
<a>show content</a>
<?php if($show5 != '' && $show6 != '') { ?>
<?php } ?>
<?php }?>
is this what you were trying to do?
<?php if ($show5 != '' && $show6 != '') { ?>
//start date to end date
<?php if (strtotime($show5) < strtotime($show6)) { ?>
<a>show5 content</a>
<?php } ?>
<?php if (strtotime($show5) > strtotime($show6)) { ?>
<a>show6 content</a>
<?php } ?>
<?php } ?>
The bottom code was not necessary and therefore it was throwing an error. Also the html had to be moved few lines top and you were missing one <?php } ?>
I am not sure at all what are you trying to do... BTW, you don't need to put each sentence between <?php ?> brackets, just until you turn to html:
<?php if($show5 != '' && $show6 != '') {
//start date to end date
if($show5 < $show6) {
}?>
<a>show content</a> <<<---- This is outside the php block, if you want it inside you can do it with echo "<a>show content</a>";
<?php if($show5 != '' && $show6 != '') {
}
}?>
Update
<?php if($show5 != '' && $show6 != '') {
echo "<a>show content</a>";
}
else{
$curDate = date(); //currentDate
if($show5 <= $curDate && $curdate < $show6) {
echo "<a>show another content</a>";
}
}?>
Notice that the date() function can be formatted as you want to match $show5 and $show6. And viceversa, this variables can be formatted to match the date() format: https://secure.php.net/manual/es/function.date.php.
If you modify this code a bit you can make it post some content depending on many different parameters. Also, you could store the content in some other variables, and then post it after all of the ifs block

Joomla 3 - category link breaking if category title contains an ampersand &

I have Joomla v3.x.x template override that creates an isotope layout with some category filters.
The problem I have is that if an ampersand (&) is put into the title of the category, that particular category filter will not show.
Is the a way to escape or allow the ampersand (&) to show and not break the filter for that particular category?
Code:
<?php
defined('_JEXEC') or die;
JHtml::_('bootstrap.tooltip');
if (count($this->children[$this->category->id]) > 0 && $this->maxLevel != 0) : ?>
<?php foreach ($this->children[$this->category->id] as $id => $child) : ?>
<?php if ($this->params->get('show_empty_categories') || $child->numitems || count($child->getChildren())) : ?>
<?php $data_name = $this->escape($child->title); ?>
<?php $data_option = str_replace(' ', '', $data_name); ?>
<li class="btn btn-primary"><?php echo $this->escape($child->title); ?></li>
<?php if (count($child->getChildren()) > 0) : ?>
<?php
$this->children[$child->id] = $child->getChildren();
$this->category = $child;
$this->maxLevel--;
if ($this->maxLevel != 0) :
echo $this->loadTemplate('children');
endif;
$this->category = $child->getParent();
$this->maxLevel++;
?>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif;
This is the particular line that create the filters from the category titles:
<li class="btn btn-primary"><?php echo $this->escape($child->title); ?></li>
The issue is most likely tied to the rendering of the filter select. Try changing the following line:
<?php $data_name = $this->escape($child->title); ?>
to:
<?php $data_name = htmlspecialchars($child->title); ?>
And see if that resolves the issue.

PHP foreach loop mark up

I have a PHP foreach loop which outputs a series of items.
What I want to achieve is some code (a div) wrapped around items 1 & 2 and also wrapped around 3 & the very last item.
Here is the PHP:
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<div class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<span class="itemExtraFieldsValue"><?php echo JHTML::_('content.prepare', $extraField->value); ?></span>
<div class="clearfix"></div>
</div>
<?php $counter++; endforeach; ?>
Any ideas on how I could achieve this?
Many thanks in advance.
Maybe something like this, forgive me my PHP is a bit rusty.
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<?php
$len = count($this->item->extra_fields);
if ($key == 1 || $key == 2 || $key == 3 || $key == len) {
echo "<div>";
}
?>
<div class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<span class="itemExtraFieldsValue"><?php echo JHTML::_('content.prepare', $extraField->value); ?></span>
<div class="clearfix"></div>
</div>
<?php
if ($key == 1 || $key == 2 || $key == 3 || $key == len) {
echo "</div>" ;
}
?>
<?php $counter++; endforeach; ?>
Might have to account for the length of the list, so your last check might be len + 1, and your first 3 checks might be (0, 1, and 2), it depends on what the $key value is.
It's a bit confusing what the $counter++ part of your code does in a foreach, perhaps you should be using that for your modulus and in place of the key.
Regardless it's difficult to code up a solution as I believe your code snippet is incomplete, and it would also be helpful to know what the data is that we are looping through and the intended output of just having the first 3 and the last item wrapped in a div.

Categories