链接的文本在短代码中消失


Linked text dissapear when in shortcode

在我的WordPress主题中使用短代码工作正常,直到我添加指向某个单词或现有文本的一部分的超链接为止。链接后,文本的那部分就会消失!查看页面源代码,我只能看到空的div标签<div></div>

这是当前在主题中使用的选项卡简码生成器源的一部分:

    function cs_shortcode_pb_tabs($atts, $content="") {
    global $tab_counter;
    $tab_counter++;
    $content = str_replace("[cs_tab_item", "<cs_tab_item", $content);
    $content = str_replace("[/cs_tab_item]", "</cs_tab_item>", $content);
    $content = str_replace('tabs="tabs"]', ">", $content);
    $content = str_replace("<br />", "", $content);
    $content = str_replace("<p>", "", $content);
    $content = str_replace("</p>", "", $content);
    $content = "<tab>". $content . "</tab>";
    $html = "";
    $tabs_count = 0;
        $html .= '<ul class="nav nav-tabs">';
            $xmlObject = new SimpleXMLElement($content);
                foreach ( $xmlObject as $node ){
                    $tabs_count++;
                    if($tabs_count==1) $tab_active=" active"; else $tab_active="";
                    $html .= '<li class="'.$tab_active.'"><a data-toggle="tab" href="#'.str_replace(" ","",$node["title"].$tab_counter).'">'.$node["title"].'</a></li>';
                }
        $html .= '</ul>';
        $html .= '<div class="tab-content">';
        $tabs_count = 0;
            foreach ( $xmlObject as $node ){
                $tabs_count++;
                if($tabs_count==1) $tab_active=" active"; else $tab_active="";
                $html .= '<div class="tab-pane '.$tab_active.'" id="'.str_replace(" ","",$node["title"].$tab_counter).'">'.$node.'</div>';
            }
        $html .= '</div>';
        $html = '<div class="tabs-sectn">'.$html.'</div>';
    return do_shortcode($html).'<div class="clear"></div>';
}
add_shortcode( 'cs_tab', 'cs_shortcode_pb_tabs' );    

请注意,.$node["title"].(第 18 行(工作正常 - 它显示标签名称,但另一方面.$node.(第 26 行(工作正常,直到链接到文本的某些部分。使用的平台是WordPress 3.5。插件已禁用,并且没有 CSS 冲突,例如display:none

在第 26 行中,你直接回显你的节点 echo $node ;(首先将其添加到字符串中,但回显此内容(。所以我希望你的节点包含一些数据,例如:

<node>
<title>title</title>
Text content here echoed as node.
</node>

如果添加指向此纯文本值的链接,则此链接将被视为子节点 (a( 而不是回显。尝试防止这种情况尝试解析您的链接,例如htmlspecialchars()

例:

<?php
$xmlstr = "<?xml version='1.0' standalone='yes'?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
   Content of a node. " . htmlspecialchars('<a href="http://php.net/">PHP</a>') . "
 </movie>
  <movie>
  <title>PHP: Behind the Parser</title>
   Content of a node 2 <a href='http://php.net/'>PHP</a>
 </movie>
</movies>";
$xmlObject = new SimpleXMLElement($xmlstr);
foreach ( $xmlObject as $node ){
  echo $node;
  echo $node->a;
}

正如您在第二个节点中看到的那样,链接成为子节点。您可以使用仅打印内容(在您的情况下为链接文本(的$node->a对此进行回显。