通过一系列特定要求,我发现自己需要使用其术语ID链接到自定义分类法类别...
我有这个 - 它显示了所有分类法的链接 - 我希望改变它,所以它只显示分类法的链接,术语id从我正在使用的自定义字段中动态拉出.
$taxonomy = 'event-categories';
$terms = get_terms($taxonomy);
if ($terms) {
foreach($terms as $term) {
echo '<li><a href="http:/mysite.com/events/categories/project-events/' . $term->slug . '">' . $term->name .'</a></li>';
}
};
Run Code Online (Sandbox Code Playgroud)
essentiall我需要"link_to_taxonomy_category(x)",其中x = term_id
谢谢
我需要编写wp_list_categories自定义函数等等,而不是显示链接的分级列表,他们是不是与父词条被显示为H3标签复选框列表.
最终的输出看起来像http://jsfiddle.net/amesy/kwqpf5fv/6/
这是我的WordPress模板文件中的PHP代码...
<?php
//list terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin)
$taxonomy = 'tags';
$orderby = 'name';
$show_count = 1; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => …Run Code Online (Sandbox Code Playgroud) 我试图从 WooCommerce 产品页面上的显示中排除某些类别。
示例:如果在单个产品页面中我有“类别:Cat1,Cat”2”,我希望只显示 Cat1。
我尝试在单品模板中编辑meta.php。我创建了一个新函数:
$categories = $product->get_category_ids();
$categoriesToRemove = array(53,76,77,78); // my ids to exclude
foreach ( $categoriesToRemove as $categoryKey => $category) {
if (($key = array_search($category, $categories)) !== false) {
unset($categories[$key]);
}
}
$categoriesNeeded = $categories;
Run Code Online (Sandbox Code Playgroud)
然后我收到了来自 WooCommerce 的回声:
echo wc_get_product_category_list( $product->get_id(), ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', count($categories), 'woocommerce' ) . ' ', '</span>' );
Run Code Online (Sandbox Code Playgroud)
但它仍然显示相同的类别。奇怪的是,当我做一个var_dump($categories)它显示正确的事情。
我正在尝试修改class-wc-breadcrumb.php以自定义产品页面面包屑中的产品类别链接。
该文件位于: wp-content/plugins/woocommerce/includes
我试图将我的子主题中的这个文件复制并编辑为:
wp-content/themes/Divi-child/woocommerce/includes/lass-wc-breadcrumb.php
但它不起作用。
如何通过我的子主题自定义 Woocommerce 中的产品类别面包屑链接?
通过Woocommerce,我正在尝试使用产品类别"Apple"为产品变体发布类型的WP_Query.
$args = array(
'product_cat' => 'Apple',
'post_type' => array('product', 'product_variation'),
'post_status' => 'publish',
'key' => '_visibility',
'value' => 'visible',
'posts_per_page' => 100,
'taxonomy' => 'pa_size',
'meta_value' => '39',
'meta_query' => array(
array(
'key' => '_stock',
'value' => 0,
'compare' => '>'
)
)
);
Run Code Online (Sandbox Code Playgroud)
但我无法在此查询中使用它.如果我删除'product_cat' => 'Apple',查询工作.为什么?
我想确定产品是否具有属性。例如:
if (product has attribute 'pa_color')
{
//do something
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做?
我一直在使用WooCommerce Codex,但似乎无法显示数据。我只想显示产品类别和说明,以便在自己的自定义布局中显示在单个产品页面上,如下所示。
<?php global $product; echo $product->get_attributes; ?>
<?php global $product; echo $product->get_short_description; ?>
Run Code Online (Sandbox Code Playgroud) 我正在制作我的第一个主题,感谢 The Loop 和 WooCommerce SDK 提供的所有帮助,一切都进展得非常快。然后今天我花了一整天的时间,没有做一些像显示图像这样简单的事情......经过一整天的努力,我唯一学到的是 WP 似乎没有提供获取类别图像的方法,而且很多人都有问这个问题很多年了,但我仍然找不到真正做到这一点的方法......:(
我想要做的是在我的商店上方创建一个滑块,显示精选商店类别的图像。我希望能够输入术语名称列表,并基于此我的函数应以类别图像的形式生成指向产品类别的链接。
听起来很简单...事实证明,它远非简单...在您将其标记为重复问题之前,让我解释一下为什么我要问它...
我发现的一些解决方案要求我知道术语的 ID,而不是术语名称。有人说“使用自定义术语搜索获取 ID”,但没有解释如何操作。我知道如何对帖子进行基于自定义分类的查询,但不知道如何对术语进行查询。该文档让我对传递给查询项的值感到困惑:(
其他解决方案要求我首先找到特定类别的产品,然后从那里向后查找产品的类别图像(???)
当然,人们喜欢对所有事情给出默认答案:“哦,你正在设计自己的主题并想要显示类别图标?很简单,只需下载一个插件即可为你做到这一点”。现在为什么我没有想到将其他人的插件包含到我的主题中?(捂脸)
其他答案只是显示如何打印术语名称列表,但到目前为止,没有什么能够让我做应该像这样简单的事情:
$categories = array("software", "plugins", "merch");
foreach($categories as $cat) {
$term_id = get_term_id($cat);
$term_image = get_term_featured_image($term_id);
echo '<img src="'.$term_image.'">;
}
Run Code Online (Sandbox Code Playgroud)
获取术语的第一个问题是,获取术语 id 的 wordpress 函数仅适用于类别分类法,但我需要查询 WooCommerce 的 Product_cat 分类法。其次,即使您有 ID,似乎也没有获取缩略图/特色图像的选项。那么现在怎么办?
因此,我进入低级别并开始直接使用 $wpdb 查询表,我确定我要查找的术语有 term_id 94。我在 termmeta 表中查询缩略图的帖子 ID,发现它是 905。现在我转向我的帖子表并发现....没有帖子条目905!搞什么?因此,我对另外两个类别进行了此操作,并发现了相同的内容。查找图像的 id 会导致尝试提取帖子附件时不会返回任何内容,因为没有帖子与图像的 id 匹配...
为什么这这么难?WordPress 让其他一切变得如此简单,但这个听起来简单的任务似乎几乎不可能完成......所以现在你看到我已经在谷歌上搜索到这个并且已经在我的背部挣扎,我出于绝望而问这个问题:
如何获取 Product_cat 术语名称数组并将其转换为 url 数组以显示类别的图像?
谢谢
我的自定义分类法(WooCommerce属性)已经存在,并且我正在使用以下内容为分类法添加新术语并将其与我的WooCommerce产品相关联:
wp_set_object_terms($product_id, array($omega_jahr), 'pa_years-of-construction');
Run Code Online (Sandbox Code Playgroud)
当我使用以下命令为产品调用“ pa_years_of_construction”时,可以看到新条款已保存:
$v = array_values( wc_get_product_terms( $product->id, 'pa_years-of-construction', array( 'fields' => 'names' ) ) );
Run Code Online (Sandbox Code Playgroud)
但是,当我在网站的后台和前端检查产品属性时,“ pa_years_of_construction”属性未显示。
我在这里想念什么?
在此先感谢您的帮助!
我在我的网站中添加了分页代码(https://www.wpblog.com/use-wp_query-to-create-pagination/)。这段代码在我的页面模板中运行良好。但是,当我在自定义分类模板中执行相同的编码时,它无法从第 2 页开始工作。它会转到错误页面。请帮忙。
此处为taxonomy-somename.php 的代码
<?php
/**
* The template for displaying archive pages.
*
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
* @package Sydney
*/
get_header();
?>
<div id="primary" class="content-area col-md-9">
<main id="main" class="post-wrap" role="main">
<ul id="service-list">
<?php
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$paged = (get_query_var( 'page' )) ? get_query_var( 'page' ) : 1;
$aud_query = new WP_Query(
array(
'post_type' => 'attachment',
'post_status' => 'inherit',
//'post_mime_type' => 'image',
'post_mime_type' => 'audio',
'posts_per_page' => …Run Code Online (Sandbox Code Playgroud) custom-taxonomy ×10
php ×9
wordpress ×9
woocommerce ×7
product ×5
breadcrumbs ×1
checkbox ×1
filtering ×1
pagination ×1
thumbnails ×1
variations ×1