【问题标题】:Wordpress - Shortcode Ignoring External DivsWordpress - 忽略外部 Div 的简码
【发布时间】:2015-04-18 09:05:51
【问题描述】:

我发现了一个大问题,我真的不明白发生了什么。所以我有一个 div,在那个 div 中嵌套了一个短代码。

编辑:短代码按应有的方式输出,它只是忽略它嵌套的所有 div 并单独输出,强制它高于页面上的其余内容。

例如:

<div id="adiv"> [SHORTCODE][/SHORTCODE] </div> <!-- Should output the same way, right? -->

而是输出:

    [SHORTCODE][/SHORTCODE]
    
    <div id="adiv"><div> <!-- Completely ignoring the fact that the shortcode is nested -->

我发誓我不是一个完全的菜鸟,但这可能是一个菜鸟问题。任何和所有的帮助都是赞赏的。至少可以说我很困惑!

谢谢, 果酱

【问题讨论】:

  • 你确定不应该有花括号吗,我有一个使用短代码的插件,它是花括号?
  • 短代码本身正在工作,它会进入页面顶部。完全忽略它周围的所有 div。为了以防万一,我尝试了花括号,但这次并非如此。谢谢你的帮助,我真的很感激:)

标签: html wordpress-theming wordpress


【解决方案1】:

我设法回答了我自己的问题,希望我能帮助其他有同样问题的人:

/*-------------------------------------------------------------------
 *						Some Shortcodey Thingy
 *------------------------------------------------------------------*/

add_shortcode('thingy','thingy_shortcodes');

function thingy_shortcodes( $atts, $content = null )
{
	extract(shortcode_atts(array( 'category' => '0'),$atts));
	
	ob_start(); <!--- use this to set the content you want to get AKA the stuff you                       want FOR DISPLAY -->
	
	STUFF FOR DISPLAY...... 
    GOES HERE

	$popular = ob_get_contents(); <!-- Set the variable that is going to dispay your                                        STUFF FOR DISPLAY-->
	ob_end_clean();               <!-- Where STUFF FOR DISPLAY ENDS-->

	return $popular;              <!-- Return your content -->
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-29
    • 1970-01-01
    • 1970-01-01
    • 2021-09-03
    • 2013-07-18
    • 1970-01-01
    • 1970-01-01
    • 2016-07-19
    相关资源
    最近更新 更多