简体   繁体   English

使用 wordpress 中的增强自定义类别插件在每个类别页脚中添加不同的文本字段

[英]Adding different text fields in each category footer using enhanced custom categories plugin in wordpress

I have been trying for hours to display an advanced custom field in the footer area in order to change the category text according to each category.我已经尝试了几个小时在页脚区域显示一个高级自定义字段,以便根据每个类别更改类别文本。 As soon as I leave the scope of the content-ecp.php file, the category ID changes.一旦我离开 content-ecp.php 文件的 scope,类别 ID 就会更改。

When using the $product_cat_id in the_field('content_under_products', $product_cat_id);?> to retrieve the field data..当使用the_field('content_under_products', $product_cat_id);?> $product_cat_id的 $product_cat_id 来检索字段数据时..

I don't get the correct ID where the field content is stored.我没有得到存储字段内容的正确 ID。 The correct ID would be (1034) but I am getting (108).正确的 ID 是(1034),但我得到的是(108)。 I know, I could change the code to the_field('content_under_products', 1034);?> but this would only work for one specific page which wouldn't make much sense side-wide.我知道,我可以将代码更改为the_field('content_under_products', 1034);?>但这仅适用于一个特定页面,这在横向范围内没有多大意义。

There must be a way to select the other ID.必须有办法 select 其他ID。 Unfortunately, my knowledge of php is very little.不幸的是,我对 php 的了解很少。 So I didn't manage to come up with a proper solution with a dynamic post ID.所以我没能想出一个带有动态帖子 ID 的适当解决方案。

I would be extremely glad if anyone could help me out with this.如果有人能帮我解决这个问题,我会非常高兴。

Here is a link to the page: https://praesenteente.de/geldgeschenke/ I basically consists of:这是该页面的链接: https://praesenteente.de/geldgeschenke/我基本上包括:

CATEGORY HEADER AND DESCRIPTION (here, the field can be displayed correctly) CATEGORY HEADER AND DESCRIPTION(这里可以正确显示字段)

WOOCOMMERCE PRODUCTS WOOCOMMERCE产品

FOOTER (here, it doesn't show up) FOOTER(这里,它不显示)

It sounds like you only have access to your $product_cat_id inside the content-ecp.php file.听起来您只能访问 content-ecp.php 文件中的 $product_cat_id 。

I think there is a logic issue you should check: The content-pages are for single views, so when there is an id for a single post/page and you want to have them look the same for all single posts.我认为您应该检查一个逻辑问题:内容页面适用于单个视图,因此当单个帖子/页面有一个 id 并且您希望它们对于所有单个帖子看起来都相同时。

An archive page is viewing a collection of posts.存档页面正在查看帖子的集合。 The name of your variable PRODUCT_cat_id using not the plural of products, lets me assume you are setting the value of the variable like this:您的变量 PRODUCT_cat_id 的名称不使用产品的复数,让我假设您正在设置变量的值,如下所示:

$product_cat_id = get_the_ID();

So the id of the current viewed post is saved to the variable.所以当前查看的帖子的id被保存到变量中。 This is working fine in a single page, but not in archives.这在单个页面中运行良好,但在档案中却不行。

When you are viewing a category, you have an id for the term you are viewing.当您查看一个类别时,您有一个您正在查看的术语的 ID。 For example the category is called "category" and you are now viewing "shoes", which is a category term.例如,类别称为“类别”,您现在正在查看“鞋子”,这是一个类别术语。 You can get the id of the term of the current viewing category term page by using:您可以使用以下方法获取当前查看类别术语页面的术语ID:

$cat_term_id = get_queried_object()->term_id;

Now you have saved the id of the category term.现在您已经保存了类别术语的 id。 With this id you can now get your category description text, which is a meta field in your category term.有了这个 id,您现在可以获得您的类别描述文本,这是您类别术语中的一个元字段。

$cat_description = get_field('content_under_products', $cat_term_id );

This is working, if your 'content_under_products' field is an field added with acf to categories.如果您的“content_under_products”字段是使用 acf 添加到类别的字段,则此方法有效。 I think this is what you are looking for.我想这就是你要找的。

If I got your question wrong and you just want to show the description for the archive itself (and not for the terms of the category / taxonomy), you can just use:如果我的问题错了,而您只想显示档案本身的描述(而不是类别/分类的术语),您可以使用:

$archive_description = get_the_archive_description();

https://developer.wordpress.org/reference/functions/the_archive_description/ https://developer.wordpress.org/reference/functions/the_archive_description/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM