【问题标题】:Wordpress Shortcodes not working on posts (single.php) but working on pages (page.php)Wordpress 简码不适用于帖子 (single.php) 但适用于页面 (page.php)
【发布时间】:2018-08-11 14:35:27
【问题描述】:

在一天没有找到解决方案后,我正在寻求帮助。

我的活动插件中有简码,它们在页面上运行良好,但不适用于单个帖子页面 (single.php)。不工作是指完全不加载最终的前端源代码(没有所需的代码,甚至没有短代码 sn-p 本身)。

我正在使用全新安装的 _underscores 生成主题。

注意:我知道是主题阻碍了简码,因为当我将主题更改为 251 时,简码​​会起作用。

我尝试了大约 30 种解决方案(使用调试,安装什么文件...没有错误,没有警告)

对于如何找到我的主题中的错误,我非常感谢一些帮助或建议。

这是我的设置:我的 single.php 和 content.php

single.php

<?php
/**
 * The template for displaying all single posts
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
 *
 * @package MyTheme
 */

get_header(); ?>

    <div id="primary" class="content-area">
        <main id="main" class="site-main">

        <?php
        while ( have_posts() ) : the_post();

            get_template_part( 'template-parts/content', get_post_type() );

            the_post_navigation();

            // If comments are open or we have at least one comment, load up the comment template.
            if ( comments_open() || get_comments_number() ) :
                comments_template();
            endif;

        endwhile; // End of the loop.
        ?>

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

<?php
get_sidebar();
get_footer();

内容.php

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

    <header class="entry-header">

        <?php the_title( sprintf( '<h3 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h3>' ); ?>

        <?php if ( 'post' == get_post_type() ) : ?>

        <div class="post-details">
            <div class="post-details-left">
                <i class="fa fa-user-circle"></i> <?php the_author(); ?>
                <i class="fa fa-history"></i> <time><?php the_date(); ?></time>
                <i class="fa fa-sticky-note"></i> <?php the_category(', '); ?>
                <i class="fa fa-tags"></i><?php the_tags('', ', ', ''); ?>
                <?php edit_post_link( 'Edit', '<i class="fa fa-pencil"></i>', '' ); ?>
            </div>

            <div class="post-details-right">
                <div class="post-comments-badge">
                    <a class="post-comments-badge-link" href="<?php comments_link(); ?>"><i class="fa fa-comments"></i> <?php comments_number( 0, 1, '%'); ?></a>
                </div>
            </div>

        </div>

        <?php endif; ?>
    </header>


    <?php if ( has_post_thumbnail() ) { ?>
    <div class="post-image">
        <div class="post-image-hvr">
            <?php the_post_thumbnail(); ?>
        </div>
    </div>
    <?php } ?>


    <div class="post-excerpt">
        <?php the_excerpt(); ?>
    </div>

</article>

再次,非常欢迎任何建议!

【问题讨论】:

    标签: php wordpress shortcode underscores-wp


    【解决方案1】:

    您实际上并没有输出页面内容(例如the_content());只是摘录 (the_excerpt())。

    您是否编写了有问题的短代码?你add a filter for the excerpt了吗?

    【讨论】:

    • 谢谢!回答您的问题:我没有编写简码代码(我只是使用了简单的示例),也没有为摘录添加过滤器。我刚刚包含了 the_content() 并且出现了简码。但是当我删除 the_content() 并添加建议的过滤器时,它们不会。是否有编写此过滤器的特定方法,因此我不必使用 the_content()?再次感谢您! (我只是在学习一切,所以你的每一句话对我和我这样的人来说都是金色的)。
    猜你喜欢
    • 2018-06-16
    • 2023-03-31
    • 1970-01-01
    • 2011-04-26
    • 1970-01-01
    • 2014-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多