【问题标题】:Why the oputput of an image gallery plugin is not displayed into a page of my WordPress custom theme?为什么图片库插件的输出没有显示在我的 WordPress 自定义主题的页面中?
【发布时间】:2016-02-28 11:55:31
【问题描述】:

作为 WordPress 开发人员,我很新,我对自己从 0 开始开发的主题感到疯狂。

因此,您可以在此链接下载整个主题,以便在详细信息中查看整个代码:http://www.asper-eritrea.com/AsperThemeV2.zip

在这个网站上,我尝试安装一个名为 GMedia Gallery 的图片库插件(我也尝试过使用其他插件,但我遇到了类似的问题),这个:https://it.wordpress.org/plugins/grand-media/

使用这个插件,我创建了一个画廊,然后进入:

外观 --> 菜单 --> GMedia 画廊 ---> 我的画廊 我将创建的画廊作为页面添加到我的主菜单中。

这里我有一个大问题,因为使用我的自定义主题,点击相关链接进入主菜单,画廊没有显示并且页面是空的,你可以在这里看到:

http://www.asper-eritrea.com/gmedia-gallery/eventi-e-manifestazioni/

我很确定这是与我的主题相关的问题,因为切换到任何默认 WordPress 主题(例如 二十十二)画廊都完美地显示在页面中,这里是屏幕截图这证明了这个断言:

所以问题必须与我的自定义主题有关,因为使用另一个主题可以正常工作!!!

我真的不知道这个问题的原因。我认为这可能取决于我自定义了 content-page.php 文件的事实,或者它可能与某些 JQuery 问题有关。

在具体情况下,如您所见,打开主题项目,我已将 JQuery 添加到 /assets/js/ 目录中,然后将主题的 JQuery 支持添加到 function.php 文件,这样:

/* Function automatically executed by the hook 'load_java_scripts':
 * 1) Load all my JavaScripts
 */
function load_java_scripts() {

    // Load JQuery:
    wp_enqueue_script('jquery');
    // Load FlexSlider JavaScript
    wp_enqueue_script('flexSlider-js', get_template_directory_uri() . '/assets/plugins/flexslider/jquery.flexslider.js', array('jquery'), 'v2.1', true);
    // Load bootstrap.min.js:
    wp_enqueue_script('bootstrap.min-js', get_template_directory_uri() . '/assets/bootstrap/js/bootstrap.min.js', array('jquery'), 'v3.0.3', true);

    // Load FancyBox:
    wp_enqueue_script('fancy-js', get_template_directory_uri() . '/assets/plugins/fancybox/jquery.fancybox.pack.js', array('jquery'), 'v2.1.5', true);
    // Load scripts.js:
    wp_enqueue_script('myScripts-js', get_template_directory_uri() . '/assets/js/scripts.js', array('jquery'), '1.0', true);
    // Load Modernizer:
    wp_enqueue_script('myodernizer-js', get_template_directory_uri() . '/assets/js/modernizr.custom.js', array('jquery'), '2.6.2', true);

}

add_action('wp_enqueue_scripts', 'load_java_scripts');

但我不太确定它是否正确,因为当我这样做时:

// Load JQuery:
wp_enqueue_script('jquery');

我没有指定 jquery.js 文件的路径,那么究竟在做什么呢? (我以前做过很多次)。

那么可能是什么问题?我该如何尝试修复它?

太多了

EDIT 1:按照建议,我将分析 content-page.php 文件的内容,该文件应该代表 页面中使用的模板。 php 代表 CMS 中的通用页面(我认为大概是放置画廊插件的地方):

<?php
/**
 * The default template for displaying content
 *
 * Used for both single and index/archive/search.
 *
 * @package WordPress
 * @subpackage AsperTheme
 * @since AsperTheme 1.0
 */
?>


<!-- Create a div with a unique ID thanks to the_ID() and semantic classes with post_class() 
     the_ID(): Print the numeric ID of the current post 
     post_class(): Print out and add various post-related classes to the div tag
