好吧,这真的很奇怪。我不认为自己是WordPress专家,但我也不是初学者。我创建了一个模板,它可以按照我需要的方式工作。基本上,它会检查与页面关联的附件,并将其显示在图库中。
当没有父级时,此模板工作正常。然而,当它变成一个孩子时,它就破碎了。它恢复到静态主页,页面标题变为(空格)-(站点名称),这向我表明WordPress对它是什么类型的页面感到困惑。
以下是完整的模板页面:
<?php
/*
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\' );
get_header();
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">
<?php
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>\';
?>
<li>
<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>
</a>
</li>
<?php
unset($new);
}
?>
</ul>
<div class="holder"></div>
</div>
</div>
<div id="bio">
<?php
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-->\';
?>
</div>
</div>
</div>
<?php
endwhile; endif;
}
?>
<section id="modal-menu">
<?php require (\'modal-menu.php\');?>
</section><!--#modal-menu-->
<?php
get_footer();
?>
考虑到代码中的某些内容可能会破坏它,我已经尝试删除初始查询和最后的模态部分,但没有任何效果。通常我会自己寻找答案。。。但在这种情况下,我完全不知道从哪里开始。
谢谢你的帮助!