admin管理员组

文章数量:1323150

I'm trying to create a page called "Comics" with the slug "comics" to use as the main table of contents for my webcomic site. I've created a page-comics.php file, however when I go to the page it just links back to index.php. It also doesn't work when I try using the ID instead. When I try using this same format with other slugs and IDs it works fine, so I know WordPress is working correctly. I thought it might be conflicting with something I had in functions.php, however nothing else was using the name "comics" (I've linked to the file below for anyone to view). I also tried scrubbing the database for any deleted items that might have been using that slug and got nothing. Does anyone know what could be causing this issue?

My functions.php file:

I'm trying to create a page called "Comics" with the slug "comics" to use as the main table of contents for my webcomic site. I've created a page-comics.php file, however when I go to the page it just links back to index.php. It also doesn't work when I try using the ID instead. When I try using this same format with other slugs and IDs it works fine, so I know WordPress is working correctly. I thought it might be conflicting with something I had in functions.php, however nothing else was using the name "comics" (I've linked to the file below for anyone to view). I also tried scrubbing the database for any deleted items that might have been using that slug and got nothing. Does anyone know what could be causing this issue?

My functions.php file: https://drive.google/file/d/1c1zZsW5xu9bTukEHllsoPS4KyDlfXQS8/view?usp=sharing

Share Improve this question asked Sep 1, 2020 at 14:31 ZackAkaiZackAkai 434 bronze badges 1
  • 1 Can you include your code in your question? Links offsite break and this question makes no sense without the google drive link – Tom J Nowell Commented Sep 1, 2020 at 15:43
Add a comment  | 

1 Answer 1

Reset to default 1

I thought it might be conflicting with something I had in functions.php, however nothing else was using the name "comics"

There is, here:

// Arguments
$args = array(
    'labels' => $labels,
    'public' => true,
    'menu_icon' => 'dashicons-book-alt',
    'hierarchical' => true,
    'exclude_from_search' => false,
    'has_archive' => true,
    'publicly_queryable' => true,
    'rewrite' => array( 'slug' => 'comics', 'with_front' => false ), // <-- Here
    'supports' => array( 'title', 'page-attributes' ),
);

// Register Comic Pages Post Type
register_post_type('comic-page', $args);

So you have a post type with the slug comics, which has has_archive set to true, meaning that the URL /comics is being used to display the archive of the comic-page post type. If you want to customise the template for this archive you should create an archive-comic-page.php file, as per the template hierarchy.

If for some reason you don't want this archive, you can set has_archive to false to disable it, freeing you up to use /comics for a page.

本文标签: pageslugphp not working but only for specific slug