【发布时间】:2014-07-26 01:18:58
【问题描述】:
我正在使用 Wordpress 的 Simplicity-Lite 主题为我的第一个客户构建一个网站。 我想以某种方式更改主题,以便将我的图像超链接到特色框位置(幻灯片的正下方)以在同一窗口中打开一个页面。 问题是图像是由一个 PHP 脚本自动生成/获取的,该脚本从媒体库中提取它们,因此一个脚本可以为所有八张图像完成所有工作。 我想通过 PHP 获取这些图像中的每一个链接到它自己的页面,以向我的网站添加交互性,但我已经尝试了几件事,但在 style.css 和 features-box.php 文件中都是徒劳的。 我认为这是因为我找不到超链接的元素,因为它是自动生成的。 下面是 features-box.php 文件中的一段 PHP 脚本,它获取 8 张图像并将它们放置在 features-boxes 位置:
<div id="featured-boxs">
<?php foreach (range(1,8) as $fboxn) { ?>
<span class="featured-box">
<img class="box-image" src="<?php echo of_get_option('featured-image' . $fboxn, get_template_directory_uri() . '/images/featured-image' . $fboxn . '.png') ?>"/>
<h3><?php echo of_get_option('featured-title' . $fboxn, 'Simplicity Theme for Small Business'); ?></h3>
<div class="content-ver-sep"></div><br />
<p><?php echo of_get_option('featured-description' . $fboxn , 'The Color changing options of Simplicity will give the WordPress Driven Site an attractive look. Simplicity is super elegant and Professional Responsive Theme which will create the business widely expressed.'); ?></p>
</span>
这里是 style.css 文件中渲染图像的代码:
#featured-boxs{padding:0 0 10px;display:block; margin: 0 -30px; text-align:center;}
.featured-box{width:210px;margin:0 15px 10px; display:inline-block; text-align:left; vertical-align:top;}
.featured-box h3{font-family:Verdana, Geneva, sans-serif;font-weight:100;font- size:15px;color:#555555;}
#featured-boxs h2{font-family:Verdana, Geneva, sans-serif;font-weight:100;font- size:19px;color:#555555;}
.featured-box-first{padding:20px 0;width:210px;margin:0;}
#featured-boxs img.box-image{border:3px solid #EEEEEE;width:202px;height:100px;}
#featured-boxs img.box-image:hover{box-shadow:0 0 11px 0px #555555;}
#featured-boxs img.box-icon{width:50px;height:50px;}
h3.featured-box2{width:140px;float:right;}
以下是我从对这一挑战的第一反应中得到的部分解决方案。它部分有效,因为它允许我在主题选项中指定要超链接到的页面或任何其他资源。但是,当我链接到一个资源时,我会被带到那个媒体元素(图像本身)而不是指定的超链接。我尝试了一些其他方法,使用主题分配永久链接中使用的图像的媒体 id 将使用的特定图像链接到页面,但我也未能成功。媒体库中的永久链接如下所示:http://www.---.com/?attachment_id=281。我正在考虑记下这些 Id 并在获取图像的 features-box.php 文件中使用它们,以便如果它获取图像并且其 Id 与指定的 Id 相同,它会自动将其超链接到指定的页面。以下是我目前的解决方案。但是,它并没有像上面提到的那样完全工作:
-
为 Simplicity Lite 添加超链接选项 将此超链接选项添加到 simple-lite/inc/options.php 的第 89/90 行
$options[] = 数组( '名称' => '超链接', 'desc' => '输入特色区域的链接。', 'id' => '精选超链接' 。 $fbsi号码, 'std' => '#', '类型' => '文本', );
保存文件,您会在主题选项中看到一个新选项。 输出链接 您可以使用主题选项附带的此功能从您的设置中提取信息:of_get_option()。此函数接受两个参数:名称和默认值。您可以在 simple-lite/inc/options-framework.php 的第 383 行中找到有关它的更多信息。 让我们用 a 标签包装每张图片,并将其链接到设置中存储的字符串。
simplicity-lite/featured-box.php,第 12 行 "/>
【问题讨论】:
标签: php jquery html css wordpress