【问题标题】:Wordpress single.php layoutWordpress single.php 布局
【发布时间】:2015-02-16 08:53:46
【问题描述】:

我正在使用 Wordpress 主题“Salient”将我的图形设计/作品集博客放在一起,我在控制博客文章页面 (single.php) 布局的主题中的设置有问题,我没有什么经验使用 php 并希望有人能告诉我一个简单的解决方案或修改我的 single.php 文件以显示我想要的方式。

我希望我的博客文章页面如下所示: http://www.ravagedesign.com/freebies/greylime-hd-launcher-theme-icon-pack-released/ 博客标题/日期/类别和社交图标列在大特征图形下方,我通过使用滑块插件实现了这一点,但这不是长期的选择,因为我最终会在我的插件上得到一个巨大的列表,这也是页面加载时间明显变慢。

我不希望它看起来像这样: http://www.ravagedesign.com/freebies/greyice-hd-launcher-theme-icon-pack-released/ 博客标题/日期/类别和社交图标放置在置顶图内,这篇文章是使用主题内置的更传统方法制作的,将大置顶图合并到每个单独的帖子中。

是否可以对我的 single.php 文件进行修改,以便在发布选项中使用特征图,同时将所有信息放在特征图下方,如第一页。

我的 single.php 文件(突出主题):

<?php get_header(); ?>

<?php 

global $nectar_theme_skin, $options;

$bg = get_post_meta($post->ID, '_nectar_header_bg', true);
$bg_color = get_post_meta($post->ID, '_nectar_header_bg_color', true);
$fullscreen_header = (!empty($options['blog_header_type']) && $options['blog_header_type'] == 'fullscreen' && is_singular('post')) ? true : false;
$fullscreen_class = ($fullscreen_header == true) ? "fullscreen-header full-width-content" : null;
$theme_skin = (!empty($options['theme-skin']) && $options['theme-skin'] == 'ascend') ? 'ascend' : 'default';
$hide_sidebar = (!empty($options['blog_hide_sidebar'])) ? $options['blog_hide_sidebar'] : '0'; 
$blog_type = $options['blog_type']; 


if(have_posts()) : while(have_posts()) : the_post();

    nectar_page_header($post->ID); 

endwhile; endif;



 if($fullscreen_header == true) { 

    if(empty($bg) && empty($bg_color)) { ?>
        <div class="not-loaded default-blog-title fullscreen-header" id="page-header-bg" data-alignment="center" data-parallax="0" data-height="450" style="height: 450px;">
            <div class="container"> 
                <div class="row">
                    <div class="col span_6 section-title blog-title">
                        <h1 class="entry-title"><?php the_title(); ?></h1>
                        <div class="author-section">
                            <span class="meta-author vcard author">  
                                <?php if (function_exists('get_avatar')) { echo get_avatar( get_the_author_meta('email'), 100 ); }?>
                            </span> 
                             <div class="avatar-post-info">
                                <span class="fn"><?php the_author_posts_link(); ?></span>
                                <span class="meta-date date updated"><i><?php echo get_the_date(); ?></i></span>
                             </div>
                        </div>
                    </div>
                </div>
            </div>
            <a href="#" class="section-down-arrow"><i class="icon-salient-down-arrow icon-default-style"> </i></a>
        </div>
    <?php } 


    if($theme_skin != 'ascend') { ?>
        <div class="container">
            <div id="single-below-header" class="<?php echo $fullscreen_class; ?> custom-skip">
                <span class="meta-share-count"><i class="icon-default-style steadysets-icon-share"></i> <?php echo '<a href=""><span class="share-count-total">0</span> <span class="plural">'. __('Shares',NECTAR_THEME_NAME) . '</span> <span class="singular">'. __('Share',NECTAR_THEME_NAME) .'</span></a>'; nectar_blog_social_sharing(); ?> </span>
                <span class="meta-category"><i class="icon-default-style steadysets-icon-book2"></i> <?php the_category(', '); ?></span>
                <span class="meta-comment-count"><i class="icon-default-style steadysets-icon-chat-3"></i> <a href="<?php comments_link(); ?>"><?php comments_number( __('No Comments', NECTAR_THEME_NAME), __('One Comment ', NECTAR_THEME_NAME), __('% Comments', NECTAR_THEME_NAME) ); ?></a></span>
            </div><!--/single-below-header-->
        </div>

    <?php }

 } ?>




