向Wordpress的Simplicity-Lite Featured-Box元素添加超链接 [英] Adding a Hyperlink to Wordpress' Simplicity-Lite featured-box element

查看:117
本文介绍了向Wordpress的Simplicity-Lite Featured-Box元素添加超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Wordpress的Simplicity-Lite主题为我的第一个客户之一建立一个网站. 我想以某种方式更改主题,以便在功能框位置(幻灯片放映下方)超链接我的图像,以在同一窗口中打开一个页面. 问题在于,这些图像是由PHP脚本自动生成/提取的,该脚本从媒体库中将其提取出来,因此,一个脚本对所有八张图像都进行了处理. 我想将这些通过PHP提取的图像链接到自己的页面,以增加与我的网站的交互性,但是我尝试了几件事,但是style.css和featured-box.php文件都徒劳无功. 我认为这是因为我无法找到超链接的元素,因为它是自动生成的. 以下是featured-box.php文件中PHP脚本的一部分,该文件可获取8张图像并将其放置在featured-boxes位置:

I'm building a site for one of my very first clients using Wordpress' Simplicity-Lite Theme. I'd like to alter the theme somehow so as to hyperlink my images in the featured-boxes position (Right below the slideshowshow) to open up a page in the same window. The problem is that the images are automatically generated/fetched by a PHP script that picks them up from the media gallery and so one script does it all for all the eight images. I want to make each of these images as fetched by PHP link to its own page to add interactivity to my site but I've tried several things but all in vain both in the style.css and the featured-box.php files. I think it's because I can't find element to hyperlink since it's auto-generated. Below is a section of the PHP script in the featured-box.php file that fetches the 8 images and places them in the featured-boxes positions:

<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文件中用于渲染图像的代码:

Here is the code in the style.css file that renders the images:

#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并在获取图像的Featured-box.php文件中使用它们,以便如果获取图像并且其ID等于指定的ID,它将自动将其超链接到指定的页面.以下是我目前正在使用的解决方案.但是,如上所述,它不能完全正常工作:

Below is the partial solution I got from the first response to this challenge. It's partially working because it lets me specify a page to or any other resource to hyperlink to in the theme options. However, when I link to a resource, I'm instead taken to that very media element(image itself) and not the hyperlink specified. I've tried some other way of linking a particular image used to a page using the media id that the theme assigns the image used in the permalink but I've failed to pull it off too. The permalink looks like this in the media library: http://www.---.com/?attachment_id=281 . I was thinking of noting down these Ids and use them in the featured-box.php file that fetches the images so that if it fetches the image and its Id is equivalent to the one specified, it automatically hyperlinks it to the page specified. Below is the current solution that I'm at. However, it's not fully working as noted above:

  1. 为Simplicity Lite添加超链接选项 将此超链接选项添加到simple-lite/inc/options.php的第89/90行

  1. Adding a Hyperlink Option for Simplicity Lite Add this hyperlink option into line 89/90 of simplicity-lite/inc/options.php

$ options [] = array( '名称'=>'超链接', 'desc'=>'输入特色区域的链接.', 'id'=>'功能超链接'. $ fbsinumber, 'std'=>'#', 'type'=>'text',);

$options[] = array( 'name' => 'Hyperlink', 'desc' => 'Input the link for the Featured Areas.', 'id' => 'featured-hyperlink' . $fbsinumber, 'std' => '#', 'type' => 'text', );

保存文件,您将在主题选项中看到一个新选项. 输出链接 您可以使用主题选项of_get_option()附带的此函数从设置中提取信息.该函数接受两个参数:名称和默认值.您可以在simple-lite/inc/options-framework.php,第383行中找到有关它的更多信息. 让我们用标签包装每个图像,然后将其href设置为设置中存储的字符串.

Save the file and you'll see a new option in your theme options. Output the link You can pull the info from your settings using this function which comes with the theme options: of_get_option(). This functions accepts two parameters: name and default value. You can find out more about it in simplicity-lite/inc/options-framework.php, line 383. Lets wrap each of the images with an a tag and href it to the stored string in your settings.

simplicity-lite/featured-box.php,第12行 "/>

simplicity-lite/featured-box.php, line 12 "/>

推荐答案

请尝试以下操作:

<a href="<?php the_permalink (); ?>"><img class="box-image" src="<?php echo of_get_option('featured-image' . $fboxn,    get_template_directory_uri() . '/images/featured-image' . $fboxn . '.png') ?>"/></a>

代替

<img class="box-image" src="<?php echo of_get_option('featured-image' . $fboxn,    get_template_directory_uri() . '/images/featured-image' . $fboxn . '.png') ?>"/>

应该可以.

这篇关于向Wordpress的Simplicity-Lite Featured-Box元素添加超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