【问题标题】:wordpress theme page not showing plugin gallerywordpress 主题页面不显示插件库
【发布时间】:2018-10-20 02:42:22
【问题描述】:

我是 Wordpress 的新手。我正在尝试从头开始构建主题。 我创建了 page.php,如下所示:

<?php
/**
 * The template for displaying pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages and that
 * other "pages" on your WordPress site will use a different template.
 *
 * @package nameofpackage
 */

get_header(); ?>



<?php get_footer(); ?>

我还安装了 NextGen 插件。 我创建了一个新页面,并使用 NextGen 的“添加画廊”按钮;我最终得到了

[ngg src="galleries" ids="1" display="basic_thumbnail"]

在页面的文本部分(可视部分在一个框中显示插件徽标)。

当我尝试预览结果时,我只得到页眉和页脚,中间没有任何内容;检查器显示不存在与画廊相关的代码。

如果我用 ThemeFifteen 尝试同样的事情,它会起作用。

所以我的问题是:我需要在 function.php 中包含一些内容,以允许我的主题在页面中包含插件的输出吗?谢谢

【问题讨论】:

    标签: wordpress wordpress-theming


    【解决方案1】:

    您缺少WP loopthe_content(),因此在页眉和页脚之间看不到任何内容是绝对正常的。例如,您需要这样的东西:

                    <?php while ( have_posts() ) : the_post(); ?>
    
                        <?php get_template_part( 'loop-templates/content', 'page' );//calling the folder with your loop templates ?>
    
                        <?php
                        // 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;
                        ?>
    
                    <?php endwhile; // end of the loop. ?>
    

    在你的循环模板里面是这样的:

    <article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
    
        <header class="entry-header">
    
            <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
    
        </header><!-- .entry-header -->
    
        <?php echo get_the_post_thumbnail( $post->ID, 'large' ); ?>
    
        <div class="entry-content">
    
            <?php the_content(); ?>
    
            <?php
            wp_link_pages( array(
                'before' => '<div class="page-links">' . __( 'Pages:', 'understrap' ),
                'after'  => '</div>',
            ) );
            ?>
    
        </div><!-- .entry-content -->
    
        <footer class="entry-footer">
    
            <?php edit_post_link( __( 'Edit', 'understrap' ), '<span class="edit-link">', '</span>' ); ?>
    
        </footer><!-- .entry-footer -->
    
    </article><!-- #post-## -->
    

    这是构建主题的常用方法,但请花一些时间学习有关开发自定义主题的初学者教程。获得基本概念非常容易,您需要几个小时才能获得想法!这只是我想强调的一个例子,你的代码的快速而肮脏的修复将是:

    <?php
    /**
     * The template for displaying pages
     *
     * This is the template that displays all pages by default.
     * Please note that this is the WordPress construct of pages and that
     * other "pages" on your WordPress site will use a different template.
     *
     * @package nameofpackage
     */
        get_header(); ?>
    
                        <?php while ( have_posts() ) : the_post(); ?>
                               <?php the_title(); ?>
                               <?php the_content(); ?>
                        <?php endwhile; // end of the loop. ?>
    
        <?php get_footer(); ?>
    

    【讨论】:

    • 谢谢。我的错误是从索引页面中取出循环并将其带到front-page.php。因此,按照您的建议一切正常。我知道我之前应该花一些时间在一些教程上;这是一个出乎意料的要求。再次感谢您
    【解决方案2】:

    你要找的是do_shortcode()See the docs

    请务必同时echo

    <?php 
    
    get_header();
    
    echo do_shortcode('[ngg src="galleries" ids="1" display="basic_thumbnail"]');
    
    get_footer();
    

    您也可以使用apply_filters() 并传入“the_content”钩子。这将使用与后端所见即所得编辑器相同的钩子/过滤器呈现您的短代码,但最终它只是在幕后使用do_shortcode()

    <?php 
    
    get_header();
    
    echo apply_filters('the_content', '[ngg src="galleries" ids="1" display="basic_thumbnail"]');
    
    get_footer();
    

    【讨论】:

    • 这不是他的问题的解决方案,请看我的回答以了解他的代码的真正问题
    • 是的,你是对的。我错过了他提到将短代码添加到可视化编辑器的部分,但仍然什么也没看到。我会给你的答案投赞成票。
    猜你喜欢
    • 1970-01-01
    • 2014-12-28
    • 2020-07-15
    • 1970-01-01
    • 1970-01-01
    • 2017-09-07
    • 1970-01-01
    • 2017-06-13
    • 1970-01-01
    相关资源
    最近更新 更多