Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在没有转义标记的WordPress中准确显示全部内容_Php_Html_Wordpress - Fatal编程技术网

Php 在没有转义标记的WordPress中准确显示全部内容

Php 在没有转义标记的WordPress中准确显示全部内容,php,html,wordpress,Php,Html,Wordpress,我想在主页上显示WordPress的最新帖子。我正在使用WordPress API和函数来显示这一点,但在这之后,获取内容()删除并转义所有的seved标记,我的帖子不能正确显示,例如编辑器标记 此函数用于转义HTML标记: <ul style="list-style: none;margin:5px" class="latest-posts"> <!-- LOOP START --> <?php $t

我想在主页上显示WordPress的最新帖子。我正在使用WordPress API和函数来显示这一点,但在这之后,
获取内容()
删除并转义所有的seved标记,我的帖子不能正确显示,例如编辑器标记

此函数用于转义HTML标记:

        <ul style="list-style: none;margin:5px" class="latest-posts">
            <!-- LOOP START -->
            <?php $the_query = new WP_Query( 'showposts=3' ); ?>
            <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
                <!-- THIS DISPLAYS THE POST THUMBNAIL, The array allows the image to has a custom size but is always kept proportional -->
                <li> <?php the_post_thumbnail( array(100,100) );?></li>
                <!-- THIS DISPLAYS THE POST TITLE AS A LINK TO THE MAIN POST -->
                <li>
                    <a href="<?php the_permalink() ?>">
                        <?php the_title(); ?>
                    </a>
                </li>
                <!-- THIS DISPLAYS THE EXCERPT OF THE POST -->
                <li>
                    <?php echo mb_substr(get_the_content(), 0, 1200).'&nbsp;...'; ?>
                </li>
                <!-- READ MORE LINK -->
                <li><a href="<?php the_permalink() ?>">more ...</a></li>
            <?php endwhile;?>
            <!-- LOOP FINNISH -->
        </ul>

基本上有三种方法可以输出文章内容的摘录

  • 使用函数,在post editor中输出摘录字段的内容,如果未填充,将显示帖子内容的前55个单词(使用过滤器控制摘录的长度)

  • 要使用
    快速标签,标签将仅显示
    快速标签的摘录。该quicktag在单页模板中不起作用

  • 手动从帖子内容中删除HTML并显示自定义摘录。一种方法是使用函数:

    echo mb_substr( wp_filter_nohtml_kses( get_the_content() ), 0, 1200 );
    

以上所有方法都将从帖子内容中删除HTML。要在文章编辑器的摘录使用摘录字段中包含HTML,WordPress将保留您在文章编辑器中包含的HTML。还有一些类似的插件可以从内容中创建摘录并保留html,但我不相信有一种防弹的方法可以做到这一点。

如果
获取内容()
包含html,那么您的substr操作几乎肯定会将标记切成两半,留下一堆破碎的html.scape?服务生?这对我来说没有任何意义。@MightyPork此函数为我删除所有html标记。如何解决这个问题?
mb_substr
只是理解多字节字符的
substr
,因此前缀是
mb
。不管怎样,正如@MarcB所解释的,这都不是一个好方法。如果
get\u the\u content()
函数返回html,它就不起作用了。@mightyport,使用
mb\u substr
我想获得1200个字符的完整内容。我可以将此功能设置为具有此功能吗?我使用的是
sahifa
主题,这个主题有自己的摘要内容设置