doutiaoku4495 2016-11-11 17:08
浏览 33

什么决定Wordpress何时加载存档模板或页面模板?

I am rewriting the URLs for a custom post type.

// Add rewrite rule
function custom_rewrite_basic() {
  add_rewrite_rule(
            '^movies/([^/]*)/([^/]*)/?',
            'index.php?post_type=movies&movie_id=$matches[1]',
            'top'
        );
}
add_action('init', 'custom_rewrite_basic');

Full code available in this thread regarding another issue: WordPress - request post by url with custom field value

However the above code only sends me to the archive.php page.

URL example: example.com/movies/157336/ The ID is a custom field, and not the actual post ID.

When I rewrite the URL to index.php?post_type=movies&movie_id=$matches[1]&name=$matches[2] then wordpress loads the single.php

Yes I have read through https://developer.wordpress.org/themes/basics/template-files/ and https://developer.wordpress.org/themes/basics/template-hierarchy/ however it does not mention anything about what is required to request the single.php or archive.php page.

From trial and error it seems when the GET parameters p or name are available, then WordPress loads the single.php, otherwise it loads archive.php

I want wordpress to load the single.php or in this case single-movies.php and not archive.php How can I tell wordpress to do that?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)