News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

How to call (echo) a spesific costume field value

Started by belsaas, June 17, 2014, 00:12:18 AM

Previous topic - Next topic

belsaas

I am working with the default.php in the map CATEGORY.
I want this page to display the same pictures for each list products with difference links attached in the background for each pictures.
So when I click on the picture I will be redirected to a new site.

I have made a variable to call the pictures like this:
$img_norskkors = '<img src="images/stories/norskkorsenter-rod-hvit-fx-small.jpg" alt="norskkorsenter-rod-hvit-fx-small" height="25" width="35" />';

I have also made a costume filed called "Norsk korsenter" where I can write the link. This custom filed have custom ID 26.

The question is how do I write the code?

I have tried with this code without success:
<a target='_blank' href='<?php $product->custom_value ?>'> <?php echo $img_norskkors ?></a>

How can I echoing this specific value for this custom field ID?



***********
Joomla 2.5.20
VirtueMart 2.6.6









[attachment cleanup by admin]
-------------------------------
Joomla 3.8.1
Virtuemart 3.2.4
PHP 7.1
-------------------------------

GJC Web Design

foreach($product->customfields as $customfield) {
if($customfield->virtuemart_custom_id == '24') {
echo "<a target='_blank' href='".$customfield->custom_value."'>".$img_norskkors."</a>";
}
}


$customfield->virtuemart_custom_id  is the custom field id in VM admin
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

belsaas

Thank you for the answer, but this code doesn't work. The picture didn't show.
I tried it like you wrote it, and I tried some tweaks of it like:

<div style="padding-top: 8px">
        <?php foreach($product->customfields as $customfield) {
             if($customfield->virtuemart_custom_id == '24') {
      ?>
      <span><?php echo "<a target='_blank' href='".$customfield->custom_value."'>".$img_norskkors."</a>"; ?></span>
   <?php }   ?>
   <?php } ?>
</div>


The code for the whole section are like this:

<!-- START OF TITLE AND COSTUMS FIELDS -->
               <div style="padding-left:10px" class="width27 floatleft">
                      <div class="category-header">
            <?php echo JHTML::link($product->link, $product->product_name); ?>
                        </div>
                        <div>
                <?php foreach($product->customfields as $field) {   
                                ?>
                                <div class="customfields">
                                   <span class="vm-custom-title"><?php echo JText::_($field->custom_title); ?></span>
                                   <span class="vm-display"><?php echo $field->custom_value ?></span>
                               </div>
                              <?php 
                                    }
                                 ?>
                   </div>
                    <div style="padding-top: 8px">
                       <?php foreach($product->customfields as $customfield) {
             if($customfield->virtuemart_custom_id == '24') {
             ?>
             <span><?php echo "<a target='_blank' href='".$customfield->custom_value."'>".$img_norskkors."</a>"; ?></span>
             <?php } ?>
             <?php } ?>
                    </div>
                </div>
                <!-- END OF  TITLE AND COSTUMS FIELDS -->

[attachment cleanup by admin]
-------------------------------
Joomla 3.8.1
Virtuemart 3.2.4
PHP 7.1
-------------------------------

GJC Web Design

why would by some amazing coincidence your custom field id be identical to mine?????

$customfield->virtuemart_custom_id == '24'

please read what I wrote

Quote$customfield->virtuemart_custom_id  is the custom field id in VM admin
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

belsaas

Sorry! My fault. No it works!

Thank you very much. :-)
-------------------------------
Joomla 3.8.1
Virtuemart 3.2.4
PHP 7.1
-------------------------------

belsaas

One more question.
If I want to call three another costume fields values can I wrote the code like this?

<?php foreach($product->customfields as $customfield) {
      if($customfield->virtuemart_custom_id == '26', '25','24,'23' ) {
?>
-------------------------------
Joomla 3.8.1
Virtuemart 3.2.4
PHP 7.1
-------------------------------

GJC Web Design

nope

$theseones = array(23,24,25,26);
foreach($product->customfields as $customfield) {
if(in_array($customfield->virtuemart_custom_id,$theseones)) {
               //do something
                  }
}
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

belsaas

Thank you again, but I have some more question.

I have four pictures call via a variables like

$img_norskkors = '<img src="images/stories/norskkorsenter-rod-hvit-fx-small.jpg" alt="norskkorsenter-rod-hvit-fx-small" height="25" width="35" />';
$img_spotify = '<img src="images/stories/spotify-logo.png" alt="logo" height="35" width="35" />';
$img_itunes = '<img src="images/stories/iTunes-icon.png" alt="itunes" height="35" width="35" />';
$img_wiki = '<img src="images/stories/wikipedia-logo.png" alt="wikipedia-logo1" height="35" width="35" />';

I the admin of VM I have made four costume field (ID: 26, 27, 28 and 29).
In those costume fields I write four different links. Sometimes the field are empty too.

In the out put I want to display the pictures if the costume value are TURE (if I have wrote a link in the field. If not, I don't want this picture displayed), and each picture shall call their costume value with the correct link.

I tired with this code, but this gave me a blank page.

****

<div style="padding-top: 8px">
            <?php $theseones = array(26,27,28,29);
         foreach($product->customfields as $customfield) {
         if(in_array($customfield->virtuemart_custom_id,$theseones)) {
             ?>
                           <span><?php echo "<a target='_blank' href='".$theseones->'26'."'>".$img_norskkors."</a>"; ?></span>
                                <span><?php echo "<a target='_blank' href='".$theseones->'27'."'>".$img_spotify."</a>"; ?></span>
                                <span><?php echo "<a target='_blank' href='".$theseones->'28'."'>".$img_itunes."</a>"; ?></span>
                                <span><?php echo "<a target='_blank' href='".$theseones->'29'."'>".$img_wiki."</a>"; ?></span>
                                       
             <?php
                  }
      }
      ?>
</div>

*****

So each 'href' shall call their specific costume id value.


-------------------------------
Joomla 3.8.1
Virtuemart 3.2.4
PHP 7.1
-------------------------------

GJC Web Design

hmmm -- think you need to do a bit of php 101 research

<div style="padding-top: 8px">
            <?php $theseones = array(26,27,28,29);
         foreach($product->customfields as $customfield) {
         if(in_array($customfield->virtuemart_custom_id,$theseones)) {
             if($customfield->virtuemart_custom_id == '26') {
             ?>
                           <span><?php echo "<a target='_blank' href='".$customfield->custom_value."'>".$img_norskkors."</a>"; ?></span>
<?php }elseif($customfield->virtuemart_custom_id == '27') {
?>
                                <span><?php echo "<a target='_blank' href='".$customfield->custom_value."'>".$img_spotify."</a>"; ?></span>

<?php }elseif($customfield->virtuemart_custom_id == '28') {
?>
                                <span><?php echo "<a target='_blank' href='".$customfield->custom_value."'>".$img_itunes."</a>"; ?></span>

<?php }elseif($customfield->virtuemart_custom_id == '29') {
?>
                                <span><?php echo "<a target='_blank' href='".$customfield->custom_value."'>".$img_wiki."</a>"; ?></span>
                                       
             <?php
                  }
      }
      ?>
</div>
<?php } ?>

you'll find a donation link on my website...  :P
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

AH

introduce the use of CASE just to throw in a curve ball!
Regards
A

Joomla 4.4.5
php 8.1