Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用带页段塞的数组_Php_Wordpress - Fatal编程技术网

Php 使用带页段塞的数组

Php 使用带页段塞的数组,php,wordpress,Php,Wordpress,我使用以下代码根据类别id显示图像: <?php if (is_category( 'web-design' )){ ?> <img src="<?php bloginfo('template_directory'); ?>/images/slider_webdesign.png" title="خدمات تصميم وتطوير المواقع" height="200px" width="960px" /> <?php }else if (

我使用以下代码根据类别id显示图像:

<?php 
if (is_category( 'web-design' )){
?>   
<img src="<?php bloginfo('template_directory'); ?>/images/slider_webdesign.png" title="خدمات تصميم وتطوير المواقع" height="200px" width="960px" />
<?php
}else if (is_category( 'printing' )){
?>
<img src="<?php bloginfo('template_directory'); ?>/images/slider_printing.png" title="تصميم مطبوعات" height="200px" width="960px" />
<?php
}else if (is_category( 'online-marketing' )){
?>

/图像/滑块网页设计.png“title=”200px“width=”960px“>
/图像/滑块打印.png“title=”200px“width=”960px“/>
我想制作一个只包含一个条件的数组,以显示带有类别slug的图像,这可能吗?


<?php

$categories = array(
  'web-design' => array(
    'image' => 'slider_webdesign.png',
    'title' => 'Title of image',
    'height' => '200',
    'width' => '960'
  ),
  'template_directory' => array(
    'image' => 'slider_printing.png',
    'title' => 'Title of image',
    'height' => '200',
    'width' => '960'
  )
);

$category = false;

/* following code might need rewriting since I'm not sure if this is the */
/* correct way of getting current category slug */

if (is_category()) {
  $slug = get_category(get_query_var('cat'))->slug;

  if (isset($categories[$slug])) {
    $category = $categories[$slug];
  }
}

?>

<?php if ($category): ?>
<img src="<?php bloginfo('template_directory'); ?>/images/<?=$category['image']?>" title="<?=$category['title']?>" height="<?=$category['height']?>" width="<?=$category['width']?>" />
<?php endif ?>