wordpress类别名称在短代码php

时间:2012-06-28 16:13:47

标签: php wordpress categories shortcode

我想在侧栏中的下面的代码中显示当前的类别名称,但我不能。任何人都可以帮助我吗?

谢谢。

<?php
    $weather_city = the_category_name();
    if ($weather_city)
    echo do_shortcode('[forecast location="' . $weather_city . ', Greece" caption="" measurement="C" todaylabel="Σήμερα" datelabel="%%weekday%%" highlow="%%high%%&deg; / %%low%%&deg;" numdays="4" iconset="Incredible" class="css_table_class"]'); ?>

1 个答案:

答案 0 :(得分:0)

$current_categories = get_the_category(); // array of objects
if (!empty($current_categories)) {
    $category = reset($current_categories); // take the first one
    $weather_city = $category->cat_name;

    echo do_shortcode('[forecast location="' . $weather_city . ', Greece" caption="" measurement="C" todaylabel="Σήμερα" datelabel="%%weekday%%" highlow="%%high%%&deg; / %%low%%&deg;" numdays="4" iconset="Incredible" class="css_table_class"]');
}