Wordpress拆分为更多标签

时间:2014-05-22 16:02:44

标签: php html wordpress

我尝试将<!--more-->标记之前的文章内容与Wordpress中的其他内容分开。

我有两列:

    左侧的
  • 包括条目标题和由<!--more-->标记之前的所有内容组成的“子标题”。
  • 右侧的文章不包括<!--more-->标记之前的所有内容。

我使用以下代码分隔两个部分: 这是“子标题”

<h2><?php global $more; $more=0; the_content(''); $more=1; ?></h2>

这是本文的其余部分。

<?php the_content( '', true ); ?>

一切正常,但我还剩下两件文物。

  • “子标题”包含在<p class="p1">...text...</p>
  • 在文章中有<p><span id="more-15"></span></p>

如何摆脱文物?我现在真的有想法,他们正在调整我的布局。

谢谢!

1 个答案:

答案 0 :(得分:1)

这应该可以让你前进。

<?php
//Output sub-title
global $more;
$more = 0;
$out = apply_filters( 'the_content', get_the_content('') );
$out = str_replace( ']]>', ']]&gt;', $out );
$out = strip_tags( $out, '<br><a><em><u><strong>' ); //may need to add more tags
echo '<h2>'.$out.'</h2>';
$more = 1;
?>

<?php
//Output content
$out = apply_filters( 'the_content', get_the_content('', TRUE ) );
$out = str_replace( ']]>', ']]&gt;', $out );
$repl = '<p><span id="more-' . get_the_ID() . '"></span></p>';
$out = str_replace($repl, '', $out);
echo $out;
?>

更好的方法是将这些作为the_content的过滤器,但不知道整个网站结构,这可能会引入其他布局错误。