WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Ok so this is really strange. I do not consider myself a WordPress expert, but I am also not a beginner either. I created a template that works just the way I need it. Basically it checks for the attachments associated with the page and displays them in a gallery.

This template works fine when there is no parent. When it becomes a child, however, it breaks. It reverts back to the static home page and the pages title becomes (space) - (site name), indicating to me that WordPress is confused as to what type of page it is.

Here is the full template page:



Template Name: Gallery


wp_register_script( 'script', get_template_directory_uri() . '/js/product-script.js' );
wp_register_script( 'jPages', get_template_directory_uri() . '/js/jPages.js' );
wp_enqueue_script( 'jPages');
wp_enqueue_script( 'script' );


global $post;

$querystr = 'SELECT ' . $wpdb->prefix . 'posts.post_title AS "imageTitle", ' . $wpdb->prefix . 'posts.post_content AS "imageDescription", ' . $wpdb->prefix . 'posts.guid AS "imageGuid" FROM ' . $wpdb->prefix . 'posts WHERE ' . $wpdb->prefix . 'posts.post_parent = '. $post->ID .' AND ' . $wpdb->prefix . 'posts.post_type = "attachment" ORDER BY post_title  LIMIT 1';

global $wpdb;

$post_item = $wpdb->get_row($querystr);

$first_title = $post_item->imageTitle;
$first_attachment = $post_item->imageGuid;
$first_description = $post_item->imageDescription;

$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID, 'order' => 'ASC', 'orderby' => 'title' );

$attachments = get_posts($args);

if ($attachments) { 


<div class="container clearfix">

<span id="gallery-page" class="clearfix"><?php echo the_title(); ?></span>
<div class="img clearfix">

    <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>

    <div class="col-three">

        <div id="gallery-thumbs">

            <ul class="thumbs noscript clearfix" id="gallery-ul">


                foreach ( $attachments as $attachment ) {

                    $title = apply_filters( 'the_title' , $attachment->post_title );

                    $full_src = wp_get_attachment_image_src( $attachment->ID, 'full' );

                    $thumb_src = wp_get_attachment_image_src( $attachment->ID, array( 100, 100) );

                    $description = $attachment->post_content;

                    $description = str_replace('*', '<br />', $description);
                    $first_description = str_replace('*', '<br />', $first_description);

                    if ( get_post_meta($attachment->ID, 'new', true))
                        $new = '<span>New!</span>';

                    $ul = '<ul><li>';
                    $end_ul = '</li></ul>';



                        <a class="thumb " href="<?php echo $full_src[0]; ?>" title="<?php echo $title; ?>" rel="<?php echo $full_src[0]; ?>" >

                            <img src="<?php echo $thumb_src[0]; ?>" alt="<?php echo $title; ?>" class="clearfix gallery-imgs"  /><br />
                            <?php echo $new; echo mb_strimwidth($title, 0, 14, '...'); ?>
                            <div class="desc-swap" style="display:none;"><?php echo $description; ?></div>
                            <div class="title-swap" style="display:none;"><?php  echo $title; ?></div>
                            <div class="new" style="display:none;"><?php echo $new; ?></div>






            <div class="holder"></div>



    <div id="bio">


        echo '<div class="title-container clearfix">';

        echo '<ul><li><span class="title-destination" >'.$first_title.'</span></li></ul><div class="new-destination" id="title-new"></div>';

        echo '</div><!--.title-container-->';

        echo '<img id="mainpic" src="'.$first_attachment.'" width="480" />';

        echo '<section id="description-container">';

        echo '<span class="new-destination" id="description-new"></span><br />';

        echo '<section class="desc-destination">'.$first_description.'</section>';

        echo '</section<!--description-container-->';





endwhile; endif;

<section id="modal-menu">
<?php require ('modal-menu.php');?>


Thinking that something in my code may be breaking it, I've already tried removing the initial query and the modal section at the end to no avail. Normally I'm searching for answers to this on my own...but in this case I have absolutely no idea where to even begin.

Thanks for any help!

share|improve this question

Disregard, I found the problem. I needed to refresh the .htaccess file by going to Settings->Permalinks and hitting Save Changes.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.