1

您好,我正在尝试将我的 grid.css 文件转换为 wordpress 短代码,但是我遇到了问题。

我想看到的:

<div class="row>
    <div class="columns one">Content</div>
    <div class="columns three">Content</div>
</div>

我得到什么:

[column_one]Awesome[/column_one] [column_three]Stuff[/column_three]

我的代码:

<?php while ( have_posts() ) : the_post();
$content = get_the_content();
echo do_shortcode($content);
endwhile; // end of the loop. ?>

我正在一个简单的页面模板上尝试这个。

我怎样才能让它正常工作?

谢谢你。

4

1 回答 1

1

您不需要在循环中添加 do_shortcode 。最好将它添加到 functions.php 文件中,如下所示:

function column_one( $atts, $content = null ) {
    return '<div class="columns one">'.do_shortcode($content).'</div>';
}

add_shortcode('column_one', 'column_one'); 
于 2013-01-29T00:03:47.333 回答