【发布时间】:2016-08-17 11:40:37
【问题描述】:
在牙科诊所的 wordpress 网站中,有多种服务(例如牙齿矫正)。这些服务就像“类别”,使用名称和 slug 名称。 (例如 Orthodontics / cat_orthodontics)。
在前端,服务页面显示每个类别、类别名称和描述。我只需要放置与每个类别相关的图像。
我注意到在创建区域以显示这些图像中的每一个的类别文件 (category.php) 中,有几行控制前端:
<?php
$args = array( 'taxonomy' => 'services_category', 'hide_empty' => '0', 'exclude' => $pixhealth_deps);
$pixhealth_categories = get_categories ($args);
if( $pixhealth_categories ):
foreach($pixhealth_categories as $pixhealth_cat) :
$pixhealth_t_id = $pixhealth_cat->term_id;
$pixhealth_cat_meta = get_option("services_category_$pixhealth_t_id");
$pixhealth_link = !isset($pixhealth_cat_meta['pix_serv_url']) || $pixhealth_cat_meta['pix_serv_url'] == '' ? get_term_link( $pixhealth_cat ) : $pixhealth_cat_meta['pix_serv_url'];
?>
<div class="departments-item ">
<span class="icon-round bg-color_second helper">
<i class="icon <?php echo esc_attr($pixhealth_cat_meta['pix_icon']) ?>"></i>
</span>
</div>
<h3 class="ui-title-inner"><?php echo wp_kses_post($pixhealth_cat->name) ?></h3>
<p class="ui-text"><?php echo pixhealth_limit_words($pixhealth_cat->description, 20) ?></p>
<a class="btn btn_small" href="<?php echo esc_url($pixhealth_link) ?>"><?php _e("READ MORE", "PixHealth") ?></a>
</div>
<?php
endforeach;
endif; ?>
“departments-item”在前端创建每个显示的服务:
<div class="departments-item ">
要放置图像,我需要为每个服务创建一个新的 div 并删除 <i class="icon">,因为我不想为每个服务显示图标。我需要图片。
所以我尝试了这个:
<?php
$args = array( 'taxonomy' => 'services_category', 'hide_empty' => '0', 'exclude' => $pixhealth_deps);
$pixhealth_categories = get_categories ($args);
if( $pixhealth_categories ):
foreach($pixhealth_categories as $pixhealth_cat) :
$pixhealth_t_id = $pixhealth_cat->term_id;
$pixhealth_cat_meta = get_option("services_category_$pixhealth_t_id");
$pixhealth_link = !isset($pixhealth_cat_meta['pix_serv_url']) || $pixhealth_cat_meta['pix_serv_url'] == '' ? get_term_link( $pixhealth_cat ) : $pixhealth_cat_meta['pix_serv_url'];
?>
<div class="departments-item ">
<!--<span class="icon-round bg-color_second helper">
<i class="icon <?php /*?><?php echo esc_attr($pixhealth_cat_meta['pix_icon']) ?><?php */?>"></i>
</span>-->
<?php servicios=array('cirugia_oral','endodoncia','estetica_dental','implantes_dentales','odontopediatria','ortodoncia','periodoncia','rehabilitacion_oral'); ?>
<div class="inner-departments <?php echo wp_kses_post($pixhealth_cat->name) ?>">
</div>
<h3 class="ui-title-inner"><?php echo wp_kses_post($pixhealth_cat->name) ?></h3>
<p class="ui-text"><?php echo pixhealth_limit_words($pixhealth_cat->description, 20) ?></p>
<a class="btn btn_small" href="<?php echo esc_url($pixhealth_link) ?>"><?php _e("READ MORE", "PixHealth") ?></a>
</div>
<?php
endforeach;
endif; ?>
我添加了一个数组:
<?php servicios=array('cirugia_oral','endodoncia','estetica_dental','implantes_dentales','odontopediatria','ortodoncia','periodoncia','rehabilitacion_oral'); ?>
并添加了一行来创建每个 div:
<div class="inner-departments <?php echo wp_kses_post($pixhealth_cat->name) ?>">
我注意到在另一行中:<?php echo wp_kses_post($pixhealth_cat->name) ?> 与每个类别的名称相呼应,因此我决定在我的新 div 中使用它来创建每个类别类。
但是,我想使用数组中的名称,而不是每个类别中的名称,因为某些名称具有特殊字符,例如“ñ”,并且不能用作类。
我不知道如何将类别的名称与数组中的每个项目相关联,也许为数组中的每个项目使用一个 foreach 以及类别中的每个名称?这个想法是为每个类别创建一个独特的类,这样我就可以使用 CSS 为每个类添加图像。
如果您对如何为每个班级添加独特的图像有更好的想法,请告诉我。
感谢您的帮助。
【问题讨论】:
-
我认为您需要简化您的要求。
-
答案已更新,我想这就是您所需要的?
-
感谢@logic-unit 清理我的问题!