SO网友:Eric B.
这里有一个很棒的帖子:https://digwp.com/2010/03/wordpress-post-content-multiple-columns/ 关于如何做到这一点。
我最常用的方法是数字3。这有点复杂,但以下是步骤。要获得更深入的报道(这可能是你想要的),请查看这篇文章。
将my\\u multi\\u col\\u v2函数添加到函数中。php文件
function my_multi_col_v2($content){
// run through a couple of essential tasks to prepare the content
$content = apply_filters(\'the_content\', $content);
$content = str_replace(\']]>\', \']]>\', $content);
// the first "more" is converted to a span with ID
$columns = preg_split(\'/(<span id="more-\\d+"><\\/span>)|(<!--more-->)<\\/p>/\', $content);
$col_count = count($columns);
if($col_count > 1) {
for($i=0; $i<$col_count; $i++) {
// check to see if there is a final </p>, if not add it
if(!preg_match(\'/<\\/p>\\s?$/\', $columns[$i]) ) {
$columns[$i] .= \'</p>\';
}
// check to see if there is an appending </p>, if there is, remove
$columns[$i] = preg_replace(\'/^\\s?<\\/p>/\', \'\', $columns[$i]);
// now add the div wrapper
$columns[$i] = \'<div class="dynamic-col-\'.($i+1).\'">\'.$columns[$i].\'</div>\';
}
$content = join($columns, "\\n").\'<div class="clear"></div>\';
}
else {
// this page does not have dynamic columns
$content = wpautop($content);
}
// remove any left over empty <p> tags
$content = str_replace(\'<p></p>\', \'\', $content);
return $content;
}
更换
the_content()
在页面模板中标记以下内容:
$content = get_the_content(\'\',FALSE,\'\'); // arguments remove \'more\' text
echo my_multi_col_v2($content);
添加一些CSS以将标记格式化为列
/* dynamic columns */
div.dynamic-col-1 { float: left; width: 38%; padding-right: 2%;}
div.dynamic-col-2 { float: left; width: 38%;padding-right: 2%;}
div.dynamic-col-3 { float: left; width: 20%;}
div.clear { clear: both; }
记住将两者相加
<!--more-->
在帖子/页面内容中添加标签以创建三列。