WordPress单个帖子模板布局

时间:2019-01-16 17:09:51

标签: wordpress layout sidebar

我对WordPress不太熟悉,但是,我创建了以下页面来显示自定义帖子类型single-opportunities.php

<?php
/**
 * The Template for displaying single opportunities posts.
 **/


get_header();
global $accesspresslite_options, $post;
$accesspresslite_settings = get_option( 'accesspresslite_options', $accesspresslite_options );
$post_class = get_post_meta( $post -> ID, 'accesspresslite_sidebar_layout', true );
?>

<div class="ak-container">
    <?php 
        if ($post_class=='both-sidebar') { ?>
            <div id="primary-wrap" class="clearfix"> 
        <?php }
    ?>
    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">


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

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

            <?php // accesspresslite_post_nav(); ?>

            <?php
            // If comments are open or we have at least one comment, load up the comment template
            if ( comments_open() || '0' != get_comments_number() ) :
                comments_template();
            endif;
            ?>

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

            ?>

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

        <?php 
    get_sidebar('left'); 

        if ($post_class=='both-sidebar') { ?>
            </div> 
        <?php }

    ?>
</div>

<?php get_footer(); ?>

我添加了一个自定义帖子类型,此页面显示信息OK,但布局的右侧有一个侧边栏。我不确定为什么在右侧显示侧边栏?可以更改此默认选项。

理想情况下,我想编辑上面的模板,以便布局具有左侧边栏,然后可以向其中添加自定义菜单。

1 个答案:

答案 0 :(得分:0)

看起来像您在帖子/页面主体之后调用侧边栏。在将其显示在左侧之前,先调用它。

/**
* The Template for displaying single opporunities posts.
*
*/

get_header();
global $accesspresslite_options, $post;
$accesspresslite_settings = get_option( 'accesspresslite_options', 
$accesspresslite_options );
$post_class = get_post_meta( $post -> ID, 'accesspresslite_sidebar_layout', true );
 ?>

<div class="ak-container">
<?php 
    if ($post_class=='both-sidebar') { ?>
        <div id="primary-wrap" class="clearfix"> 
    <?php }
     get_sidebar('left'); 
?>
<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">


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

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

        <?php // accesspresslite_post_nav(); ?>

        <?php
        // If comments are open or we have at least one comment, load up the comment template
        if ( comments_open() || '0' != get_comments_number() ) :
            comments_template();
        endif;
        ?>

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

        ?>

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

    <?php 

    if ($post_class=='both-sidebar') { ?>
        </div> 
    <?php }

?>