1391 posts How's the surf doing?
  • Has referred 200+ members
  • Has sold $500,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+6 more
tommusrhodus says

This is interesting. I tried using get_pages for a one page theme and I found that the function ignored page templates. All it would return was the page text. Did you get it to work?

Get pages returns a page object from WordPress, not from the page templates you’ve set out. So what you’d need to do is read the page template from your objects meta details, and work with that data accordingly.

Assuming you’re in a foreach loop having called $pages as $page, the following will grab the page template data:

get_post_meta( $page->ID, '_wp_page_template', true )

EDIT: I also feel like index.php should be left well alone apart from the main blog loop, all this get pages stuff can just be run from a custom page template and then we can just let index.php chill and do its thing :)

186 posts
  • Has been part of the Envato Community for over 2 years
  • Has sold $1+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
ThemeBuddies says

I am using this method but it really doesn’t work. The page templates don’t get used. It only returns the text. For example, This is the loop I am using right now


  $page_query = new WP_Query(array(
        'post_status' => 'publish',
        'post_type' => 'page',
        'order' => 'ASC',
        'orderby' => 'menu_order',
        'posts_per_page' => '-1',
        'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1
    ));

            if ( $page_query->have_posts() ) : while ( $page_query->have_posts() ) : $page_query->the_post(); ?>
                          //CHECK IF THE PAGE HAS A PAGE TEMPLATE AND THAT THERE IS CONTENT IN THE PAGE
            <?php $template = get_post_meta( get_the_ID(), '_wp_page_template', TRUE ); ?>
            <?php if( $template && $post->post_content != '' ) { ?>
                        <li id="page_<?php echo str_replace(' ','_',strtolower( get_the_title())); ?>">
                            <?php get_template_part( 'content', 'page' ); ?>
                        </li>
             <?php } 

            endwhile;
            endif;
            ?>


So lets say that I have a page template called “template-portfolio.php”. It will not render the portfolio template. It will however return the text in the page but without any custom formatting.

1485 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+3 more
OriginalEXE says
^ Just a note, instead of using this:
<?php echo str_replace(' ','_',strtolower( get_the_title())); ?>
use this: http://codex.wordpress.org/Function_Reference/the_title_attribute


And in general, when you need to sanitize some string to be used in attribute, use this: http://codex.wordpress.org/Function_Reference/esc_attr

Also, no need for
if ( $page_query->have_posts() ) : while ( $page_query->have_posts() )
This is enuff:
while ( $page_query->have_posts() )
5 posts
  • Has been part of the Envato Community for over 3 years
  • Has collected 10+ items on Envato Market
UserFriendlyIT says

I use a “Home” custom post type, much better than using pages so they can still be used.

This has given me a good idea… CPT “Home page layout” has the multi-select/sorter to pull in any page the user wants and handle sorting. Hopefully they would only want to pull in pages that they had filled out using the provided sortcodes.

Could you please elaborate on your version of this?

264 posts
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Had an item featured on Envato Market
  • Located in Bangladesh
+2 more
theweblab says

Hi,

For a single page wp theme do I need to work on the other pages like archive, category, single etc.

Or the options with the home page is fine.

Thanks.

368 posts
  • Has referred 50+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+5 more
QBKL says

Last time I did it using the front-page.php template with a custom menu that handles the included pages and also the page order. Used the menu as navigation with a modified walker and also, queried all menu pages order-based in the front-page template. Worked like a charm.

@theweblab: Since it will be submitted as a WordPress theme you need to style and code every bit of WP core element. That includes categories, archives, searches, singles and so on. People have to be able to use the theme as standalone blogs if they so wish. Otherwise your theme will be rejected.

Regards, Alex

264 posts
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Had an item featured on Envato Market
  • Located in Bangladesh
+2 more
theweblab says

Thank you Alex.

Regards.

264 posts
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Had an item featured on Envato Market
  • Located in Bangladesh
+2 more
theweblab says

Hi,

I am creating different page templates for each sections and will treat each section as pages.

Each section/page template has a custom meta box with some custom fields to configure that section.

As the meta box is dependent on the template selection, user first need to select a template and then publish/save the page to see the corresponding meta box. IS THIS OK?

And then in the theme option have a tab to assign pages for each section.

Please let me know.

Thanks.

1602 posts Chris Robinson
  • Located in United States
  • Has sold $500,000+ on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has been part of the Envato Community for over 6 years
+10 more
contempoinc says


I use a “Home” custom post type, much better than using pages so they can still be used.

This has given me a good idea… CPT “Home page layout” has the multi-select/sorter to pull in any page the user wants and handle sorting. Hopefully they would only want to pull in pages that they had filled out using the provided sortcodes.

Could you please elaborate on your version of this?

Here’s a couple screenshots of the admin side:

by
by
by
by
by
by