2

I have been developing a one page WordPress personal portfolio theme for Themeforest submission.

I have some sections in the front page which is my main page for this one page theme. The sections are:

  1. Service Section

  2. Portfolio Section

  3. Testimonial Section

  4. Team Section etc. etc.

And most of them are populated by custom post type.

Now my queries are:

  1. Is it mandatory to create single post page for each of the custom post types?

  2. If not, then what about the ‘href’ attribute value(where we write this code the_permalink()) of the anchor tag ()? Should I keep it dead like href=”#”?

  3. Is it mandatory to design Section Page, Portfolio Page etc. which are created by custom page templates?

  4. Is it mandatory to keep ‘has_archive’ => true in the custom post register?

N. B. This is a onepage personal portfolio WordPress theme.

Thanks in advance.

  • I hope you will consider putting the custom post type functions in one or more plugins bundled with your theme so the content is more portable and less tied to the theme. – Dan Knauss Mar 21 '17 at 19:29
  • 1
    Thanks much @Dan Knauss :) . Yeees! I did it. Thanks again for your hearty recommendation. – Mohammad Shohel Rana Mar 22 '17 at 13:54
5

Is it mandatory to create single post page for each of the custom post types? No not all all. If you add 'publicly_queryable' => false; the system won't create single page entries for your cpts. (make sure to flush permalinks after this change)

If not, then what about the ‘href’ attribute value(where we write this code the_permalink()) of the anchor tag ()? Should I keep it dead like href=”#”? with the publicly_queryable arg set to false, this will just load to the homepage

Is it mandatory to design Section Page, Portfolio Page etc. which are created by custom page templates? no its not. in fact if you set ‘has_archive’ => false; those pages won't load either and if someone were to try to go to those archive pages "www.example.com/your_cpt" it will also load to the home page. (remember to flush permalinks after you make this change)

Is it mandatory to keep ‘has_archive’ => true in the custom post register? no. see the above questions answer.

To flush your permalinks. go to your dashboard and then settings/permalinks and hit save.

Alternately, you can add this into your plugin. This call should only be done as part of initialization though because it does use a lot of resources. This is how you would do it:

function my_rewrite_flush() {
    // First, we "add" the custom post type via the above written function.
    // Note: "add" is written with quotes, as CPTs don't get added to the DB,
    // They are only referenced in the post_type column with a post entry, 
    // when you add a post of this CPT.
    my_cpt_init();

    // ATTENTION: This is *only* done during plugin activation hook in this example!
    // You should *NEVER EVER* do this on every page load!!
    flush_rewrite_rules();
}

register_activation_hook( __FILE__, 'my_rewrite_flush' );

Much more information here too: https://codex.wordpress.org/Function_Reference/register_post_type

  • Thank you so much, @rudtek :) . Your answers are very helpful and meet my needs. If you don't get bothered, I would like to know how to flush permalink. Thanks again. – Mohammad Shohel Rana Mar 18 '17 at 1:24
  • added that to the bottom of my answer for you. – rudtek Mar 18 '17 at 3:50

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.