'has_archive' => true, ... 'rewrite' => array('slug' => 'businesses', 'with_front' => false)
Well @ThemeBuddies, remember one thing… when you create custom post types, there is one important note about both rewrite, and has_archive. These arguments are necessary if you want to be able to view an index of your posts without having a specific page template dedicated to it.'has_archive' => true, ... 'rewrite' => array('slug' => 'businesses', 'with_front' => false)
This doesn’t make sense to me. I don’t have any CPT in the theme. just posts and pages. Trying to get them all to display on the homepage.
Well, you get duplicated posts because you run the loop twice… You have pretty much answered your question. You just have to either modify the main query or run a custom one, like this:
$args = array( 'post_type' => 'page' ); $page_query = new WP_Query( $args ); if ( $page_query->have_posts() ) : while ( $page_query->have_posts() ) : $page_query->the_post(); $template = get_post_meta( $post->ID, '_wp_page_template', true ); // If the page doesn't have any template assigned - display the default page template if ( $template == 'default' ) $template = 'page.php'; get_template_part( $template ); endwhile; endif;
That’s pretty much it.
I like your idea. It seems simple enough but doesn’t return anything. no posts or pages. I understand the code. It does make sense but doesn’t make sense as to why it’s not working. I am going to look into get_template_part and see if I can figure it out.
Oh, I know what might be wrong. The ‘_wp_page_template’ returns the file name with ’.php’ at the end, e.g. ‘template-portfolio.php’, while the
get_template_part function accepts the template name without ’.php’ at the end. You will have to strip that part and you’ll be good to go.
I just change it from get_template_part to include and it’s working fine. Now I am editing the code to make it work in my theme. This might be the solution I was looking for. I don’t see any double posts yet so that is good. Thank you for your help.
P.S I have been working on this theme for over two months and have spent countless hours googling looking for any tutorials that I could find on how to make a one page WordPress site. As far as I can tell, there are ZERO tuts out there. Since ThemeForest does look for tutorials to post and sell, this might make a great tut for someone who can share the wisdom.
- Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
- Open a support ticket if you would like specific help with your account, deposits or purchases.
- Item Support by authors is optional and may vary. Please see the Support tab on each item page.
Most of all, enjoy your time here. Thank you for being a valued Envato community member.