im displaying list of results through for each array where i need to hide a button for only specific items in list , i tried it using an if statement , but its hiding button of whole list items , please advice me on this?
here the place i have put code. this will hide whole buttons even though the id is not equal to 83
<div class="jd-items-button-details">
<?php if(($item->categories_id)==83) { ?>
<style type="text/css">
.jd-button-details {display:none !important}
</style>
<?php
} else {
echo "test2";
}
echo $item->categories_id;
?>
<?= JHTML::_('link', $link , JText::_('COM_JOMDIRECTORY_DETAILS'), 'class="jd-button-details"') ?>
您可以使用以下内容:
<div class="jd-items-button-details" <?= $item->categories_id == 83 ? 'style="display: none"' : ''?>>
Even if written once, you css style will be applied to every links with the .jd-button-details
class. Instead you should conditionnaly apply this class to your button:
<style type="text/css">
.jd-button-details
{display: none!important;}
</style>
<div class="jd-items-button-details">
<?php
if(($item->categories_id)==83){
$class = 'jd-button-details';
}
else {
$class = '';
}
echo $item->categories_id;
?>
<?= JHTML::_('link', $link , JText::_('COM_JOMDIRECTORY_DETAILS'), 'class="<?php echo $class; ?>"') ?>
Or even shorter:
<?= JHTML::_('link', $link , JText::_('COM_JOMDIRECTORY_DETAILS'), 'class="'.(($item->categories_id)==83 ? "jd-button-details" : "").'"') ?>
the easiest to do is : dont use tag <styles>
since it will applied to whole html area you're displayed. use inline styling :
<div class="jd-items-button-details">
<?php if(($item->categories_id) !== 83){ ?>
<button>this is button</button>
<?php
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.