WordPress修改the_content标记

| 使用jQuery或PHP,我想修改WordPress中the_content函数的dom结构。在某些帖子中,我使用了h3元素,并且我想添加一个包含内容的包装,直到下一个h3。 所以我想将其转换为:
<h3>Title</h3>
<p>This is just regular text</p>
<h3>Next title</h3>
变成这个:
<div class=\'wrapper\'>
  <h3>Title</h3>
  <p>This is just regular text</p>
</div>
<div class=\'wrapper\'>
  <h3>Next title</h3>
</div>
谢谢!     
已邀请:
        假设内容仅由

组成,并且它们的格式如下:

<div id=\"content\">
   <h3>title</h3>
    <p>..........</p>
    <p>..........</p>
   <h3>another title</h3>
    <p>.........</p>
   <h3>yet another title</h3>
    <p>..........</p>
 </div>
那么您可以在jQuery中尝试。
  //get the main post content
  $content=$(\"#content\");
  $h3s=$content.find(\'h3\');
  $h3s.each(function(index){
       if(index==0)$(this).before(\'<div class=\"wrapper\">\');           
       else $(this).before(\'</div><div class=\"wrapper\">\');
  });
  //remeber to close the last one
  $content.append(\'</div>\');
    

要回复问题请先登录注册