因为专注
所以专业

WebStack导航的site-card.php文件

<?php
/*
* @Theme Name:WebStack
* @Theme URI:https://www.iotheme.cn/
* @Author: iowen
* @Author URI: https://www.iowen.cn/
* @Date: 2019-02-22 21:26:02
* @LastEditors: iowen
* @LastEditTime: 2023-02-20 19:36:41
* @FilePath: \WebStack\templates\site-card.php
* @Description:
*/
if ( ! defined( ‘ABSPATH’ ) ) { exit; } ?>

<?php
// ===== 新增:图标优先级逻辑 =====
$icon_url = get_post_meta($post->ID, ‘_custom_icon’, true); // 1. 优先使用文章自定义图标

// 2. 如果没有文章图标,尝试获取分类默认图标
if (!$icon_url) {
$terms = get_the_terms($post->ID, ‘favorites’); // 替换为您的分类法名称
if ($terms && !is_wp_error($terms)) {
foreach ($terms as $term) {
$category_icon = get_term_meta($term->term_id, ‘category_icon’, true);
if ($category_icon) {
$icon_url = $category_icon;
break; // 只取第一个分类的图标
}
}
}
}

// 3. 如果都没有,使用原主题图标逻辑
if (!$icon_url) {
$thumbnail = get_post_meta($post->ID, ‘_thumbnail’, true);
if ($thumbnail) {
$icon_url = $thumbnail;
} else {
$icon_url = io_get_option(‘ico_url’) . format_url($link_url) . io_get_option(‘ico_png’);
}
}

// 4. 最终回退到主题默认图标
if (!$icon_url) {
$icon_url = $default_ico;
}
// ===== 图标优先级逻辑结束 =====

$title = $link_url;
$is_html = ”;
$tooltip = ‘data-toggle=”tooltip” data-placement=”bottom”‘;
if(get_post_meta($post->ID, ‘_wechat_qr’, true)){
$title=”<img src='” . get_post_meta(get_the_ID(), ‘_wechat_qr’, true) . “‘ width=’128’>”;
$is_html = ‘data-html=”true”‘;
} else {
switch(io_get_option(‘po_prompt’)) {
case ‘null’:
$title = get_the_title();
$tooltip = ”;
break;
case ‘url’:
if($link_url==””)
$title = __(”,’i_theme’);
break;
case ‘summary’:
$title = get_post_meta($post->ID, ‘_sites_sescribe’, true);
break;
case ‘qr’:
if($link_url==””)
$title = __(”,’i_theme’);
else{
$title = “<img src=’//api.qrserver.com/v1/create-qr-code/?size=150×150&margin=10&data=” . $link_url . “‘ width=’128’>”;
$is_html = ‘data-html=”true”‘;
}
break;
default:
}
}

$url = ”;
$blank = ‘_blank’;
if(io_get_option(‘details_page’)){
$url=get_permalink();
}else{
if($link_url==””){
$url = ‘javascript:’;
$blank = ”;
}else{
if(io_get_option(‘is_go’))
$url = home_url().’/go/?url=’.base64_encode($link_url) ;
else
$url = $link_url;
}
}
?>

<a href=”<?php echo $url ?>” target=”<?php echo $blank ?>” class=”xe-widget xe-conversations box2 label-info” <?php echo $tooltip . ‘ ‘ . $is_html ?> title=”<?php echo $title ?>”>
<div class=”xe-comment-entry”>
<div class=”xe-user-img”>
<?php if(io_get_option(‘lazyload’)): ?>
<img class=”img-circle lazy” src=”<?php echo esc_url($default_ico); ?>” data-src=”<?php echo esc_url($icon_url); ?>” onerror=”javascript:this.src='<?php echo esc_url($default_ico); ?>'” width=”40″>
<?php else: ?>
<img class=”img-circle lazy” src=”<?php echo esc_url($icon_url); ?>” onerror=”javascript:this.src='<?php echo esc_url($default_ico); ?>'” width=”40″>
<?php endif ?>
</div>
<div class=”xe-comment”>
<div class=”xe-user-name overflowClip_1″>
<strong><?php the_title() ?></strong>
</div>
<p class=”overflowClip_1″><?php echo get_post_meta($post->ID, ‘_sites_sescribe’, true) ?: preg_replace(“/(\s|\&nbsp\;| |\xc2\xa0)/”,””,get_the_excerpt($post->ID)); ?></p>
</div>
</div>
</a>

赞(0)
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址