如何解析在过滤器“ the_content”之后添加的任何内容

时间:2019-01-31 11:49:02

标签: php wordpress dom domparser

如何解析在过滤器“ the_content”之后添加的所有内容?

例如,我具有通过Worpdress Admin控制台创建的简单页面的html结构->页面->添加新页面:

<div id="content" class="site-content">
<div class="wrap">
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">
            <article id="post-20" class="post-20 page type-page status-publish hentry">
                <header class="entry-header">
                    <h1 class="entry-title">Some page</h1>
                    <span class="edit-link">
                        <a class="post-edit-link" href="http://wp.loc/wp-admin/post.php?post=20&amp;action=edit">Edit
                            <span class="screen-reader-text"> "Some page"</span>
                        </a>
                    </span> 
                </header><!-- .entry-header -->
                <div class="entry-content">
                </div><!-- .entry-content -->
            </article><!-- #post-## -->

        </main><!-- #main -->
    </div><!-- #primary -->
</div><!-- .wrap -->

在那之后,用一些代码我将任何东西添加到主题的page.php中。例如:

<ul>
    <li>Some content after working out "the_content" filter</li>
    <li>Some text</li>
    <li>Some text</li>
    <li>Some text</li>
    <li>Some text</li>
</ul>

之后,我得到此页面:

<div id="content" class="site-content">
<div class="wrap">
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">
            <article id="post-20" class="post-20 page type-page status-publish hentry">
                <header class="entry-header">
                    <h1 class="entry-title">Some page</h1>
                    <span class="edit-link">
                        <a class="post-edit-link" href="http://wp.loc/wp-admin/post.php?post=20&amp;action=edit">Edit
                            <span class="screen-reader-text"> "Some page"</span>
                        </a>
                    </span>
                </header><!-- .entry-header -->
                <div class="entry-content">
                </div><!-- .entry-content -->
            </article><!-- #post-## -->

        </main><!-- #main -->
    </div><!-- #primary -->
</div><!-- .wrap -->

<ul>
    <li>Some content after working out "the_content" filter</li>
    <li>Some text</li>
    <li>Some text</li>
    <li>Some text</li>
    <li>Some text</li>
</ul>

因此,当我将过滤器称为“ the_content”时,我得到的是这样:

<div id="content" class="site-content">
<div class="wrap">
<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
        <article id="post-20" class="post-20 page type-page status-publish hentry">
            <header class="entry-header">
                <h1 class="entry-title">Some page</h1>
                <span class="edit-link">
                    <a class="post-edit-link" href="http://wp.loc/wp-admin/post.php?post=20&amp;action=edit">Edit
                        <span class="screen-reader-text"> "Some page"</span>
                    </a>
                </span> 
            </header><!-- .entry-header -->
            <div class="entry-content">
            </div><!-- .entry-content -->
        </article><!-- #post-## -->

    </main><!-- #main -->
</div><!-- #primary -->

我需要连接$ content和计算出“ the_content”过滤器后添加的内容。我认为我需要为此使用Dom Parser。有什么建议吗?

0 个答案:

没有答案