是否使用更多标签将内容拆分为多列?

时间:2012-10-29 作者:qwerty

首先,这几乎与以下内容完全相同:Split columns into three+ divs?

但给定的解决方案不起作用(返回空白)。我猜它与qTranslate冲突,后者在html中添加了一些非常奇怪的注释,但我不确定。

我发现了一个很好的代码片段,它通过more标记将内容拆分为多个片段。问题是它似乎只分为两列。它会忽略其余的more标记。实际上,我并没有将内容划分为列,而是划分为水平部分(中间有分隔符)。

当前代码:

function split_content() {
    global $more;
    $more = true;
    $content = preg_split(\'/<span id="more-\\d+"><\\/span>/i\', get_the_content(\'more\'));
    for($c = 0, $csize = count($content); $c < $csize; $c++) {
        $content[$c] = apply_filters(\'the_content\', $content[$c]);
    }
    return $content;
}
链接线程中建议的解决方案不起作用,我已经搜索了其他解决方案,但没有找到任何有效的解决方案。

以“列”数组返回内容很重要。喜欢$content[0] 是第1列,$content[1] is第2列等。

有什么想法吗?

1 个回复
SO网友:Marty

为什么不为你需要的东西创建几个短代码呢?

您可以创建各种用途的列,,

将此添加到主题功能中。php文件。。

<?php
function yourtheme_one_third( $atts, $content = null ) {
   return \'<div class="one_third">\' . do_shortcode($content) . \'</div>\';
}
add_shortcode(\'one_third\', \'yourtheme_one_third\');

function yourtheme_one_third_last( $atts, $content = null ) {
   return \'<div class="one_third last">\' . do_shortcode($content) . \'</div><div class="clearboth"></div>\';
}
add_shortcode(\'one_third_last\', \'yourtheme_one_third_last\');

function yourtheme_two_third( $atts, $content = null ) {
   return \'<div class="two_third">\' . do_shortcode($content) . \'</div>\';
}
add_shortcode(\'two_third\', \'yourtheme_two_third\');

function yourtheme_two_third_last( $atts, $content = null ) {
   return \'<div class="two_third last">\' . do_shortcode($content) . \'</div><div class="clearboth"></div>\';
}
add_shortcode(\'two_third_last\', \'yourtheme_two_third_last\');

function yourtheme_one_half( $atts, $content = null ) {
   return \'<div class="one_half">\' . do_shortcode($content) . \'</div>\';
}
add_shortcode(\'one_half\', \'yourtheme_one_half\');

function yourtheme_one_half_last( $atts, $content = null ) {
   return \'<div class="one_half last">\' . do_shortcode($content) . \'</div><div class="clearboth"></div>\';
}
add_shortcode(\'one_half_last\', \'yourtheme_one_half_last\');

function yourtheme_one_fourth( $atts, $content = null ) {
   return \'<div class="one_fourth">\' . do_shortcode($content) . \'</div>\';
}
add_shortcode(\'one_fourth\', \'yourtheme_one_fourth\');

function yourtheme_one_fourth_last( $atts, $content = null ) {
   return \'<div class="one_fourth last">\' . do_shortcode($content) . \'</div><div class="clearboth"></div>\';
}
add_shortcode(\'one_fourth_last\', \'yourtheme_one_fourth_last\');

function yourtheme_three_fourth( $atts, $content = null ) {
   return \'<div class="three_fourth">\' . do_shortcode($content) . \'</div>\';
}
add_shortcode(\'three_fourth\', \'yourtheme_three_fourth\');

function yourtheme_three_fourth_last( $atts, $content = null ) {
   return \'<div class="three_fourth last">\' . do_shortcode($content) . \'</div><div class="clearboth"></div>\';
}
add_shortcode(\'three_fourth_last\', \'yourtheme_three_fourth_last\');

function yourtheme_one_fifth( $atts, $content = null ) {
   return \'<div class="one_fifth">\' . do_shortcode($content) . \'</div>\';
}
add_shortcode(\'one_fifth\', \'yourtheme_one_fifth\');

function yourtheme_one_fifth_last( $atts, $content = null ) {
   return \'<div class="one_fifth last">\' . do_shortcode($content) . \'</div><div class="clearboth"></div>\';
}
add_shortcode(\'one_fifth_last\', \'yourtheme_one_fifth_last\');

function yourtheme_two_fifth( $atts, $content = null ) {
   return \'<div class="two_fifth">\' . do_shortcode($content) . \'</div>\';
}
add_shortcode(\'two_fifth\', \'yourtheme_two_fifth\');

function yourtheme_two_fifth_last( $atts, $content = null ) {
   return \'<div class="two_fifth last">\' . do_shortcode($content) . \'</div><div class="clearboth"></div>\';
}
add_shortcode(\'two_fifth_last\', \'yourtheme_two_fifth_last\');

function yourtheme_three_fifth( $atts, $content = null ) {
   return \'<div class="three_fifth">\' . do_shortcode($content) . \'</div>\';
}
add_shortcode(\'three_fifth\', \'yourtheme_three_fifth\');

function yourtheme_three_fifth_last( $atts, $content = null ) {
   return \'<div class="three_fifth last">\' . do_shortcode($content) . \'</div><div class="clearboth"></div>\';
}
add_shortcode(\'three_fifth_last\', \'yourtheme_three_fifth_last\');

function yourtheme_four_fifth( $atts, $content = null ) {
   return \'<div class="four_fifth">\' . do_shortcode($content) . \'</div>\';
}
add_shortcode(\'four_fifth\', \'yourtheme_four_fifth\');

function yourtheme_four_fifth_last( $atts, $content = null ) {
   return \'<div class="four_fifth last">\' . do_shortcode($content) . \'</div><div class="clearboth"></div>\';
}
add_shortcode(\'four_fifth_last\', \'yourtheme_four_fifth_last\');

function yourtheme_one_sixth( $atts, $content = null ) {
   return \'<div class="one_sixth">\' . do_shortcode($content) . \'</div>\';
}
add_shortcode(\'one_sixth\', \'yourtheme_one_sixth\');

function yourtheme_one_sixth_last( $atts, $content = null ) {
   return \'<div class="one_sixth last">\' . do_shortcode($content) . \'</div><div class="clearboth"></div>\';
}
add_shortcode(\'one_sixth_last\', \'yourtheme_one_sixth_last\');

function yourtheme_five_sixth( $atts, $content = null ) {
   return \'<div class="five_sixth">\' . do_shortcode($content) . \'</div>\';
}
add_shortcode(\'five_sixth\', \'yourtheme_five_sixth\');

function yourtheme_five_sixth_last( $atts, $content = null ) {
   return \'<div class="five_sixth last">\' . do_shortcode($content) . \'</div><div class="clearboth"></div>\';
}
add_shortcode(\'five_sixth_last\', \'yourtheme_five_sixth_last\');
?>
然后在主题样式中添加一些css。css文件

.one_half{ width:48%; }
.one_third{ width:30.66%; }
.two_third{ width:65.33%; }
.one_fourth{ width:22%; }
.three_fourth{ width:74%; }
.one_fifth{ width:16.8%; }
.two_fifth{ width:37.6%; }
.three_fifth{ width:58.4%; }
.four_fifth{ width:67.2%; }
.one_sixth{ width:13.33%; }
.five_sixth{ width:82.67%; }
.one_half,.one_third,.two_third,.three_fourth,.one_fourth,.one_fifth,.two_fifth,.three_fifth,.four_fifth,.one_sixth,.five_sixth{ position:relative; margin-right:4%; float:left; }
.last{ margin-right:0 !important; clear:right; }
.clearboth {clear:both;display:block;font-size:0;height:0;line-height:0;width:100%;}
然后在写文章时,使用新的短代码为特定文本等创建区域。。

[one_third]text here[/one_third]
[one_third_last]text here[/one_third_last]
[two_third]text here[/two_third]
[two_third_last]text here[/two_third_last]
[one_half]text here[/one_half]
[one_half_last]text here[/one_half_last]
etc...etc....
更改所有函数名称以适合您的主题,并编辑任何css以匹配您的主题设置等。。

此处为完整来源http://tutorials.mysitemyway.com/adding-column-layout-shortcodes-to-a-wordpress-theme/

马蒂

结束

相关推荐

Content in footer file

我发誓我以前做过这件事,但现在我一片空白。。。我正在尝试获取它,以便在我的页脚中有可编辑的内容。php文件。以便我(或用户)可以更新页面区域内的内容。但我不记得该怎么做,或者我是否需要做一个小部件?