0

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.com/mkhczg

Kindly advise on this.

Thank you very much for the all the advise given,

  • Please conform you pass "has_archive = true;" this parameter or not ? when you create post type. – Jignesh Patel Feb 13 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 Feb 13 at 11:27
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).

  • Hey, thanks for the article, it makes sense now, once again, really appreciate it – desh Feb 13 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.