dongxing7083 2017-07-13 15:48
浏览 42
已采纳

前端开发人员试图理解Wordpress / PHP代码中的奇怪语法

I'm a front end designer starting to dabble in backend stuff.

I am starting to create a wordpress site for a side business of mine and am using a couple of different plugins. In order for me to successfully use this plugin, I have to edit one of the plugins template files. When I use a certain option in the plugin (Pulling a image down from amazon, tumblr, ebay, instagram, etc...), it pulls down the correct image but inserts a hard coded width and height in the html.

This is great for rendering of the page quick, but I want to change the width and height of the image in the html.

Here's the kicker. In the php, there is a template file in the plugin where i see it pulls this from. It's 50% regular html code and 50% php in the template file.

(So in the plugin settings, if you choose this option, it pulls from that image template.)

In the template, there is a section for the image tag. Which places the <img xxxxxx src=xxxx width=xxxxx height=xxxxx alt=xxxxxx> code into the html.

Here is how the code reads.

    <?php
/*
 * Template:    Image and Prices
 * Stylesheets: basic.css, image.css
 * Scripts:     popover.js
 */
?>

<?php
$price_l = isset($item['attributes']['ListPrice']) ? $item['attributes']['ListPrice'] : false;
$price_c = isset($item['offer']) && isset($item['offer']['price']) ? $item['offer']['price'] : false;
$price_l_numeric = floatval(preg_replace('#[^\d.]#', '', $price_l));
$price_c_numeric = floatval(preg_replace('#[^\d.]#', '', $price_c));
?>

<div class="easyazon-block-information">
    <?php if($image_atts) { ?>
    <div class="easyazon-block-image-container">
        <?php printf('<a %s><img %s /></a>', easyazon_collapse_attributes($link_atts), easyazon_collapse_attributes($image_atts)); ?>
    </div>
    <?php } ?>

    <div class="easyazon-block-information-title"><?php printf('<a %s>%s</a>', easyazon_collapse_attributes($link_atts), esc_html($item['title'])); ?></div>

    <div class="easyazon-block-information-prices">
        <?php if($price_l && (false === $price_c || $price_l_numeric >= $price_c_numeric)) { ?>
        <div class="easyazon-block-information-price"><?php printf('<td class="easyazon-block-information-price-label">%s:</td> <td class="easyazon-block-information-price-value"><a %s>%s</a></td>', __('List Price'), easyazon_collapse_attributes($link_atts), esc_html($price_l)); ?></div>
        <?php } ?>

        <?php if($price_c && 'N/A' !== $price_c) { ?>
        <div class="easyazon-block-information-price"><?php printf('<td class="easyazon-block-information-price-label">%s:</td> <td class="easyazon-block-information-price-value"><a %s>%s</a></td>', __('Price'), easyazon_collapse_attributes($link_atts), esc_html($price_c)); ?></div>
        <?php } ?>

        <?php if($item['offer'] && $item['offer']['saved'] && 'N/A' !== $item['offer']['saved']) { ?>
        <div class="easyazon-block-information-price"><?php printf('<td class="easyazon-block-information-price-label">%s:</td> <td class="easyazon-block-information-price-value"><a %s>%s</a></td>', __('You Save'), easyazon_collapse_attributes($link_atts), esc_html($item['offer']['saved'])); ?></div>
        <?php } ?>
    </div>

    <?php if($cta_atts) { ?>
    <div class="easyazon-block-information-cta">
        <?php $cta_atts['class'][] = 'easyazon-block-cta'; ?>
        <?php printf('<a %s><img %s /></a>', easyazon_collapse_attributes($link_atts), easyazon_collapse_attributes($cta_atts)); ?>
    </div>
    <?php } ?>

    <div class="easyazon-block-information-price-disclaimer">
        <small class="easyazon-price-disclaimer" data-content="<?php printf(__('Prices are accurate as of %1$s. Product prices and availability are subject to change. Any price and availablility information displayed on Amazon at the time of purchase will apply to the purchase of any products.'), date('F j, Y \a\t g:i A', $item['fetched'] + get_option('gmt_offset') * HOUR_IN_SECONDS)); ?>"><?php _e('Price Disclaimer'); ?></small>
    </div>
</div>

What does the s% mean? How does this code pull in all this information for the image. Is it located somewhere else in the plugin? There's lots of other folder. I couldn't personally find it, maybe I didn't look hard enough?

  • 写回答

1条回答 默认 最新

  • dpwtr666638 2017-07-13 23:40
    关注

    The %s is a type specifier which means it will treat it as a string. It uses the format argument with these specifies that act as slots that the following arguments will be slotted into.

    $format = 'some digit %d and some string %s'; echo sprintf($format, $digit, $string);

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

报告相同问题?

悬赏问题

  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。