如何将变量设为 do_shortcode 值?我想更改短代码值,如 (category="others") 怎么可能?

How will make variable to do_shortcode value? i want to change shortcode value like (category="others") how it possible?

我想为这些红色方块部分制作变量 (screenshot).

PHP代码:

echo do_shortcode('[product_category category="others" per_page="12" columns="4"]');

您可以直接在 PHP 中的 "" 分隔字符串中插入变量值。

$cat = "some_category";
$per = 20; // some number
$col = 10; // some number

echo do_shortcode("[product_category category=\"$cat\" per_page=\"$per\" columns=\"$col\"]");

如果您仍想使用 '' 分隔字符串,则需要将值附加在一起。

echo do_shortcode('[product_category category="' . $cat . '" per_page="' . $per . '" columns="' . $col . '"]');