【问题标题】:wordpress display categories with imagewordpress 用图像显示类别
【发布时间】:2017-04-11 16:38:14
【问题描述】:

在这里编写 PHP 的新手。几个小时的搜索,不知道我是否在寻找正确的地方。

我有一个自定义分类(目录),其中包含列表的自定义帖子类别。

我正在使用高级自定义字段将图像添加到每个自定义类别(目录图像)。

我目前正在使用下面的代码在自定义目录页面模板中完美地显示自定义类别。

$cat = get_query_var('cat'); $args = array(
'orderby' => 'id',
'child_of' => $cat,
'hide_empty' => 0,
'taxonomy' => directory_categories 
); 
$categories = get_categories($args);
foreach($categories as $category) {
echo '<a href="' . get_category_link( $category->term_id ) . '" class="cat-icon-view">' . "\n";
echo '<img src=" " width="90%" height="164"></img>' . "\n";
echo '  <h5>' . $category->name . '</h5>' . "\n";
echo '</a>' . "\n";
}$

它有放置图像的空间,但是我对编写 php 标记以包含从自定义类别下的自定义图像字段输出的图像没有信心。

<?php the_field('directory-image', false); ?>

我已经阅读了很多关于在 PHP 中编写 PHP 的页面,但我无法让它工作,我确信有更好的方法:帮助!

Write PHP code in PHP How to write php within html within php? Display Categories with Image in Multiple Pages of Homepage - Magento

【问题讨论】:

    标签: php html wordpress markup


    【解决方案1】:

    如果您已将自定义图像字段添加到类别分类,则应通过税元访问它。供参考使用官方doc

    foreach ($categories as $category){ $image = get_term_meta($category->term_id, 'directory-image', true); }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-06
      • 2012-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多