Community Forums › Forums › Archived Forums › Design Tips and Tricks › Diplaying Custom Post type
Tagged: custom post types
- This topic has 6 replies, 2 voices, and was last updated 9 years, 6 months ago by
codebot5000.
-
AuthorPosts
-
July 18, 2015 at 2:13 pm #159758
codebot5000
MemberHi, I created a custom post type and published a post here http://www.jeff-cunningham.com/jc_portfolio/first-custom-post/ Now I would like this post to display on a page I created called portfolio. I tried matching the permalink of the portfolio page to the permalink of the custom post above, however it still does not display on the portfolio page.
I have tried looking this up online but no one is clear on how to do this. I followed several articles that told me to match the permalinks and make sure the permalink setting was set to post name which I did.
Any knowledge you could impart would be greatly appreciated.
http://www.jeff-cunningham.comJuly 18, 2015 at 2:19 pm #159761Christoph
MemberHi,
I see the post at http://www.jeff-cunningham.com/jc_portfolio/first-custom-post/
The archive at jeff-cunningham.com/jc_portfolio/ might not be set up right.
Did you set the page template to the archive for your custom post type?
July 18, 2015 at 2:39 pm #159762codebot5000
MemberI did not set up a page template because as soon as I set my has_archive to true my whole page breaks. You will see now that there is an internal sever error as a result of adding this
'has_archive' => true,
Here is the custom post type I'm working with
<?php /* Plugin Name: Custom Post Types Plugin URI: http://www.jeff-cunningham.com/ Description: Here are the custom post types for my website Version: 1.0 Author: Jeff Cunningham Author URI: http://jeff-cunningham.com */ class JC_Portfolio_Post_Type{ public function __construct(){ $this->register_post_type(); $this->taxonomies(); } public function register_post_type(){ $labels = array ( 'name' => 'portfolio Selection', 'singular_name' => 'portfolio', 'add_new' => 'Add New portfolio', 'add_new_item' => 'Add New portfolio', 'edit_item' => 'Edit portfolio', 'new_item' => 'New portfolio', 'all_items' => 'All portfolio', 'view_item' => 'View portfolio', 'search_items' => 'Search All portfolio', 'not_found' => 'Nothing found', 'not_found_in_trash' => 'Nothing found in the Trash', 'parent_item_colon' => '', 'menu_name' => 'portfolio Selection' 'has_archive' => true, ); $args = array ( 'labels' => $labels, 'description' => 'This section holds all portfolio pieces', 'public' => true, 'menu_position' => 6, // 'menu_icon' => get_stylesheet_directory_uri() .'images/movie_art.png' 'supports' => array('title', 'editor') ); register_post_type ('jc_portfolio', $args); } public function taxonomies(){ $taxonomies = array(); $taxonomies['genre'] = array ( 'query_var' => 'movie_var', 'hierachical' => true, 'rewrite' => array ( 'slug' => 'movies/genre'), 'labels' => array ( 'name' => 'Genre', 'singular_name' => 'Genre', 'search_items' => 'Search Genre', 'all_items' => 'All Genre', 'parent_item' => 'Parent Genre', 'parent_item_colon' => 'Parent Genre', 'edit_item' => 'Edit Genre', 'update_item' => 'Update Genre', 'add_new_item' => 'Add New Genre', 'new_item_name' => 'New Genre Name', 'menu_name' => 'Genre' ) ); $taxonomies['studio'] = array ( 'query_var' => 'movie_var', 'hierachical' => true, 'rewrite' => array ( 'slug' => 'movies/studio'), 'labels' => array ( 'name' => 'Studio', 'singular_name' => 'Studio', 'search_items' => 'Search Studio', 'all_items' => 'All Studio', 'parent_item' => 'Parent Studio', 'parent_item_colon' => 'Parent Studio', 'edit_item' => 'Edit Studio', 'update_item' => 'Update Studio', 'add_new_item' => 'Add New Studio', 'new_item_name' => 'New Studio Name', 'menu_name' => 'Studio' ) ); $this->register_all_taxonomies($taxonomies); } public function register_all_taxonomies($taxonomies){ foreach ($taxonomies as $name => $arr) { register_taxonomy ($name, array(dh_movies), $arr); } } } add_action('init', function(){ new JC_Portfolio_Post_Type(); });
July 18, 2015 at 5:15 pm #159782Christoph
MemberHi,
you are missing a comma after 'portfolio Selection':
'menu_name' => 'portfolio Selection' 'has_archive' => true,
July 23, 2015 at 4:26 pm #160247codebot5000
MemberThanks, the page is now working, but I still can't seem to get my custom post type page to display in the nav menu. I have tried the method copied below. The problem is that after I refresh the permalinks I'm not seeing anything display in the menu section that I can drag over.
Displaying Your Post Type on the Front End
Once you’ve added some products, you’ll need to be able to display these on the front end of your site.
Setting Permalinks to Link to Your Post Type’s PagesFirst you need to refresh the permalinks on your site so that WordPress will use the correct links to display products or product archives:
In the WordPress admin, go to Settings -> Permalinks.
Make sure the ‘post name’ option is selected.
Click the Save Changes button.Note: You need to do this even if you’ve already configured permalinks, as WordPress needs to refresh these settings for the new set of links to your products.
Adding Your Post Type to the Navigation MenuIf you want to add products to your navigation menu, you can. Go to Appearance -> Menus, and you’ll see that Products are displayed on the left. Simply drag any products onto your menu to include them.
July 24, 2015 at 11:36 am #160320Christoph
MemberHi,
sorry, I cannot replicate your problem.
I'm using your code, "refreshed" the permalinks and created 3 test portfolios.
This is what shows under Appearance - Menus
http://screencast.com/t/G65k7is69XR2
July 24, 2015 at 5:34 pm #160372codebot5000
MemberI don't know what the issue is. It works fine on my localhost page but wont work on my parallax pro child theme. It's driving me crazy.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.