首页 > 解决方案 > 使 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 文件,请告诉我。

标签: phpwordpresswordpress-theming

解决方案


试试:(希望它对你有用)

<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>

推荐阅读