<div class="container-wrap <?php echo ($fullscreen_header == true) ? 'fullscreen-blog-header': null; ?> <?php if($blog_type == 'std-blog-fullwidth' || $hide_sidebar == '1') echo 'no-sidebar'; ?>">

    <div class="container main-content">

        <?php if(get_post_format() != 'quote' && get_post_format() != 'status' && get_post_format() != 'aside') { ?>

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

                if((empty($bg) && empty($bg_color)) && $fullscreen_header != true) { ?>

                    <div class="row heading-title">
                        <div class="col span_12 section-title blog-title">
                            <h1 class="entry-title"><?php the_title(); ?></h1>

                            <div id="single-below-header">
                                <span class="meta-author vcard author"><span class="fn"><?php echo __('By', NECTAR_THEME_NAME); ?> <?php the_author_posts_link(); ?></span></span> 
                                <?php if( !empty($options['blog_social']) && $options['blog_social'] == 1) { ?>
                                    <span class="meta-date date updated"><?php echo get_the_date(); ?></span>
                                <?php } ?>
                                <span class="meta-category"><?php the_category(', '); ?></span>
                                <span class="meta-comment-count"><a href="<?php comments_link(); ?>"><?php comments_number( __('No Comments', NECTAR_THEME_NAME), __('One Comment ', NECTAR_THEME_NAME), __('% Comments', NECTAR_THEME_NAME) ); ?></a></span>

                            </ul><!--project-additional-->
                            </div><!--/single-below-header-->

                            <div id="single-meta" data-sharing="<?php echo ( !empty($options['blog_social']) && $options['blog_social'] == 1 ) ? '1' : '0'; ?>">
                                <ul>

                                    <?php if( empty($options['blog_social']) || $options['blog_social'] == 0 ) { ?>

                                            <li>
                                                <?php echo '<span class="n-shortcode">'.nectar_love('return').'</span>'; ?>
                                            </li>
                                            <li>
                                                <?php echo get_the_date(); ?>
                                            </li>

                                    <?php } ?>

                                </ul>

                                <?php nectar_blog_social_sharing(); ?>

                            </div><!--/single-meta-->
                        </div><!--/section-title-->
                    </div><!--/row-->

            <?php }

            endwhile; endif; ?>

        <?php } ?>

        <div class="row">

            <?php $options = get_option('salient'); 

            global $options;

            if($blog_type == 'std-blog-fullwidth' || $hide_sidebar == '1'){
                echo '<div id="post-area" class="col span_12 col_last">';
            } else {
                echo '<div id="post-area" class="col span_9">';
            }

                 if(have_posts()) : while(have_posts()) : the_post(); 


                    if ( floatval(get_bloginfo('version')) < "3.6" ) {
                        //old post formats before they got built into the core
                         get_template_part( 'includes/post-templates-pre-3-6/entry', get_post_format() ); 
                    } else {
                        //WP 3.6+ post formats
                         get_template_part( 'includes/post-templates/entry', get_post_format() ); 
                    } 

                 endwhile; endif; 

                 wp_link_pages(); 


                    $options = get_option('salient');

                    if($theme_skin != 'ascend') {
                        if( !empty($options['author_bio']) && $options['author_bio'] == true){ 
                            $grav_size = 80;
                            $fw_class = null; 
                        ?>

                            <div id="author-bio" class="<?php echo $fw_class; ?>">
                                <div class="span_12">
                                    <?php if (function_exists('get_avatar')) { echo get_avatar( get_the_author_meta('email'), $grav_size ); }?>
                                    <div id="author-info">
                                        <h3><span><?php if(!empty($options['theme-skin']) && $options['theme-skin'] == 'ascend') { _e('Author', NECTAR_THEME_NAME); } else { _e('About', NECTAR_THEME_NAME); } ?></span> <?php the_author(); ?></h3>
                                        <p><?php the_author_meta('description'); ?></p>
                                    </div>
                                    <?php if(!empty($options['theme-skin']) && $options['theme-skin'] == 'ascend'){ echo '<a href="'. get_author_posts_url(get_the_author_meta( 'ID' )).'" data-hover-text-color-override="#fff" data-hover-color-override="false" data-color-override="#000000" class="nectar-button see-through-2 large"> '. __("More posts by",NECTAR_THEME_NAME) . ' ' .get_the_author().' </a>'; } ?>
                                    <div class="clear"></div>
                                </div>
                            </div>

                    <?php } ?>

                    <div class="comments-section">
                           <?php comments_template(); ?>
                     </div>   


                <?php } ?>

            </div><!--/span_9-->

            <?php if($blog_type != 'std-blog-fullwidth' && $hide_sidebar != '1') { ?>

                <div id="sidebar" class="col span_3 col_last">
                    <?php get_sidebar(); ?>
                </div><!--/sidebar-->

            <?php } ?>

        </div><!--/row-->


        <!--ascend only author/comment positioning-->
        <div class="row">

            <?php if($theme_skin == 'ascend' && $fullscreen_header == true) { ?>

            <div id="single-below-header" class="<?php echo $fullscreen_class; ?> custom-skip">
                <span class="meta-share-count"><i class="icon-default-style steadysets-icon-share"></i> <?php echo '<a href=""><span class="share-count-total">0</span> <span class="plural">'. __('Shares',NECTAR_THEME_NAME) . '</span> <span class="singular">'. __('Share',NECTAR_THEME_NAME) .'</span> </a>'; nectar_blog_social_sharing(); ?> </span>
                <span class="meta-category"><i class="icon-default-style steadysets-icon-book2"></i> <?php the_category(', '); ?></span>
                <span class="meta-comment-count"><i class="icon-default-style steadysets-icon-chat-3"></i> <a class="comments-link" href="<?php comments_link(); ?>"><?php comments_number( __('No Comments', NECTAR_THEME_NAME), __('One Comment ', NECTAR_THEME_NAME), __('% Comments', NECTAR_THEME_NAME) ); ?></a></span>
            </div><!--/single-below-header-->

            <?php }

            if($theme_skin == 'ascend') nectar_next_post_display(); ?>

            <?php if( !empty($options['author_bio']) && $options['author_bio'] == true && $theme_skin == 'ascend'){ 
                        $grav_size = 80;
                        $fw_class = 'full-width-section '; 
                        $next_post = get_previous_post();
                        $next_post_button = (!empty($options['blog_next_post_link']) && $options['blog_next_post_link'] == '1') ? 'on' : 'off';
                    ?>

                        <div id="author-bio" class="<?php echo $fw_class; if(empty($next_post) || $next_post_button == 'off' || $fullscreen_header == false && $next_post_button == 'off') echo 'no-pagination'; ?>">
                            <div class="span_12">
                                <?php if (function_exists('get_avatar')) { echo get_avatar( get_the_author_meta('email'), $grav_size ); }?>
                                <div id="author-info">
                                    <h3><span><?php if(!empty($options['theme-skin']) && $options['theme-skin'] == 'ascend') {  echo '<i>' . __('Author', NECTAR_THEME_NAME) . '</i>'; } else { _e('About', NECTAR_THEME_NAME); } ?></span> <?php the_author(); ?></h3>
                                    <p><?php the_author_meta('description'); ?></p>
                                </div>
                                <?php if(!empty($options['theme-skin']) && $options['theme-skin'] == 'ascend'){ echo '<a href="'. get_author_posts_url(get_the_author_meta( 'ID' )).'" data-hover-text-color-override="#fff" data-hover-color-override="false" data-color-override="#000000" class="nectar-button see-through-2 large">' . __("More posts by",NECTAR_THEME_NAME) . ' ' . get_the_author().' </a>'; } ?>
                                <div class="clear"></div>
                            </div>
                        </div>

             <?php } ?>


              <?php if($theme_skin == 'ascend') { ?>

                 <div class="comments-section">
                       <?php comments_template(); ?>
                 </div>   

             <?php } ?>

        </div>


       <?php if($theme_skin != 'ascend') nectar_next_post_display(); ?>

    </div><!--/container-->

</div><!--/container-wrap-->

<?php get_footer(); ?>

非常感谢任何帮助。

【问题讨论】:

    标签: php wordpress blogs


    【解决方案1】:

    您可以使用插件:https://wordpress.org/plugins/custom-post-template/

    现在你必须复制 single.php 并制作另一个模板,假设你将它命名为 blog.php 然后将它添加到你的文件顶部:

    <?php
    /** blog.php
     *
     * The Template for displaying all Blog posts.
     *
     * Template Name Posts: Blog Page
     */
    
    get_header(); ?>
    

    现在复制您的 content-single.php 并将其命名为 content-blog.php

    并在这两个自定义文件中对布局进行所有更改。

    确保当您更改模板时,您必须调用 content-blog 来代替您的 blog.php 文件模板中的 content single。 例如:

    while ( have_posts() ) {
                the_post();
                get_template_part( '/partials/content', 'blog' );
                comments_template();
            } ?>
    

    【讨论】:

    • 您好,Montiyago,感谢您的回复。已经尝试过这个插件,这只是让我可以选择我创建的不同模板。我的问题更多是关于如何重组现有的 single.php 文件,以便所有标题信息显示在全宽特征图形下方而不是在其中。
    • @Cjeffryes13:很高兴为您提供帮助,亲爱的。如果这对您有帮助,请在您的左侧打勾作为答案。
    • 对不起,我认为这没有帮助或回答我的问题
    猜你喜欢
    • 1970-01-01
    • 2012-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多