【问题标题】:How to manage page--front.tpl.php images from back-end/admin-panel in drupal 7如何在drupal 7中管理来自后端/管理面板的页面--front.tpl.php图像
【发布时间】:2014-07-24 05:10:37
【问题描述】:

我正在使用 drupal 7 开发一个网站,我在 page--front.tpl.php 中创建了一个主页,其中 Static Html 如下所示,

<div class="col-sm-8 col-xs-24 botmboxes">
              <div class="row">
                <div class="boxbotmimg">
                  <img class="img-responsive" src="./sites/all/themes/korhanifashion/images/PlasticRug-Boat.png">
                  <span class="hovblck"></span>
                </div>
                <div class="botboxhov">
                  <a href="<?php print $front_page; ?>limited_offers">
                    <img class="bbres" src="./sites/all/themes/korhanifashion/images/limroffer.png"></a>
                </div>
              </div>
            </div>
            <div class="col-sm-4 col-xs-24 botmboxes botboxthree">
              <div class="row">
                <div class="boxbotmimg">
                  <img class="img-responsive" src="./sites/all/themes/korhanifashion/images/AnchorLine_BLCR_HI.png">
                  <span class="hovblck"></span>
                </div>
                <div class="botboxhov">
                  <a href="https://www.facebook.com/KORHANIhome">
                    <img class="bbres" src="./sites/all/themes/korhanifashion/images/fusonfbok.png"></a>
                </div>
              </div>
            </div>

我想从后端管理这些图像,即来自Admin-panel。以便管理员可以更改来自Admin-panel 的图像,以及管理员如何从后端放置指向该图像的链接。 我怎么能这样做? 提前致谢

【问题讨论】:

    标签: php drupal drupal-7


    【解决方案1】:

    我通常通过创建自定义内容类型(https://www.drupal.org/node/306792)来解决类似的问题(自定义动态主页内容)。

    然后您可以硬编码以读取模板文件中特定类型的节点或使用视图 (https://www.drupal.org/project/views)。

    添加示例代码:

    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'node')
          ->entityCondition('bundle', 'home_image')
          ->entityCondition('status', 1);
    $result = $query->execute();
    
    if (isset($result['node'])) {
        $nodes = node_load_multiple(array_keys($result['node']));
        foreach ($nodes as $node) {
            $img_url = file_create_url($node->field_image['und'][0]['uri']);
        }
    }
    

    在上面的代码中,“home_image”是您创建的内容类型的名称,“field_image”是图像字段的名称。在编辑内容类型的字段时,您可以添加和编辑图像字段的名称。请务必将字段类型设置为“图像”。

    【讨论】:

    • 有什么办法只是创建一个内容类型并在图像部分插入一些php代码,以便在将图像输入内容类型时,图像应该显示在插入php代码的位置。
    • 在您的模板中,您可以加载您刚刚使用 EntityFieldQuery(drupal.org/node/1343708) 创建的自定义内容类型的节点。它返回 nid 列表。使用 node_load_multiple() 加载节点对象,可以使用 file_create_url() 获取图片的 url: file_create_url($node->field_image['und'][0]['uri]);
    • 请发布一些示例代码或编辑我发布的代码,谢谢
    • 非常感谢我正在尝试这个,我应该把这段代码放在哪里,并且 $img_url 像我认为的那样粘贴 src=""
    • 你可以把代码放在你的模板文件 page--front.tpl.php 中,是的,在 'src' 属性中回显 $img_url。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-19
    • 2014-05-16
    • 2012-06-24
    • 1970-01-01
    • 2018-12-30
    • 2018-07-29
    • 2021-05-07
    相关资源
    最近更新 更多