Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 1506

General Questions/New to Joomla! 5.x • Re: How to hide the output of a custom field?

$
0
0
I forgot to ask the field types. This code is based on the Sold field type to be Radio (Yes/No). It can be easily changed when you use another field type.

Here we go...
Field names, classes, html, etc. are examples, you may want/need to rename/edit them.

1. Create an override for the article.
You can do that manually or under System > Site Template > Your template Details and Files

2. Open the file ~/templates/yourtemplate/html/article/default.php and add the following code.
I always place it at the top, after the use ... stuff.

Code:

// Get the fields$myField = $this->item->jcfields;foreach($myField as $field) {  $myField[$field->name] = $field;}// Shorten the field parameters$price = $myField['my-price-field-name']->value;$sold  = $myField['my-sold-field-name']->value;
3. Now in the code, on the location where you want the price and/or sold banner to display, you need to add some php/html.
This code is only displayed if the price is not empty.
If Sold is set to Yes, it displays Sold, else it displays the price.

Code:

<?php if(!empty($price)) { ?><div class="price-sold-box">  <?php if($sold == "Yes") { ?>  <div class="sold-box">    <span class="sold-text">Sold</span>  </div>  <?php } else { ?>  <div class="price-box">    <span class="price-text"><?php echo $price; ?></span>  </div>  <?php } ?></div><?php } ?>
You can ofcourse split them

Code:

<?php if($sold == "Yes") { ?><div class="sold-box">  <span class="sold-text">Sold</span></div><?php } ?>/* Some other html */<?php if(!empty($price)) { ?><div class="price-box">  <span class="price-text"><?php echo $price; ?></span></div><?php } ?>
4. To stop using the default display options, open the fields for Price and Sold and set Automatic display to Do not automatically display.

5. Finally edit the CSS to style the price and sold boxes.

I have not tested this code, but it's close to something I use.

Statistics: Posted by Mr. Wimpy — Fri Jul 26, 2024 2:56 pm



Viewing all articles
Browse latest Browse all 1506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>