Community Forums › Forums › Archived Forums › Design Tips and Tricks › Ho to add content to a template page
- This topic has 1 reply, 2 voices, and was last updated 8 years, 11 months ago by Brad Dalton.
-
AuthorPosts
-
April 30, 2015 at 11:14 am #149633ravenousravendesignMember
Hi,
I'm using the graceful child theme and have integrated the minimum pro child theme portfolio into the theme itself. It' works great, but I would like to make a customization that doesn't seem to be working for me.
See here: http://181.224.137.174/~ashleyg6/portfolio/I would like to a couple things to happen.
1. Allow the client to choose the template from the page templates drop down option. So in order to do that, I added the Template Name: Portfolio into the archive-portfolio. Problem is, when you apply the portfolio to a page, although it does take the css, it does not show any of the portfolio items. It's just blank. Why? (I applied portfolio to this page http://181.224.137.174/~ashleyg6/press/)
2. The reason I want my client to choose a page template is because for a while she will only show images until she has enough to create an album and use the portfolio post types. So if she were to use the same page and later convert it to a page template, that would be awesome so that her URL to the page doesn't have to change. But when applying the template, aside from not being able to display portfolio items, it also doesn't display content that has been written in the wp editor for that page.
I don't like that the only way to view the portfolio is by creating a men item and linking to the page (mysite/portfolio). It doesn't allow for anyone to add any content above the portfolio or below the portfolio if they choose. Perhaps it would prove best to create a shortcode from the custom portfolio post type? Does anyone know how to properly do that with the current code cause my efforts proved fruitless.
Here is the functions code for portfolio post type
//* Create portfolio custom post type add_action( 'init', 'minimum_portfolio_post_type' ); function minimum_portfolio_post_type() { register_post_type( 'portfolio', array( 'labels' => array( 'name' => __( 'Portfolio', 'minimum' ), 'singular_name' => __( 'Portfolio', 'minimum' ), ), 'exclude_from_search' => true, 'has_archive' => true, 'hierarchical' => false, 'menu_icon' => 'dashicons-admin-page', 'public' => true, 'show_in_menu' => true, 'rewrite' => array( 'slug' => 'portfolio', 'with_front' => true ), 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes', 'genesis-seo' ), ) ); }
Here is the code used in the archive-portfolio.php post type (aside from adding the template name)
<?php /** * The custom portfolio post type archive template/minimum */ //* Force full width content layout add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' ); //* Add even/odd post class add_filter( 'post_class', 'minimum_even_odd_portfolio_post_class' ); function minimum_even_odd_portfolio_post_class( $classes ) { global $wp_query; $classes[] = ($wp_query->current_post % 2 == 0) ? 'portfolio-odd' : 'portfolio-even'; return $classes; } //* Remove the entry meta in the entry header remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 ); remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 ); //* Remove the entry content remove_action( 'genesis_entry_content', 'genesis_do_post_content' ); //* Remove the entry image remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 ); //* Add the featured image after post title add_action( 'genesis_entry_content', 'minimum_portfolio_grid' ); function minimum_portfolio_grid() { if ( $image = genesis_get_image( 'format=url&size=portfolio' ) ) { printf( '<div class="portfolio-image"><a href="%s" rel="bookmark"><img src="%s" alt="%s" /></a></div>', get_permalink(), $image, the_title_attribute( 'echo=0' ) ); } } //* Remove the entry meta in the entry footer remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 ); remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 ); //* Run the Genesis loop genesis();
May 2, 2015 at 6:44 pm #149885Brad DaltonParticipant1. You can see how the WordPress Template Hierarchy works
WordPress uses the file name for your custom post type archive. There's actually no need to even add a file named archive-portfolio.php unless you want to modify it to be different than your themes default archives which is the case.
A page template is different and isn't loaded unless you select it from the Page Attributes meta box which can't happen for archives which is why you use the Template Hierarchy and file name.
Another way to load a specific file or template is to use a filter like template_include
I assume you want to enable the user the capability to select a page template for single custom post types?
2. You can add content before the portfolio archive page using the CPT archive settings.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.