目前的解决方案是:创建一个插件,用当前页面段塞重新创建短代码。将页面slug命名为类别slug。并手动将类别添加到dflip。
目前还找不到更好的。
// Disable direct access
defined(\'ABSPATH\') or die(\'No script kiddies please!\');
// use page slug to call dflip book in same slug dflip_category
add_shortcode(\'dflip_book_slug\', \'shortcode_dflip_book_slug\');
function shortcode_dflip_book_slug($atts = array(), $content = \'\', $tag)
{
global $post;
// default parameters (but filtered, only declared ones are passed)
// $atts = shortcode_atts(array(
// \'books\' => $post->post_name
// ), $atts, $tag);
$atts = is_array($atts) ? $atts : array();
if (array_key_exists(\'books\', $atts)) {
$atts[\'books\'] = str_replace(\'%slug%\', $post->post_name, $atts[\'books\']);
} else {
// par défaut on passe le slug
$atts[\'books\'] = $post->post_name;
}
$atts_str = array();
foreach ($atts as $key => $value) {
$atts_str[] = $key . \'="\' . str_replace(\'"\', \'\\"\', $value) . \'"\';
}
$shortcode = \'[dflip \' . implode(\' \', $atts_str) . \']\' . $content . \'[/dflip]\';
return do_shortcode($shortcode);
}