Wordpress拆分为更多标签

I tried separating the content of an article before the <!--more--> Tag from the rest in Wordpress.

I have two columns:

  • on the left side including the entry-title and a "sub-title" consisting of everything BEFORE the <!--more--> Tag.
  • on the right side the article excluding everything before the <!--more--> Tag.

I used the following code to separate both parts: This is the "sub-title"

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

This is the rest of the article.

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

Everything works, but I have two artifacts left.

  • the "sub-title" is wrapped in <p class="p1">...text...</p>
  • in the article there is this <p><span id="more-15"></span></p>

How can I get rid of the artifacts? I really have now idea and they are screwing with my layout.

Thanks!

This should work to get you going.

<?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;
?>

A better approach would be to make these as filters for the_content, but without knowing your whole site structure, this could introduce other layout errors.