-->
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>                              

    <header>
        <h3 class="entry-title">
                <a href="<?php the_permalink(); ?>" 
                   title="<?php printf(__('Permalink to %s', 'your-theme'), the_title_attribute('echo=0')); ?>"
                   rel="bookmark"><?php the_title(); ?>
                </a>

        </h3>

        <div class="entry-meta-page">
            <span class="meta-prep meta-prep-author"><?php _e('By ', 'your-theme'); ?></span>
            <span class="author vcard">
                <a class="url fn n" href="<?php echo get_author_link(false, $authordata -> ID, $authordata -> user_nicename); ?>" 
                                    title="<?php printf(__('View all posts by %s', 'your-theme'), $authordata -> display_name); ?>"><?php the_author(); ?>
                </a>
            </span>
            <span class="meta-sep"> | </span>
            <span class="meta-prep meta-prep-entry-date"><?php _e('Published ', 'your-theme'); ?></span>
            <span class="entry-date">
                <abbr class="published" title="<?php the_time('Y-m-d\TH:i:sO') ?>"><?php the_time(get_option('date_format')); ?></abbr>
            </span>
            <?php edit_post_link( __( 'Edit', 'your-theme' ), "<span class=\"meta-sep\">|</span>\n\t\t\t\t\t\t<span class=\"edit-link\">", "</span>\n\t\t\t\t\t" ) ?>
         </div>     <!-- .entry-meta -->

    </header>

    <div class="entry-content">    
        <?php the_content(__('Continue reading <span class="meta-nav">&raquo;</span>', 'your-theme')); ?>
        <?php wp_link_pages('before=<div class="page-link">' . __( 'Pages:', 'your-theme' ) . '&after=</div>') ?>
    </div>      <!-- .entry-content -->

    <!--
    <div class="entry-utility">

        <span class="cat-links">
            <span class="entry-utility-prep entry-utility-prep-cat-links"><?php _e('Posted in ', 'your-theme'); ?></span>
            <?php echo get_the_category_list(', '); ?>
        </span>

        <span class="meta-sep"> | </span>

        <?php the_tags( '<span class="tag-links"><span class="entry-utility-prep entry-utility-prep-tag-links">' . __('Tagged ', 'your-theme' ) . '</span>', ", ", "</span>\n\t\t\t\t\t\t<span class=\"meta-sep\">|</span>\n" ) ?>
            <span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'your-theme' ), __( '1 Comment', 'your-theme' ), __( '% Comments', 'your-theme' ) ) ?></span>
            <?php edit_post_link( __( 'Edit', 'your-theme' ), "<span class=\"meta-sep\">|</span>\n\t\t\t\t\t\t<span class=\"edit-link\">", "</span>\n\t\t\t\t\t\n" ) ?>
    </div>      <!-- #entry-utility 
    -->

</article>  <!-- #post-<?php the_ID(); ?> -->

所以这里似乎没有引用 the_content() 函数。但是为什么我要使用 the_content() 函数来显示我的画廊呢?这里官方文档说是用来显示帖子内容,这和插件输出有什么关系?

【问题讨论】:

    标签: php wordpress content-management-system wordpress-theming


    【解决方案1】:

    在您的网站上,我在 entry-content 块中看到了图库,但它已发表评论,因此未显示。

    见下面的代码:

    <div class="entry-content">
      <!--<div class="gmedia_gallery phantom_module" id="GmediaGallery_3" data-gallery="3" data-module="phantom"> ... </div>-->
    </div>
    

    在其他页面(例如here)上,您的内容显示两次:第一次评论,但第二次没有 cmets 并正常显示。

    尝试检查 single.phpcontent-page.php 中的 the_content() 函数。

    这可能会有所帮助。

    更新 1

    这里是复制页面内容的代码。文件 contentPost.php [ line:47 ]

    <!--<?php the_content(__('Continue reading <span class="meta-nav">&raquo;</span>', 'your-theme')); ?>-->
    

    此代码必须删除或正确注释:

    <?php //the_content(__('Continue reading <span class="meta-nav">&raquo;</span>', 'your-theme')); ?>
    

    我正在激活您的主题并使用测试库创建帖子http://template.dev-city.me/gallery/

    更新 2

    有关 WordPress 主题开发的更多信息。

    【讨论】:

    • 我已经编辑了我的原始帖子,在其底部添加了附加信息。请您进一步澄清一下吗?
    • 我在表示的文件中看不到错误。你能给出所有主题文件的链接吗?如果没有,您可以检查 the_content() 使用的主题中的所有 *.php 文件。可能你会发现这样的东西:
    • 嘿伙计,整个主题的链接在原始讨论中,但是这里是:www.asper-eritrea.com/AsperThemeV2.zip 如果您可以查看并尝试帮助我,我将非常感谢你(我是一名 Java 开发人员,我不太喜欢 PHP,这是一个人道主义协会网站,我正在免费工作。如果你帮助我,我很乐意在网站)
    • 我第一次没有看到主题的链接,对不起(我已经更新了答案,试试这个解决方案。
    • 很高兴我的回答对您有所帮助!至于你的问题。您很可能已经使用帖子模板创建了帖子。如有必要,您还可以创建具有相同画廊的静态页面。您可以在 WordPress Codex 上阅读有关 WordPress 主题的更多信息。我附上了第一篇文章的链接。编码不错!
    猜你喜欢
    • 2018-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-07
    相关资源
    最近更新 更多