php - 使 Avatar 也成为超链接
问题描述
我有这个 wordpress 模板的部分行,它显示团队成员的姓名并超链接它。该超链接重定向到该成员的实际页面。
<h4 class="sc_team_item_title"><?php echo (!empty($post_options['link']) ? '<a href="'.esc_url($post_options['link']).'">' : '') . (!empty($post_data['post_id']) ? insurance_ancora_get_post_title($post_data['post_id']) : '') . (!empty($post_options['link']) ? '</a>' : ''); ?></h4>
在那条线的上方,有一条线显示了该团队成员的照片:
<div class="sc_team_item_avatar"><?php insurance_ancora_show_layout($post_options['photo']); ?></div>
我想让那张图片也成为重定向到会员个人资料的超链接。我对 PHP 很陌生,无论我尝试什么都失败了。你能帮我看看吗?我想您需要的任何内容都在代码的第一部分。如果您需要整个 php 文件,请告诉我。
解决方案
试试:(希望它对你有用)
<div style="cursor: pointer;" onclick="window.location='<?php echo esc_url($post_options['link']); ?>';" class="sc_team_item_avatar"><?php insurance_ancora_show_layout($post_options['photo']); ?></div>
或者检查 var 是否不为空可能更好
<div style="cursor: pointer;" onclick="window.location='<?php if(!empty($post_options['link'])){ echo esc_url($post_options['link']);} ?>';" class="sc_team_item_avatar"><?php insurance_ancora_show_layout($post_options['photo']); ?></div>
推荐阅读
- php - 如何正确地将我的 PHP 文件链接到我的 CSS
- python - 如何确定字节是 utf-8 还是 utf-16
- python - 替换或交换 3 个列表以创建单个列表/数组
- r - 如何在我的热图上分配 9 列特定颜色的独立渐变?
- c# - 如何解决:下载多个电子表格文件时,该进程无法访问文件“**”,因为它正被另一个进程使用
- django - Embed plotly:dash figure inside django template
- javascript - iPhone / iPad - 终止应用程序时未保存 Safari 浏览器 cookie
- node.js - 为什么我的快速路由器中间件没有定义 req.route?
- vue.js - 事件高度,如使用 vue-cal 的谷歌日历
- wpf - StackPanel 水平内容对齐在 dataTemplate 中居中