Javascript 获取_category()不';不要在内部工作<;figcaption>;

Javascript 获取_category()不';不要在内部工作<;figcaption>;,javascript,php,wordpress,Javascript,Php,Wordpress,我面临一个奇怪的问题。我正在尝试使用我的wordpress主题的其中一个图库。我想将帖子的类别显示为figcaption,但当我将PHP代码放入其中时,它就不起作用了。当我将相同的代码粘贴到标签外时,它就像一个符咒 请注意,该脚本正在执行某些操作,因为如果有两个以上的category,它将使用逗号,但不会显示类别名称 <div class="grid"> <figure class="effect-sarah"> <?p

我面临一个奇怪的问题。我正在尝试使用我的wordpress主题的其中一个图库。我想将帖子的类别显示为figcaption,但当我将PHP代码放入其中时,它就不起作用了。当我将相同的代码粘贴到标签外时,它就像一个符咒

请注意,该脚本正在执行某些操作,因为如果有两个以上的category,它将使用逗号,但不会显示类别名称

 <div class="grid">
          <figure class="effect-sarah">
            <?php the_post_thumbnail(); ?>
            <figcaption>
              <h2>**Category: <span>  <?php $categories=get_the_category(); $separator=", " ; $output='' ; if ($categories) { foreach ($categories as $category) { $output .='<a href="' . get_category_link($category->term_id) . '">' . $category->cat_name . '</a>' . $separator; } echo trim($output, $separator); } ?></span>**</h2>
              <a href="<?php the_permalink(); ?>">View more</a>
            </figcaption>
          </figure>
        </div>


        <div class="title-excerpt">
          <h3> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <small> <?php the_time( 'F j, Y g:i a'); ?></small></h3>
        </div>
      Category: <span>  <?php $categories=get_the_category(); $separator=", " ; $output='' ; if ($categories) { foreach ($categories as $category) { $output .='<a href="' . get_category_link($category->term_id) . '">' . $category->cat_name . '</a>' . $separator; } echo trim($output, $separator); } ?></span>
              <a href="<?php the_permalink(); ?>">View more</a>

**类别:**
类别:

因此,您的PHP工作得非常好。您可以通过检查页面并查看以下html来确认:

问题在于CSS。具体来说,在
figure
figcaption
元素及其后代
a
标记周围有很多CSS。第一条线索(我相信有几个问题)是CSS的一小部分:

这将使链接缩进200%(例如,使标签加倍),将其字体大小设置为0(例如,太小以至于看不见),并将其不透明度设置为0(例如,即使它更大,也将是完全透明的)


我知道这本身并没有“回答”你的问题,但它确实澄清了你的PHP不是问题所在

我假设对
获取\u category()
的两个调用都在循环中?(例如,
中的一个并非完全不同)。。。很难说你的代码是为了演示而组合在一起的,还是真的是这样编码的。当然,我问的原因是,
get_the_category()
需要一个
$post_id
,如果它是在循环之外使用的。另外,如果你要打开开发人员工具栏(例如firebug或chrome开发工具)看看这两个逗号,你看到了什么?是:
类别:,
?我将代码粘贴到代码中,与代码中的代码完全相同。两者都在content.php中,所以它们确实在循环中。