WordPress的画廊没有显示 [英] Wordpress Gallery is not displaying
问题描述
我从头开始开发了一个自定义的wordpress主题.我有一个问题.当我尝试在帖子或页面中使用本机wordpress画廊简码时,它在编辑器中可以很好地显示,但不会在前端显示.
I have developed a custom wordpress theme from scratch. I'm having a issue in it. When I try to use native wordpress gallery shortcode in my post or page, It is display fine in the editor but its not displaying on the front end.
我什至尝试使用:
echo do_shortcode('[gallery columns="5" link="none" ids="70,69,68,67"]');
但是什么都没有出现...
But nothing has shown up...
其他帖子/页面内容显示良好,但没有显示图库.就像它甚至没有在前端产生任何东西一样.
Other post / page content is displaying fine but just gallery is not displaying. Its like its not even generating anything on the front-end.
如果我将主题切换为任何其他主题,它将起作用,但不适用于我的主题,因此很明显这是一个主题问题.我必须为图库添加某种主题支持吗?
If I switched the theme to any other theme it work but not in my theme, so its clear that its a theme problem. Do I have to add some kind of theme support for the gallery?
任何帮助将不胜感激:)
Any help would be appreciated :)
更新:2017年5月2日
我正在使用pre_get_posts
钩子导致问题.有人可以帮我理解为什么吗?
I'm using pre_get_posts
hook which causing the problem. Can someone help me understand why?
推荐答案
等待了很多,但找不到答案...我找到了问题,但不知道如何解决.但幸运的是,有一种解决方法.
Waited a lot but couldn't find an answer... I found the issue but doesn't know how to resolve it. But fortunately there is a way around it.
我一直在使用wordpress的pre_get_posts
钩子来设置tax_query
,它看起来像这样:
I have been using wordpress's pre_get_posts
hook to set a tax_query
which looks like this:
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
对象使用相同的代码,它将起作用!
but if I use same code in index.php with new WP_Query
object it works!
$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'
)
)
) );
不知道为什么,但是有效...
Don't know why but it works...
但是我仍然要等待适当的答案,因为我的存在只是帮助我和其他人的一种方法:)
But still I'll wait for the appropriate answer because mine is just a way around to help me and others :)
这篇关于WordPress的画廊没有显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!