wordpress 如何将子页面添加到自定义帖子类型“帖子”

uelo1irk  于 2023-01-04  发布在  WordPress
关注(0)|答案(1)|浏览(146)

朋友们,你们好。
我有一个问题,我正在寻找答案2天了。我想我已经检查了所有10个第一谷歌网页的20个不同的要求。所以,这是它。
I have a custom post type named "Footballer". I have created 2 "Posts" of that CPT, which are "Messi" and "Ronaldo". My permalinks for these 2 footballers are "mysite.com/footballer/messi/" and "mysite.com/footballer/ronaldo/". It is OK for me.
Now, I want to add a child page "about" (or "stats", or anything) to my footballers and I want this page to be available by the link "mysite.com/footballer/messi/about" (just add the child page slug after the cpt post link). Obviously, I want to create a single page "about", not one for every footballer I have, and in this page I would retrieve data for the specific footballer (by functions/shortcodes).
Nota: the cpt and values in this post are fictionnals, I know I would display the about/stats directly in the footballer cpt post. I am just trying to explain what I need -> a generic child page for a cpt, available by "mysite.com/cpt/cptpost/childpage".
我怎么能这么做?这有可能吗?
谢谢你的帮助。

    • 编辑;**

由于Divi不允许,我可以重写我的子页面的网址吗?如果我的子页面网址是"mysite/subpage/?foot = messi",我可以将其显示为"mysite/footballer/messi/subpage"吗?
我试过这个密码,没有成功

function my_rewrite_url() {

    add_rewrite_tag( '%foot%','([^&]+)' );
    
    add_rewrite_rule(
      'footballer/([^/]+)/subpage',
      'index.php?pagename=subpage&foot=$matches[1]',
      'top'
    );
}
add_action( 'init', 'my_rewrite_url' );
jchrr9hc

jchrr9hc1#

您正在查找自定义帖子类型的自定义分类。

相关问题