Home › Forums › Themes Support › How to create WordPress Custom Post type and display template
Tagged: shortcode, custom posttype
- This topic has 2 replies, 2 voices, and was last updated 4 years, 2 months ago by
admin.
-
AuthorPosts
-
August 16, 2018 at 1:14 am #1690
Hi all our customer,
In this tutorial we’ll help you create new custom post type in our theme and display it in new template.
1. Create new Custom Post type
- Step 1: go to path {yourwebroot}/wp-content/plugins/haru-xxx-core/includes/posttypes then create new posttype by duplicate testimonial.php file. You can change name to post type name you want to create. (Example: actor.php)
More details to understand the code you can read here: https://codex.wordpress.org/Function_Reference/register_post_type
- Step 2: Open file _init.php in this posttypes folder and add the code like this:
You will have new Posttype named is Actor
2. Display Custom Posttype
You need to know about WordPress template structure from here: https://wphierarchy.com/
2.1. Display Archive page:
You can skip this step if use default template from archive for blog page.
- Step 1: go to path {yourwebroot}/wp-content/theme/xxx/(XXX is our theme folder) and duplicate archive-haru_video.php and change haru_video to your posttype name (Example: archive-haru_actor.php). Also please change code in this file (archive-haru-video to archive-haru-actor)
- Step 2: go to path {yourwebroot}/wp-content/theme/xxx/templates/ and duplicate archive-haru-video.php to archive-haru-actor.php
(All variable in this template to set layout used in Theme Options so you can read file {yourwebroot}/wp-content/theme/xxx/framework/includes/theme-options.php
- Step 3: {yourwebroot}/wp-content/theme/xxx/templates/archive/ then duplicate content-haru-video.php to content-haru-actor.php to display your content.
2.2. Display Single page:
- Step 1: go to path {yourwebroot}/wp-content/theme/xxx/(XXX is our theme folder) and duplicate single-haru_video.php and change haru_video to your posttype name (Example: single-haru_actor.php). Also please change code in this file (single-haru-video to single-haru-actor)
- Step 2: go to path {yourwebroot}/wp-content/theme/xxx/templates/ and duplicate single-haru-video.php to single-haru-actor.php
- Step 3: {yourwebroot}/wp-content/theme/xxx/templates/single/ then duplicate content-haru-video.php to content-haru-actor.php to display your content.
Above is step to step to create new custom posttype and display them in our theme. More details you need is read and understand about the code.
Reference topic to help you add custom meta to posttype in our theme: https://harutheme.com/forums/topic/add-new-metabox-circle-single-video-film-actor-director/
Hope this help you all to customize theme to fit your work!
******
Best regards,
HaruTheme
January 26, 2019 at 9:26 pm #2710Hi, in my old theme I have this shortcode for display the post with a particular tag like an actor:
Película
[display-posts category="película" tag="park-shi-hoo" posts_per_page="100"]
Serie
[display-posts category="serie" tag="park-shi-hoo" posts_per_page="100"]
and the result is:
Película
– After Love
– Confession of MurderSerie
– Babel
– Lovely Horribly
– My Golden Life
– Local Hero
– Cheongdamdong Alice
– The Princess’ Man
– Queen of Reversals
– Family’s Honor
– Iljimae
– Delightful Girl Choon HyangI have the Haru Theme (Circle), is there any way I can do this with the directors and actors in this theme.
Best regards,
Dalia
January 27, 2019 at 1:31 pm #2712Hi,
Thanks for contacting us and choosing our product!
In this case you can use child theme add new style for shortcode actor to display it.
– Add new style for shortcode actor in wp-content/plugins/haru-formota-core/shortcodes/posttypes/actor/ then open file actor.php
– Add new style for actor like this: (on line 102):array( 'param_name' => 'layout_type', 'type' => 'dropdown', 'heading' => esc_html__( 'Layout Style', 'haru-formota' ), 'edit_field_class' => 'vc_col-sm-6 vc_column vc_column-with-padding', 'admin_label' => true, 'value' => array( esc_html__( 'Grid', 'haru-formota' ) => 'grid', esc_html__( 'Masonry', 'haru-formota' ) => 'masonry', esc_html__( 'List', 'haru-formota' ) => 'list', ), ),
(add List style)
– Add new template to display actor with list style (has been added): http://prntscr.com/mct8ta
– You also can follow this topic tutorial to add new template style:
Hope this help!******
Regards,
HaruTheme-
This reply was modified 4 years, 2 months ago by
admin.
-
AuthorPosts
You must be logged in to reply to this topic.