将列拆分为三个+div?

时间:2012-04-23 作者:Phife Dawz

我得到了这个密码(source)

// split content at the more tag and return an array
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;
}

// original content display
// the_content(\'<p>Read the rest of this page &raquo;</p>\');
// split content into array
$content = split_content();
// output first content section in column1
echo \'<div id="column1">\', array_shift($content), \'</div>\';
// output remaining content sections in column2
echo \'<div id="column2">\', implode($content), \'</div>\';
这只获得两列-如何获得第三个div列?

干杯

2 个回复
最合适的回答,由SO网友:Phife Dawz 整理而成

好的,从以下方面找到了一个很好的解决方案:http://digwp.com/2010/03/wordpress-post-content-multiple-columns/

功能。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(\']]>\', \']]&gt;\', $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\\u content()标记:

$content = get_the_content(\'\',FALSE,\'\'); // arguments remove \'more\' text
echo my\\u multi\\u col\\u v2($内容);

添加CSS:

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--> 在帖子/页面内容中添加标签以创建三列。

SO网友:kaiser

具有上述功能split_content() 不可能构建三列布局。它基本上将内容与<!-- more -->-标记为一半,然后构建两列(以非常复杂的方式)。

也许它可以与添加多个<!--more-->-标记到HTML编辑器中的帖子内容。

结束

相关推荐

在users.php中使用Manage_User_Columns显示cimy用户字段

我正在尝试向我的主题函数添加代码。php在仪表板用户中显示使用Cimy用户额外字段插件创建的字段。php。我知道我需要使用manage\\u users\\u列,但除此之外,我陷入了困境。有谁对这个插件足够熟悉,可以帮助我获得要显示的正确字段?