Archived topic
How to use CPT and Elements Layout Template for Pages, not Posts
5 replies · Started by blackbird on May 24, 2021
Hi I´ve been working with Wordpress for many years but I am still never made any "Custom Post Type". I think it would be great for our big site, but I need advice on how to start working with CPT combined with all the new in GP Elements Layout Templates. And my question is about PAGES, not blog posts. (I have watched your videos about blog posts, but I don´t feel it is as easy with pages that don´t have categories etc you can target so easy..?)
First the most basic: Do I need the plugin "Custom-post-type-UI"? Do I need any other extra plugin? Do I have to make any basic changes to my child theme to start making my own CPT?
This is an example of what I would like to do:
Say I have an About-us-section on our site, with a parent page with a long list of all employees, and when you click on a persons photo you are linked to that persons single page with a video, some text info, some links, a sidebar and so on. All these child pages have the same layout.
If there was only 5 persons/pages, it makes sence to keep them as ordinary static single pages. Right?
But if there was 50 persons/pages looking the same, it must be much better to build them all using Custom Post Type and use a GP Elements Layout Template targeted for those Single Pages. Right? So I easily can make and change the single page design template in only one place now and in the future.
But how do I do this? How do I set it up, step-by-step??
Could/Should my parent About-page with the link-list be a static ordinary page, or how should I build that up from the database-content in my custom post type single pages?
And how do I make a Layout Template that targets only these CPT single pages, and not my other content?
And also:
How can I target a Elements Layout template to a whole section with a lot of pages on my site, for example "Documentation", if that section contains a big MIX of a lot of static single pages, CPT from a download plugin, and also my custom-post-type-pages...? Is it difficult? Can a "mark" all of them somehow, how?
I would love to see a step-by-step video about this subject. About pages, not blog posts.
Hi there,
1. But how do I do this? How do I set it up, step-by-step??
this doc explains the basics of registering a CPT, and then using copies of the GP Theme templates ( in your child theme ) to display them:
https://docs.generatepress.com/article/setting-up-a-simple-custom-post-type/
Best to begin there with a simple post type to see how it works.
We recommend using copies of the themes templates - as this will maintain the themes hooks and importantly the generate_do_template_part functions of the theme which is required if you want to use Block Elements to design your layout.
2. Could/Should my parent About-page with the link-list be a static ordinary page, or how should I build that up from the database-content in my custom post type single pages?
That depends - the simplest method would be to use the archive template ( as in #1 above ) to display your list of Posts. You can of course create a static page but then you would require a way to output the list of 'posts' on that page... which we would use the WP Show Posts plugin for.
3. All CPTs are Post Types - and in an Elements Display Rules, as you would see Posts > All Posts you will see your CTP listed eg. Employees > All Employees assuming your CPT name/slug was Employees.
4. And Also
I am not sure i fully understand - but you mention Elementor ( maybe a typo ) and other plugins... the GPP 2.0 Block Elements only applies to theme templates ( or copies of ) - it won't integrate with content generated by other plugins.
Hi thank you for quick answer.
1. Yes, I´ve seen that page, the description is very short (!), but okey I get the basics:
After I have installed a CPT-plugin I will duplicate two GP PHP-files and put them in my child theme. And if I do a lot of different CPT there will be a lot of copied and differently altered PHP-files in my child theme.
And you are absolutely right, I will have to do this on a test site first and learn how it works. (I was hoping for a quick and easy road...)
2. Aha! An Archive Template, I understand. That must be the best. And I will dig more into how to style that as well.
And I guess that goes into my child theme as well.
3. Ok, good. That sounds easy to find.
4. Sorry, it was a typo, I mean Elements. My question is, if I style a bunch of CPT pages (= posts) to have a special background, and header, and so on. Can I target that same look to pages made by a download plugin? If I want them to look the same. Or do I have to style pages made by other plugins the old usual way with custom CSS?
1. Yeah thats the thing with CPTs - we have to keep the documentation light as its really out of scope and the possibilities are endless - which would have made a very long boring read and still not answered 90% of the things users may require.
2. Yes in the child theme too.
4. Plugins will generate their own HTML and CSS , a lot of which won't be the same as the themes, so you would have to use your own custom CSS to match.
Thank you, now I know how to move forward and where to start with this new big project! :-)
Glad to be of help