如何在自定义Gutenberg块或短代码中重复使用页面查询?

发布于 2025-02-03 07:56:12 字数 536 浏览 5 评论 0原文

我想解决这个问题,但不确定是否有可能...

说我有一个页面上显示一些术语的页面,所以我开始检索它们:

  $children_terms = get_terms(array(
    'taxonomy' => $taxonomy_name,
    'hide_empty' => false,
    'parent' => $related_product_term->term_id
  ));

很棒。然后,我启动post_content Output,即普通的Gutenberg块。

在Gutenberg的页面内容中间,我需要再次显示上述术语,例如带有拇指和标题的卡片。我可以通过短代码或自定义块进行操作,但是问题在于,在这一点上,我将重复上述查询,这是我在页面模板中已经进行的。

有没有一种方法可以简单地在自定义块或短代码上重复使用$ childris_terms

或者,甚至更不可能:有没有办法将Gutenberg输出分为2件,以便我可以在中间放置标准的“手动”代码?

I'd like to solve this problem, but not sure if it's even possible...

Say I've got a page which on header shows some terms, so I start retrieving them:

  $children_terms = get_terms(array(
    'taxonomy' => $taxonomy_name,
    'hide_empty' => false,
    'parent' => $related_product_term->term_id
  ));

Great. Then I start post_content output, which is plain gutenberg blocks.

In the middle of the page contents from gutenberg, I would need to show again the above terms, like cards with thumb and title. I can do it via shortcode or custom block, but the problem is that at this point, I'm going to repeat the above query, which I already did in page template.

Is there a way to simply reuse $children_terms on the custom block or shortcode?

Or, even more impossible: is there a way to split gutenberg output in 2 pieces, so that I can place standard 'manual' code in the middle?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

耶耶耶 2025-02-10 07:56:12

我找不到通过页面的任何方法($ childres_terms,请参见上文)变量到Gutenberg的短代码。但是我用“空”解决(我的意思是:没有自定义字段)ACF块,并通过set_query_var(wordpress api函数)从页面模板中传递$ childres_terms

I didn't find any way to pass page ($children_terms, see above) variables to a shortcode from gutenberg. But I solved with an 'empty' (where I mean: with no custom fields) acf block and passing $children_terms from the page template with set_query_var, a wordpress api function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文