有时,通常出现在我们主页上的“特色”图片已经停止显示。
我做了一些挖掘,在索引中找到了这个模板代码。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)
最合适的回答,由SO网友:Christina 整理而成
这些是WooCommerce 3。仅x说明
GitHub上的线程(
https://github.com/woocommerce/woocommerce/issues/14914#issuecomment-299714488) 由一位Woo开发人员更新,他提供了一个循环示例,并解释了发生的情况:
Featured是2.6中的meta,但它是一种分类法(为了性能!)在3.0中,请相应地调整查询以使用tax\\u查询而不是meta\\u查询。
要通过WooThemes将新参数应用于Artificer主题(可惜他们没有更新主题),请执行以下操作:
对于非开发人员:
使用FTP登录主机。有很多ftp客户端应用程序,在Google中键入“ftp客户端”,不加引号。然后为您的操作系统选择一个。使用购买主机时获得的凭据登录。通常,这些与您的cPanel登录用户名和密码相同。您将进入
ftp.yourdomain.com
. 你将进入你的
public_html
目录然后找到您的
wp_content
目录中,您将看到更多子目录,其中之一是
themes
在里面你会看到目录名
artificer
. 作为主页的文件是
index.php. 这是您与本要点中的文件交换的文件。
https://gist.github.com/carasmo/03cbbd2f70c30d0649de4ada7095a3dd
单击“raw”按钮,然后保存(到您在计算机上为此创建的目录)作为索引。php。除非有代码编辑器,否则不要打开它。然后将其从计算机拖动到/wp-content/themes/artificer目录。
对于开发人员:
替换循环$参数所在的两个位置:
loop 1 for three images:
$args = array(
\'post_type\' => \'product\',
\'posts_per_page\' => 3,
\'tax_query\' => array(
array(
\'taxonomy\' => \'product_visibility\',
\'field\' => \'name\',
\'terms\' => \'featured\',
),
),
);
loop 2 for the single image $args = array(
\'post_type\' => \'product\',
\'posts_per_page\' => 1,
\'offset\' => 3,
\'tax_query\' => array(
array(
\'taxonomy\' => \'product_visibility\',
\'field\' => \'name\',
\'terms\' => \'featured\',
),
),
);