我定制WordPress的博客,我有一个需要进行自定义侧边栏小工具。我的PHP是生锈的最好的。我所试图做的是串联一个PHP变量到一个字符串被设置为一个数组元素。这里是我使用的代码,它似乎并没有工作。它所做的就是在每一个页面的顶部打印样式表目录:

if ( function_exists("register_sidebar") )
    register_sidebar(array(
        "before_widget" => "<div class=\"rounded_box\"><div class=\"top_curve\"><img src=\"".bloginfo('stylesheet_directory')."/images/top_curve.jpg\" alt=\"Top\" width=\"247\" height=\"9\" /></div><div class=\"middle\">",
        "after_widget" => "</div><div class=\"bottom_curve\"><img src=\"".bloginfo('stylesheet_directory')."/images/bottom_curve.jpg\" alt=\"Bottom\"  /></div></div>",
        "before_title" => "<h2>",
        "after_title" => "</h2>",
    ));

所以你可以在这里看到我想要的bloginfo('stylesheet_directory')连接成的元素2。这并不正常工作。它只是结束在页的doctype前顶端打印。

有帮助吗?

解决方案

bloginfo ( 'stylesheet_directory')将回显样式表目录。在声明数组时,实际上是写到标准输出。这就是为什么它会显示在页面的顶部。你所寻找的是 get_bloginfo

其他提示

使用破灭

string implode  ( string $glue  , array $pieces  )
string implode ( array $pieces )

加入用胶水字符串数组元素。

它看起来像你必须在最后一个逗号。这可能是。删除并测试。 我还替换\”具有烧毛”。

<强>更新 与get_bloginfo替换代码bloginfo()()。

if ( function_exists("register_sidebar") )
{
  $args =array(
  "before_widget" => "<div class='rounded_box'><div class='top_curve'><img src='".get_bloginfo('stylesheet_directory')."/images/top_curve.jpg' alt='Top' width='247' height='9' /></div><div class='middle'>",
  "after_widget" => "</div><div class='bottom_curve'><img src='".get_bloginfo('stylesheet_directory')."/images/bottom_curve.jpg' alt='Bottom' /></div></div>",
  "before_title" => "<h2>",
  "after_title" => "</h2>");'

  register_sidebar($args);
}

我知道,这是不是的技术上的回答你的问题,但你有没有考虑:

if ( function_exists("register_sidebar") )
    $ssheet_dir = bloginfo('stylesheet_directory');
    register_sidebar(array(
            "before_widget" => "<div class=\"rounded_box\"><div class=\"top_curve\"><img src=\"$ssheet_dir/images/top_curve.jpg\" alt=\"Top\" width=\"247\" height=\"9\" /></div><div class=\"middle\">",
            "after_widget" => "</div><div class=\"bottom_curve\"><img src=\"$ssheet_dir/images/bottom_curve.jpg\" alt=\"Bottom\"  /></div></div>",
            "before_title" => "<h2>",
            "after_title" => "</h2>",
    ));

这将是更容易和更快 - 这将只涉及使代码bloginfo函数调用一次

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top