Question

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"') ?>
Was it helpful?

Solution

You can use something like:

<div class="jd-items-button-details" <?= $item->categories_id == 83 ? 'style="display: none"' : ''?>>

OTHER TIPS

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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top