嗨,我已经在谷歌上搜索了一段时间,但我找不到相关帮助。我有一个页面模板,列出了一堆自定义帖子。。。我在循环之前使用此代码显示我的自定义帖子:
<?php query_posts( array( \'post_status\' => \'publish\' , \'post_type\' => array( \'ncp_news\' ) ) ); ?>
当我删除它使其成为一个普通页面时,我可以很好地显示我的自定义侧栏,这样我就知道这与博客(自定义)帖子有关。。。
以下是完整代码:
<div class="posts_wrapperk">
<?php query_posts( array( \'post_status\' => \'publish\' , \'post_type\' => array( \'nyacp_news\' ) ) ); ?>
<?php if (have_posts()) : while(have_posts()) : the_post(); ?>
<?php
$sidebar_position = vp_metabox(\'_page_sidebar.sidebar_position\');
$main_classes = \'main\';
$aside_classes = \'aside\';
if (!empty($sidebar_position)) {
$opp = (($sidebar_position == \'left\') ? \'right\' : \'left\');
$main_classes .= " grid-9 $opp";
$aside_classes .= " grid-3 $sidebar_position";
}
?>
<section id="content"<?php echo qualia_build_class(array("content", "section", "color- palette-1", "separator-{$qualia_content_separator}")); ?>>
<div class="section-inner">
<div class="wrapper">
<div<?php echo (!empty($sidebar_position)) ? \' class="grids"\' : \'\'; ?>>
<div class="<?php echo $main_classes; ?>">
<article id="page-<?php the_ID(); ?>" <?php post_class(\'original-content\'); ?>>
<h1 class="nyacp-subheader"><?php echo get_the_title($ID); ?></h1>
<?php the_content(); ?>
</article>
</div>
</div>
</div>
<?php //echo qualia_spacer(array(\'size\' => $qualia_content_bottom_spacing)); ?>
</section>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
</div><!--.posts_wrapperk-->
<?php if (!empty($sidebar_position)) : ?>
<div class="<?php echo $aside_classes; ?> inner_sidebar">
<?php if ( !function_exists(\'dynamic_sidebar\') || !dynamic_sidebar(\'innerpage-sidebar\') ) : endif; ?>
</div>
<?php endif; ?>
<?php get_footer(); ?>
如何在显示自定义帖子时显示侧边栏?
SO网友:Sagive
你的结构可能不好。。。侧栏本身不应该在循环中,因为它可能包含多个循环(其中的小部件),这些循环会破坏代码。
这是“正确的结构”
如您所见,我们将侧边栏和内容分开
下面是使用您的代码的示例:
<?php
get_header();
global $qualia_content_separator, $qualia_content_top_spacing, $qualia_content_bottom_spacing;
?>
<div class="inner_banner_news">
<h1>In the News</h1>
<div class="inner_banner_feat">
<img src="<?php bloginfo(\'template_directory\'); ?>/images/board-image.jpg" />
</div>
</div>
<div class="posts_wrapperk">
<section id="content"<?php echo qualia_build_class(array("content", "section", "color-palette-1", "separator-{$qualia_content_separator}")); ?>>
<div class="section-inner">
<div class="wrapper">
<?php query_posts( array( \'post_status\' => \'publish\' , \'post_type\' => array( \'ncp_news\' ) ) ); ?>
<?php if (have_posts()) : while(have_posts()) : the_post(); ?>
<?php
$sidebar_position = vp_metabox(\'_page_sidebar.sidebar_position\');
$main_classes = \'main\';
$aside_classes = \'aside\';
if (!empty($sidebar_position)) {
$opp = (($sidebar_position == \'left\') ? \'right\' : \'left\');
$main_classes .= " grid-9 $opp";
$aside_classes .= " grid-3 $sidebar_position";
}
?>
<div<?php echo (!empty($sidebar_position)) ? \' class="grids"\' : \'\'; ?>>
<div class="<?php echo $main_classes; ?>">
<article id="page-<?php the_ID(); ?>" <?php post_class(\'original-content\'); ?>>
<h1 class="nyacp-subheader"><?php echo get_the_title($ID); ?></h1>
<?php the_content(); ?>
</article>
</div>
</div>
<?php endwhile; endif; ?>
<?php if (!empty($sidebar_position)) : ?>
<div class="<?php echo $aside_classes; ?> inner_sidebar">
<?php if ( !function_exists(\'dynamic_sidebar\') || !dynamic_sidebar(\'innerpage-sidebar\') ) : endif; ?>
</div>
<?php endif; ?>
</div>
<?php //echo qualia_spacer(array(\'size\' => $qualia_content_bottom_spacing)); ?>
</section>
</div><!--.posts_wrapperk-->
<?php get_footer(); ?>
这仍然有点混乱,但它应该工作。。。我怎么会认为你需要将侧边栏CSS到所需的位置。