本文介绍了PHP中的超链接自动生成图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在使用 Wordpress'Simplicity-Lite主题为我的第一个客户建立网站。 我想改变主题,以超链接我的图片在特色盒位置(在幻灯片放映下面的右侧)打开一个页面在同一个窗口。 问题是图像是由PHP脚本自动生成/抓取的,它从媒体库中拾取图像,所以一个脚本对所有8个图像。 我想让这些图片中的每一个通过PHP链接到自己的页面来添加互动性到我的网站,但我已经尝试了几件事情,但都没有白费在 style.css 和特色box.php 文件中。 我认为这是因为我无法找到超链接的元素,因为它是自动生成的。 下面是 features-box.php 文件中PHP脚本的一部分,它提取8张图片,框位置: < div id =featured-boxs> <?php foreach(range(1,8)as $ fboxn){?> < span class =featured-box> < img class =box-imagesrc =<?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,'Simplicity的颜色变化选项将给WordPress驱动网站一个有吸引力的外观,简约是超级优雅和专业响应主题将创造的业务广泛表达。 ?>< / 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;} #features-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;} 解决方案 这些精选的帖子是从您的主题选项中提取的。您需要在精选图片和精选图片中添加新的精选链接选项。 我没有测试以下内容步骤,但你会得到的想法。 1。为Simplicity Lite添加超链接选项 将此超链接选项添加到 simple-lite / inc / options的 89/90 行中。 php $ options [] = array('name'=>'Hyperlink' 'desc'=>'输入特色区域的链接。','id'=>'featured-hyperlink'。$ fbsinumber,'std'=> '#','type'=>'text',); 保存文件,您将在主题选项中看到一个新选项。 2。输出链接 您可以使用主题选项附带的函数从您的设置中获取信息: of_get_option / code>。此函数接受两个参数: name 和默认值。您可以在 simplicity-lite / inc / options-framework.php 行 383 中找到更多信息。 让每个图像包含 a 标签和 href 到设置中存储的字符串。 / p> simplicity-lite / featured-box.php ,行 12 < img class =box-imagesrc =<?php echo of_get_option('featured-image'。$ fboxn,get_template_directory_uri / featured-image'。$ fboxn。'.png')?>/> 成为 <?php echo of_get_option('featured-image'。$ fboxn)? '< a href ='of_get_option('featured-hyperlink'。$ fboxn)。'>':''; ?> < img class =box-imagesrc =<?php echo of_get_option('featured-image'。$ fboxn,get_template_directory_uri()。/ images / featured-image'。$ fboxn。 .png')?>/> <?php echo of_get_option('featured-image'。$ fboxn)? '< / a>':''; ?> 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>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;} 解决方案 Those featured 'posts' are extracted from your theme options. You'll need to add a new "featured-link" option among the "featured-title" and "featured-image".I've not tested the following steps, but you'll get the idea.1. Adding a Hyperlink Option for Simplicity LiteAdd this hyperlink option into line 89/90 of simplicity-lite/inc/options.php$options[] = array( 'name' => 'Hyperlink', 'desc' => 'Input the link for the Featured Areas.', 'id' => 'featured-hyperlink' . $fbsinumber, 'std' => '#', 'type' => 'text', );Save the file and you'll see a new option in your theme options.2. Output the LinkYou 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, line 12<img class="box-image" src="<?php echo of_get_option('featured-image' . $fboxn, get_template_directory_uri() . '/images/featured-image' . $fboxn . '.png') ?>"/>becomes<?php echo of_get_option('featured-image' . $fboxn) ? '<a href="' . of_get_option('featured-hyperlink' . $fboxn) . '">' : ''; ?> <img class="box-image" src="<?php echo of_get_option('featured-image' . $fboxn, get_template_directory_uri() . '/images/featured-image' . $fboxn . '.png') ?>"/><?php echo of_get_option('featured-image' . $fboxn) ? '</a>' : ''; ?> 这篇关于PHP中的超链接自动生成图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 08:21