categories - Archieve.php not loading for custom post type

admin2025-06-03  3

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).

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748912380a314755.html

最新回复(0)