duanfen7676 2012-04-26 01:47
浏览 47
已采纳

too long

I'm using the WordPress Shopp plugin to sell products on my WordPress site. So far I love this plugin but I'm trying to do something custom and unfortunately I'm not good enough with PHP to figure this out on my own (I've done tons of research too!).

Here is what I am trying to accomplish...

To display the product title for each individual product Shopp uses the following code to reference the product title...

<?php shopp('product','name'); ?>

What I am trying to do is reference the product name and if for example the product name says something like 'FLIR H-Series Thermal Imaging Camera' I want my code to detect whether or not the product title contains the word 'FLIR' in it and if it DOES contain the word 'FLIR' I want it to echo a FLIR logo image (let's say the URL of the image is http://example.com/images/flir.jpg). Alternatively I would want it to echo a Thermal-Eye logo image anytime the word 'Thermal-Eye' is found in the product title, etc. How could I go about modifying the code to do this?

Hopefully this make sense, thanks for any help!

  • 写回答

1条回答 默认 最新

  • doutuobao4004 2012-04-26 05:18
    关注
    <?php
    $keywords = array('FLIR', 'Thermal-Eye');
    foreach($keywords as $word)
    {
        if(preg_match('/'.$word.'/i', shopp('product','name', 'return=true')))
            echo $word;
    }
    ?>
    

    UPDATE: If you want to echo out a unique image based on the word, rather than the word itself, you can do something like:

    if(preg_match('/'.$word.'/i', shopp('product','name', 'return=true')))
            echo '<img src="'.get_bloginfo('stylesheet_directory').'/images/'.$word.'.jpg" />';
    

    So in the case of FLIR, you just need to make sure FLIR.jpg exists within the images folder in your theme directory.

    Best thing to do is to play around with it and see what works for you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题