$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>categories - Archieve.php not loading for custom post type|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

categories - Archieve.php not loading for custom post type

matteradmin9PV0评论

I have a post with a category of blog .

So i came across with this archieve.php , whereby we can edit the layout and content of a custom post type.

From what I understand archieve.php contains the post meta details of a posts such as category, tags and so on. Please correct me if i am wrong.

However, right now what is affecting the custom post type is a file called single.php

From what I have researched, they told me to go to Settings -> Permalinks and choose Post name

However i have choose that option and it still doesn't work

archive.php

<?php get_header();?>
<h2>Welcome to archieve</h2> //This is not loading in the post page
    <div class="container pt-5 pb-5 ">
        <h1>right now</h1>
        <h1>
            <?php 
                single_cat_title();
                if( have_posts() ) {
                    while( have_posts() ) {
                    the_post();
                    }
                  }
            ?>
            <p></p>
        </h1>
    </div>
<?php get_footer();?>

single.php

<?php get_header();?>
<h2>Welcome to single</h2> // This is loading in the post page
    <div class="container pt-5 pb-5 ">
        <h1>
            <?php 
                if( have_posts() ) {
                    while( have_posts() ) {
                    the_post();
                      the_content();
                        the_permalink();
                    }
                  }
            ?>
            <p></p>
        </h1>
    </div>
<?php get_footer();?>

Results

Kindly advise on this.

Thank you very much for the all the advise given,

I have a post with a category of blog .

So i came across with this archieve.php , whereby we can edit the layout and content of a custom post type.

From what I understand archieve.php contains the post meta details of a posts such as category, tags and so on. Please correct me if i am wrong.

However, right now what is affecting the custom post type is a file called single.php

From what I have researched, they told me to go to Settings -> Permalinks and choose Post name

However i have choose that option and it still doesn't work

archive.php

<?php get_header();?>
<h2>Welcome to archieve</h2> //This is not loading in the post page
    <div class="container pt-5 pb-5 ">
        <h1>right now</h1>
        <h1>
            <?php 
                single_cat_title();
                if( have_posts() ) {
                    while( have_posts() ) {
                    the_post();
                    }
                  }
            ?>
            <p></p>
        </h1>
    </div>
<?php get_footer();?>

single.php

<?php get_header();?>
<h2>Welcome to single</h2> // This is loading in the post page
    <div class="container pt-5 pb-5 ">
        <h1>
            <?php 
                if( have_posts() ) {
                    while( have_posts() ) {
                    the_post();
                      the_content();
                        the_permalink();
                    }
                  }
            ?>
            <p></p>
        </h1>
    </div>
<?php get_footer();?>

Results http://prntscr/mkhczg

Kindly advise on this.

Thank you very much for the all the advise given,

Share Improve this question edited Feb 13, 2019 at 12:53 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Feb 13, 2019 at 10:37 deshdesh 1372 silver badges10 bronze badges 2
  • Please conform you pass "has_archive = true;" this parameter or not ? when you create post type. – Jignesh Patel Commented Feb 13, 2019 at 10:44
  • I have never used register_post_type(). Sorry I think i should have explained better. Basically i have a post with the category of blog. So what I desire to achieve is to modify the layout of this post with the category of blog by adding some text. Sorry for the confusion caused. – desh Commented Feb 13, 2019 at 11:27
Add a comment  | 

1 Answer 1

Reset to default 2

The single.php template is loaded when you visit a post. The archive.php page is a generic archive template, loaded in case a grouping of posts (a year, a month, a category, a tag, etc.) does not have it's own template.

Please read this about template hierarchy.

If you want to create a custom post template for a specific post_type you have to create a dedicated template and call if single-post_type.php (replace post_type with your post type, i.e. product).

Post a comment

comment list (0)

  1. No comments so far