【问题标题】:Wordpress Gallery is not displayingWordpress 图库未显示
【发布时间】:2017-05-02 18:47:52
【问题描述】:

我从头开始开发了一个自定义的 wordpress 主题。我有一个问题。当我尝试在我的帖子或页面中使用原生 wordpress 图库短代码时,它在编辑器中显示正常,但在前端没有显示。

我什至尝试过使用:

echo do_shortcode('[gallery columns="5" link="none" ids="70,69,68,67"]');

但是什么都没有出现……

其他帖子/页面内容显示正常,但没有显示图库。就像它甚至没有在前端生成任何东西一样。

如果我将主题切换到任何其他主题,它可以工作但不在我的主题中,所以很明显这是一个主题问题。我是否必须为图库添加某种主题支持?

任何帮助将不胜感激:)


更新:2017 年 5 月 2 日

我正在使用导致问题的pre_get_posts 钩子。有人可以帮我理解为什么吗?

【问题讨论】:

  • 它是否适用于其他主题?你试过了吗?
  • 是的,它适用于其他主题...我试过了
  • 能否贴出page.php文件的代码
  • 还要检查页眉和页脚中有 wp_head() 和 wp_footer()

标签: php wordpress gallery


【解决方案1】:

等了很久,但找不到答案...我找到了问题,但不知道如何解决。但幸运的是,有办法绕过它。

我一直在使用 wordpress 的 pre_get_posts 挂钩来设置 tax_query,如下所示:

add_action( 'pre_get_posts', 'homeInjector' );

function homeInjector( $query ) {

        if ( $query->is_home() ) {

            $issues = get_terms( array(
                'taxonomy' => 'issues'
            ) );

            if ( isset( $_POST['issue'] ) ) {
                $term = $_POST['issue'];
            } else {
                $term = $issues[0]->slug;
            }


            $arg = array(
                array(
                    'taxonomy' => 'issues',
                    'terms'    => $term,
                    'field'    => 'slug'
                )
            );

            $query->set( 'tax_query', $arg );

        }

但如果我在 index.php 中使用与 new WP_Query 对象相同的代码,它就可以工作!

$issues = get_terms( array(
    'taxonomy' => 'issues'
) );

if ( isset( $_POST['issue'] ) ) {
    $term = $_POST['issue'];
} else {
    $term = $issues[0]->slug;
}

$qry = new WP_Query( array(
    'post_type' => 'post',
    'tax_query' => array(
        array(
            'taxonomy' => 'issues',
            'terms'    => $term,
            'field'    => 'slug'
        )
    )
) );

不知道为什么,但它有效......

但我仍然会等待适当的答案,因为我只是帮助我和其他人的一种方式:)

【讨论】:

    猜你喜欢
    • 2012-07-05
    • 2014-05-21
    • 2015-05-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-07
    • 2017-08-02
    • 2012-10-22
    • 1970-01-01
    相关资源
    最近更新 更多