【问题标题】:wordpress category name in shortcode php简码php中的wordpress类别名称
【发布时间】:2012-06-28 16:13:46
【问题描述】:

我想在侧边栏下面的代码中显示当前类别名称,但我不能。谁能帮帮我?

谢谢。

<?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"]'); ?>

【问题讨论】:

  • 您似乎缺少if 的一些括号
  • 如果只有一行代码则不需要... :)

标签: php wordpress categories shortcode


【解决方案1】:
$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"]');
}

【讨论】:

  • 你在帖子页面上尝试这个吗?
  • 如果我删除 do_shortcode 类别提供正确但短代码不起作用..
  • 那么你的预测插件肯定有问题。
  • 由于这个问题是关于获取类别名称的,我认为如果你发布一个关于你的插件的新问题会更好。
猜你喜欢
  • 1970-01-01
  • 2017-01-10
  • 2017-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多