November 2, 201213 yr I have a custom post type (that I'm using on a template page), the custom post type is called 'Headerhome'. When I post say a gallery there I'm trying to get it to redirect to 'single-Headerhome.php', yet it always just goes to 'single.php'. The name of the custom post type itself is arbitrary, the name of the templage page it's on is 'homepage.php'. I'm really confused, I'm not the best at WP yet so when something simple like this doesn't work I have no idea how to fix it, even after pouring over the codex for an hour.
November 2, 201213 yr Author Could you post your register_post_type() call? // Add new post type for homepage add_action('init', 'frontpage_top_init'); function frontpage_top_init() { $args = array( 'label' => __('Homepage'), 'singular_label' => __('Homepage'), 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'hierarchical' => false, 'menu_position' => 5, 'supports' => array('title','editor') ); register_post_type('Headerhome',$args); }
November 2, 201213 yr Try making both your post type slug and the template file lowercase, to start off with.
November 2, 201213 yr register_post_type('headerhome',$args); and name your template 'single-headerhome.php'
November 3, 201213 yr Is it local or live? The other thing I'd point out there is WordPress already has two templates in the hierarchy for the homepage, there's home.php for when the homepage is the blog index and front-page.php for when the homepage is a Page.
November 3, 201213 yr Author It's live, it's just a simple portfolio site I'm doing for a friend. It's not going to win any design awards, but then again it's nowhere near finished nor is it anything more than a reference for employers and a place to house a basic blog. www.scottomahony.co.uk Well, how I have it set up is I have 2 template files, one for the blog and one for the home page (currently the home page template file is called homepage.php but it has the title of portfolio). It's a custom 'loop' if you will that I've written for the custom post type that pulls in content from that post type (post type is called headerhome). The custom post type (headerhome) uses advanced custom fields to edit the content and make it easy to update. I've set wordpress to use a 'static page' for the front page and selected the homepage.php template as that page, although it's not 'static'. Here's my (messy) code for the homepage.php <?php /* Template Name: Homepage */ ?> <?php get_header(); ?> <div id="main-content"> <div class="head-home"> <?php query_posts(array( 'post_type' => 'headerhome', 'showposts' => 1 ) ); ?> <?php while (have_posts()) : the_post(); ?> <h2><?php the_title(); ?></h2> <?php the_content(); ?> <div style="clear:both"></div> <div class="embed-container"> <?php the_field('showreel'); ?> </div> <!-- end div embed-container --> </div> <!-- end div head-home --> <div class="gallerydescription"> <?php the_field ('gallery-description'); ?> </div> <!-- end div gallerydescription --> <?php the_field('image-1'); ?> <div style="clear:both;"></div> <?php endwhile; wp_reset_query();?> </div> <!-- end div main-content --> <?php get_footer(); ?>
November 3, 201213 yr Righto. First step is to rename the template to front-page.php, and make sure you have "Static Page" selected for homepage in Settings > Reading. Next up, you want: <?php $portfolio_query = new WP_Query(array( 'post_type' => 'headerhome', 'showposts' => 1 ) ); ?> instead of query_posts(), so you can use a second loop for the portfolio stuff with: <?php while ($portfolio_query->have_posts()) : $portfolio_query->the_post(); ?> leaving the main loop free to set up the page as WP expects. As a side note, you should never use query_posts(), there's always a better way (either hooking to pre_get_posts or setting up a separate query). Edited November 3, 201213 yr by Renaissance-Design
November 3, 201213 yr Author Checked static page set for the homepage(it was), template renamed to front-page.php. Change the loop to what you wrote. Posted a new image to test just incase something was cached, still defaults to single.php instead of single-headerhome.php Full code:- <?php /* Template Name: frontpage */ ?> <?php get_header(); ?> <div id="main-content"> <div class="head-home"> <?php $portfolio_query = new WP_Query(array( 'post_type' => 'headerhome', 'showposts' => 1 ) ); ?> <?php while ($portfolio_query->have_posts()) : $portfolio_query->the_post(); ?> <h2><?php the_title(); ?></h2> <?php the_content(); ?> <div style="clear:both"></div> <div class="embed-container"> <?php the_field('showreel'); ?> </div> <!-- end div embed-container --> </div> <!-- end div head-home --> <div class="gallerydescription"> <?php the_field ('gallery-description'); ?> </div> <!-- end div gallerydescription --> <?php the_field('image-1'); ?> <div style="clear:both;"></div> <?php endwhile; wp_reset_query();?> </div> <!-- end div main-content --> <?php get_footer(); ?> Edited November 3, 201213 yr by andys
November 3, 201213 yr Author This is currently displaying using single.php? Yup, I copied single.php and make some changes so I'll know if it displays the new template. For example single-headerhome.php has no sidebar.
Create an account or sign in to comment