我正在尝试将变量添加$link
到此自定义查询的末尾。我从官方 php 页面http://php.net/manual/en/language.operators.string.php关注了这一点,但似乎没有任何效果。
<?php
ob_start();
the_category();
$link = ob_get_contents();
ob_end_clean();
$custom_query = new WP_Query('posts_per_page=-1&category_name='. $link);
if ($custom_query->have_posts()) :
while ($custom_query->have_posts()) : $custom_query->the_post();
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$all_tags[] = $tag->term_id;
}
}
endwhile;
endif;
$tags_arr = array_unique($all_tags);
$tags_str = implode(",", $tags_arr);
$args = array(
'smallest' => 12,
'largest' => 12,
'unit' => 'px',
'number' => 0,
'format' => 'list',
'include' => $tags_str
);
wp_tag_cloud($args);
?>
我检查了变量是否包含正确的输出,它确实如此。我还尝试在查询中输入类别名称,这很有效。
所以我的问题是如何将变量添加到查询中?
编辑
如果我可以将 $link 输出打印到一段文本,那么我认为这会起作用。