The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End help with foreach loop Reply To: help with foreach loop


each template uses categories to get it’s content. When I make a template called template-contact.php and I put the contact page specific code into that template and then make a page called contact and assign the contact page template to that page, the page will be blank when I go to it. The only way I could get the actual content to show was to paste all the code into functions.php as a shortcode and put that shortcode into the page. It appears that the template structure gets ignored by this method. Here is the full code to my custom query. maybe this will make it make more sense. I will put comments in the code to explain it.

 //starting my custom query 
    $page_query = new WP_Query(array(
    'post_status' => 'publish',
    'post_type' => 'page',   // getting the pages
    'order' => 'ASC',
    'orderby' => 'menu_order',
    'posts_per_page' => '-1',
    'offset' => '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(); ?>

                     //checking to see if the page has a template assigned to it
        <?php $template = get_post_meta( get_the_ID(), '_wp_page_template', TRUE ); ?> 

          //asking the system not to load a page that doesn't have any content in it.  This prevents duplicates
        <?php if( $template && $post->post_content != '' ) { ?>

                                           The theme has a jquery powered slider that slides each page into view. This list element is      programmed to hold all the pages. The id="page_page-title" interacts with the code to slide the page
                    <li id="page_<?php echo str_replace(' ','_',strtolower( get_the_title())); ?>">

                                                    //using the standard WordPress code to get the page
                        <?php get_template_part( 'content', 'page' ); ?>
         <?php }