有时,通常出现在我们主页上的“特色”图片已经停止显示。
我做了一些挖掘,在索引中找到了这个模板代码。php(这是Artificer WooThemes主题)
这似乎是处理特色图像的代码:
<ul class="featured-products">
<!-- The first 3 -->
<?php
$args = array( \'post_type\' => \'product\', \'posts_per_page\' => 3, \'meta_query\' => array( array(\'key\' => \'_visibility\',\'value\' => array(\'catalog\', \'visible\'),\'compare\' => \'IN\'),array(\'key\' => \'_featured\',\'value\' => \'yes\')) );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); $_product;
if ( function_exists( \'get_product\' ) ) {
$_product = get_product( $loop->post->ID );
} else {
$_product = new WC_Product( $loop->post->ID );
}
?><li class="featured">
<?php //woocommerce_show_product_sale_flash( $post, $_product ); ?>
<a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, \'shop_catalog\'); else echo \'<img src="\'.woocommerce_placeholder_img_src().\'" alt="Placeholder" />\'; ?>
<h3><?php the_title(); ?> <span class="price"><?php echo $_product->get_price_html(); ?></span></h3>
</a>
</li><?php endwhile; ?><!-- the large 1 --><?php
$args = array( \'post_type\' => \'product\', \'posts_per_page\' => 1, \'offset\' => 3, \'meta_query\' => array( array(\'key\' => \'_visibility\',\'value\' => array(\'catalog\', \'visible\'),\'compare\' => \'IN\'),array(\'key\' => \'_featured\',\'value\' => \'yes\')) );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
if ( function_exists( \'get_product\' ) ) {
$_product = get_product( $loop->post->ID );
} else {
$_product = new WC_Product( $loop->post->ID );
}
?><li class="featured">
<?php //woocommerce_show_product_sale_flash( $post, $_product ); ?>
<a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, \'shop_single\'); else echo \'<img src="\'.woocommerce_placeholder_img_src().\'" alt="Placeholder" />\'; ?>
<h3><?php the_title(); ?> <span class="price"><?php echo $_product->get_price_html(); ?></span></h3>
</a>
</li><?php endwhile; ?><!-- the last 3 --><?php
$args = array( \'post_type\' => \'product\', \'posts_per_page\' => 3, \'offset\' => 4, \'meta_query\' => array( array(\'key\' => \'_visibility\',\'value\' => array(\'catalog\', \'visible\'),\'compare\' => \'IN\'),array(\'key\' => \'_featured\',\'value\' => \'yes\')) );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); $_product;
if ( function_exists( \'get_product\' ) ) {
$_product = get_product( $loop->post->ID );
} else {
$_product = new WC_Product( $loop->post->ID );
}
?><li class="featured">
<?php //woocommerce_show_product_sale_flash( $post, $_product ); ?>
<a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, \'shop_catalog\'); else echo \'<img src="\'.woocommerce_placeholder_img_src().\'" alt="Placeholder" />\'; ?>
<h3><?php the_title(); ?> <span class="price"><?php echo $_product->get_price_html(); ?></span></h3>
</a>
</li><?php endwhile; ?>
</ul>
<?php } ?>
我了解了如何获取上次运行的SQL查询,它返回为:SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts
INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
INNER JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id )
WHERE 1=1
AND (
( wp_postmeta.meta_key = \'_visibility\' AND wp_postmeta.meta_value IN (\'catalog\',\'visible\') )
AND ( mt1.meta_key = \'_featured\' AND mt1.meta_value = \'yes\' ) )
AND wp_posts.post_type = \'product\' AND (wp_posts.post_status = \'publish\' OR wp_posts.post_status = \'private\')
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0, 3
果不其然,如果我在phpMyAdmin中运行它,我会得到一个ermpty结果集。为什么会突然发生这种情况?几周前,我们确实升级到了WooCommerce 3.0.5,所以我想知道是否内部有什么变化需要更新?Update: 再深入一点,我发现这似乎并没有设定好:
( mt1.meta_key = \'_featured\' AND mt1.meta_value = \'yes\' ) )
他们在WooCommerce管理区显示为“特色”:WooCommerce如何决定一篇文章是否具有特色?我对上述代码的理解是,它正在做:wp_postmeta.meta_key = "_featured"
AND
wp_postmeta.meta_value = "yes"
。。。但这不可能是正确的,因为wp_postmeta
表偶数匹配%featured%
!UPDATE 3: 按照建议,我在WP中打开了调试,现在我在主页上看到了这一点:
Notice: Undefined index: woo_enable_lightbox in /home/costumes/web/thecostumerooms.co.uk/public_html/test/wp-content/themes/artificer/includes/theme-woocommerce.php on line 274
Notice: Undefined index: woo_shop_archives_fullwidth in /home/costumes/web/thecostumerooms.co.uk/public_html/test/wp-content/themes/artificer/includes/theme-woocommerce.php on line 91
class="home blog logged-in admin-bar no-customize-support gecko alt-style-default two-col-left ">
Notice: Undefined index: woo_display_store_info in /home/costumes/web/thecostumerooms.co.uk/public_html/test/wp-content/themes/artificer/index.php on line 141
Notice: Undefined index: woo_display_store_info in /home/costumes/web/thecostumerooms.co.uk/public_html/test/wp-content/themes/artificer/index.php on line 144
Notice: Undefined index: woo_display_store_info in /home/costumes/web/thecostumerooms.co.uk/public_html/test/wp-content/themes/artificer/index.php on line 167
这是最新WP的普通安装,以及Artificer和WooCommerce(3.0.5)