single.php上的WordPress边栏

时间:2013-12-17 16:57:47

标签: php wordpress templates sidebar

所以,我的侧边栏在我的博客页面上工作得很好:beta.cleantelligent.com/blog 但是,当您单击一个帖子时,我希望显示相同的侧边栏。

我假设这将是single.php,对吧?该代码如下所示。如果您需要任何其他代码,请告诉我,我会在此处发布。

我在Wordpress中的编辑页面上的页面属性中有'博客'侧边栏,但是我觉得它不被模板识别?

任何帮助都会很棒。谢谢!

<?php 
get_header(); ?>
<div class="blackbar">
<div class='bbw'>
Blog
</div>
</div>
<div class='cont-wrap'>

<div id="primary">
    <?php
$post_obj = $wp_query->get_queried_object();
$post_name = $post_obj->post_name;
if($post_name == 'blog'){
    echo 'Blog';
}else{
    $parent_title = get_the_title($post->post_parent);
    echo $parent_title;
}
?>
    <div id="content" role="main">

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

            <?php get_template_part( 'content', 'archive' ); ?>

        <?php endwhile; // end of the loop. ?>

    </div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
</div>

博客页面正在使用index.php

<?php
get_header(); ?>
<div class="blackbar">
<div class='bbw'>
<?php
$post_obj = $wp_query->get_queried_object();
$post_name = $post_obj->post_name;
if($post_name == 'blog'){
    echo 'Blog';
}else{
    $parent_title = get_the_title($post->post_parent);
    echo $parent_title;
}
?>
</div>
</div>
<div class='cont-wrap'>
    <div id="primary">
        <div id="content" role="main">

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


                <?php get_template_part( 'content', 'blog' ); ?>



                <?php comments_template( '', false ); ?>

            <?php endwhile; // end of the loop. ?>

        </div><!-- #content -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>
</div>

</div><!-- #main -->

这是我的sidebar.php:

<?php

$options = twentyeleven_get_theme_options();
$current_layout = $options['theme_layout'];
$nav = sb_get_page_nav($post);
if ( 'content' != $current_layout ) :
?>
<img class="sidebar-top" src='<?php bloginfo('stylesheet_directory'); ?>/images/sidebar-top.png' />
    <div id="secondary" class="widget-area" role="complementary">
    <?php
        $post_obj = $wp_query->get_queried_object();
        $post_name = $post_obj->post_name;
        $title = 'cs-' . $post_name; 
        ?>
    <?php
        if($post_name == 'news-events'){
            if ( ! dynamic_sidebar( 'sidebar-web' ) ) :
            endif;
        }
    ?>

    <?php if(!$nav['no_nav']) { ?>
        <div class="SimpleSideNav">
            <?php wp_nav_menu(array('container_id' => 'left-navigation','menu' => $nav['title'])); ?>
        </div>
    <?php } ?>


    <?php if ( ! dynamic_sidebar( 'sidebar-all' ) ) : ?>
    <?php endif; // end sidebar widget area ?>
    <?php /*
    <nav id="left-nav">
        <div class="nav-wrapper">
            <?php if(!$nav['no_nav']) {
                wp_nav_menu(array('container_id' => 'left-navigation','menu' => $nav['title']));
            } ?>
        </div>
    </nav>
        */ ?>

        <?php if ( ! dynamic_sidebar( $title ) ) : ?>
        <?php endif; // end sidebar widget area ?>
        <img class="sidebar-bot" src='<?php     bloginfo('stylesheet_directory'); ?>/images/sidebar-bot.png' />
    </div><!-- #secondary .widget-area -->

<?php endif; 
$parent_title = get_the_title($post->post_parent);
if($parent_title == 'Tour'){
echo"
<script>
jQuery('.w-1').hide();
</script>
";
}
?>

1 个答案:

答案 0 :(得分:0)

我通过在sidebar-blog.php下创建一个全新的侧边栏并将我的模板重定向到它来修复它。