Php WordPress:无法获取当前ID。
我是WordPress的新手,我一直在想方设法弄明白这一点 我有一个自定义主题,主题非常简单,其中包含一个图像旋转木马,它是从画廊中的图像集合中构建的 如果我删除了carousel include文件,页面其余部分的post ID将正确返回,一旦我添加了carousel,它将使用代码中最后一个类别的ID 我删除了所有“全局”引用,因为我认为这将覆盖页面其余部分的ID,但这仍然是错误的 carousel.php文件中的代码:Php WordPress:无法获取当前ID。,php,wordpress,Php,Wordpress,我是WordPress的新手,我一直在想方设法弄明白这一点 我有一个自定义主题,主题非常简单,其中包含一个图像旋转木马,它是从画廊中的图像集合中构建的 如果我删除了carousel include文件,页面其余部分的post ID将正确返回,一旦我添加了carousel,它将使用代码中最后一个类别的ID 我删除了所有“全局”引用,因为我认为这将覆盖页面其余部分的ID,但这仍然是错误的 carousel.php文件中的代码: <div id="carousel"> <?
<div id="carousel">
<?php
$args = array(
'post_type' => 'gallery',
'post_status' => 'publish',
'name' => $wp_query->query_vars['name'],
'posts_per_page' => 1
);
$second_query = new WP_Query($args);
$gllr_options = get_option('gllr_options');
$gllr_download_link_title = addslashes(__('Download high resolution image', 'gallery'));
if ($second_query->have_posts()) : while ($second_query->have_posts()) : $second_query->the_post(); ?>
<div class="carousel-holder">
<?php
the_content();
$galleries = get_posts(array(
'showposts' => -1,
'what_to_show' => 'posts',
'post_status' => 'inherit',
'post_type' => 'attachment',
'orderby' => $gllr_options['order_by'],
'order' => $gllr_options['order'],
'post_mime_type' => 'image/jpeg,image/gif,image/jpg,image/png',
'post_parent' => $post->ID
));
if (count($galleries) > 0) { ?>
<ul id="carousel-gallery">
<?php foreach ($galleries as $attachment) {
$key = 'gllr_image_text';
$link_key = 'gllr_link_url';
$alt_tag_key = 'gllr_image_alt_tag';
$image_attributes = wp_get_attachment_image_src( $attachment->ID, 'photo-thumb' );
$image_attributes_large = wp_get_attachment_image_src( $attachment->ID, 'large' );
$image_attributes_full = wp_get_attachment_image_src( $attachment->ID, 'full' );
if ( 1 == $gllr_options['border_images'] ) {
$gllr_border = 'border-width: ' . $gllr_options['border_images_width'] . 'px; border-color:' . $gllr_options['border_images_color'] . '';
$gllr_border_images = $gllr_options['border_images_width'] * 2;
} else {
$gllr_border = '';
$gllr_border_images = 0;
}
if (($url_for_link = get_post_meta($attachment->ID, $link_key, true)) != "") { ?>
<li>
<img alt="<?php echo get_post_meta($attachment->ID, $alt_tag_key, true); ?>" title="<?php echo get_post_meta( $attachment->ID, $key, true ); ?>" src="<?php echo $url_for_link; ?>" />
</li>
<?php } else { ?>
<li rel="gallery_fancybox<?php if ( 0 == $gllr_options['single_lightbox_for_multiple_galleries'] ) echo '_' . $post->ID; ?>">
<img alt="<?php echo get_post_meta($attachment->ID, $alt_tag_key, true); ?>" title="<?php echo get_post_meta( $attachment->ID, $key, true ); ?>" src="<?php echo $image_attributes_large[0]; ?>" />
</li>
<?php }
$count_image_block++;
} ?>
</ul>
<div class="clearfix"></div>
<div id="arrows" class="arrows">
<a id="prev" class="prev" href="#"></a>
<a id="next" class="next" href="#"></a>
</div>
<div id="paginator" class="paginator"></div>
<?php } ?>
</div>
<?php endwhile; else: endif;?>
</div>
-
" />
尝试使用wp_reset_query()方法重置循环
将此放置在旋转木马循环结束后
<?php wp_reset_query(); ?>
哪部分显示“页面其余部分的帖子ID返回正确”?注意:这类问题还有Wordpress Stackexchange
<?php
/**
* Template Name: 2 Column Left
*/
get_header();
?>
<div id="maincontent">
<div id="content" class="site-content" role="main">
<div class="left sidebar">
<?php
echo the_ID();
?>
</div>
</div>
</div>
<?php get_footer(); ?>
<?php wp_reset_query(); ?>