2014-11-24 64 views
-1

我在查找帖子的类别ID,然后在下面的短代码中使用它。要找到我使用<?php the_category_ID(); ?>的类别ID,但我不确定如何使用类别ID的输出并将其替换为include_categories =。即我想用我从<?php the_category_ID(); ?>获得的当前类别ID替换4号。如何在另一个内部使用php变量

<?php echo do_shortcode('[include_categories="4"]'); ?> 

我厌倦了以下操作,但没有奏效。任何想法将不胜感激。

<?php echo do_shortcode('[include_categories="<?php the_category_ID(); ?>"]'); ?> 

我知道我不能使用PHP内部的另一个PHP代码,但我不知道如何把报价之间的类别ID。

谢谢。

+0

你永远不能有''内现有的PHP代码。 – Albzi 2014-11-24 09:08:24

回答

1

尝试 -

<?php echo do_shortcode('[include_categories="'.the_category_ID().'"]'); ?> 
+0

[the_category_ID()](http://codex.wordpress.org/Function_Reference/the_category_ID)已被弃用,因为0.71 ... – rnevius 2014-11-24 09:15:38

+0

问题dint提到它..它使用相同的.. – 2014-11-24 09:16:52

+0

谢谢sgt。它工作完美!我只是想知道为什么使用单引号“'在双引号内/ – user2334436 2014-11-24 09:20:58

2

几件事情:(1)你不能嵌套<?php ?>标签,(2)the_category_ID()一直以来的WordPress 0.71弃用。您需要改用get_the_category()

正确的解决办法是:

<?php echo do_shortcode('[include_categories="' . get_the_category() . '"]'); ?> 

圆点. “串联” 与get_the_category()return ED 50值的字符串。你可以阅读更多关于string operators in the PHP docs

-1

使用此添加PHP verial在短代码:

相关问题