【问题标题】:WordPress Page Template Remove SidebarWordPress 页面模板删除侧边栏
【发布时间】:2016-02-17 06:17:19
【问题描述】:

使用 Ambition 的子主题版本。出于某种原因,侧边栏显示在底部。如何编辑子主题或页面模板以使侧边栏不显示。

这是现场示例的链接:http://businessblessed.com/specialoffers/sales-pages/

这是页面模板代码:

<?php
/*
Template Name: SQ w Img 2step
*/
?>
<?php
/**
 * This file displays page with no sidebar.
 *
 * @package Theme Horse
 * @subpackage Ambition
 * @since Ambition 1.0
 */
?>

<!DOCTYPE html>
<!--[if IE 7 ]>    <html lang="cs" class="ie7 no-js"> <![endif]-->
<!--[if IE 8 ]>    <html lang="cs" class="ie8 no-js"> <![endif]-->
<!--[if IE 9 ]>    <html lang="cs" class="ie9 no-js"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="cs" class="no-js"> <!--<![endif]-->
<head>
    <meta charset="utf-8" />
    <!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><![endif]-->
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <meta name="viewport" content="width=device-width; initial-scale=1.0; minimum-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
    <title>GiveAway</title>
    <link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,600,400italic,700' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="http://businessblessed.com/wp-content/themes/virtue-child/squeeze-page-w-prodImage-2step-optin/css/style.css?v=1" media="screen, projection" />
    <link rel="stylesheet" href="http://businessblessed.com/wp-content/themes/virtue-child/squeeze-page-w-prodImage-2step-optin/css/print.css?v=1" media="print" />
    <link rel="shortcut icon" href="./favicon.ico" />
    <script>document.documentElement.className = document.documentElement.className.replace('no-js', 'js');</script>
</head>
<body class="page-subpage">
    <div id="main">
        <div class="row-main">
            <div class="col col-book">
                <a href="#"><img src="http://businessblessed.com/wp-content/themes/virtue-child/squeeze-page-w-prodImage-2step-optin/img/book.png" alt="book" /></a>
            </div>
            <div class="col col-content">
                <div class="in">
                    <p class="read-this"><?php single_post_title(); ?></p>
 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content( ); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>​
                        </div>
                    </form>
                    <p class="secure">Your Information is 100% Secure And Will Never Be Shared With Anyone.</p>
                    <p class="legal"><a href="#">Legal Information</a></p>
                </div>
            </div>
        </div>
    </div>
    <!--[if lte IE 8 ]>
        <img src="http://businessblessed.com/wp-content/themes/virtue-child/squeeze-page-w-prodImage-2step-optin/img/bg.jpg" alt="" class="bg-ie" />
    <![endif]-->

    <script src="http://businessblessed.com/wp-content/themes/virtue-child/squeeze-page-w-prodImage-2step-optin/js/jquery.js?v=1"></script>
    <script src="http://businessblessed.com/wp-content/themes/virtue-child/squeeze-page-w-prodImage-2step-optin/js/app.js?v=1"></script>
    <script>
        App.run({})
    </script>
</body>
</html>

我还在父主题中找到了一个“无侧边栏”模板,但不确定是否可以应用。

<?php
/**
* This file displays page with no sidebar.
*
* @package Theme Horse
* @subpackage Ambition
* @since Ambition 1.0
*/
?>
<?php
/**
* ambition_before_loop_content
 *
 * HOOKED_FUNCTION_NAME PRIORITY
 *
 * ambition_loop_before 10
*/
do_action( 'ambition_before_loop_content' );
/**
* ambition_loop_content
 *
 * HOOKED_FUNCTION_NAME PRIORITY
 *
 * ambition_theloop 10
*/
do_action( 'ambition_loop_content' );
/**
* ambition_after_loop_content
 *
 * HOOKED_FUNCTION_NAME PRIORITY
 *
 * ambition_next_previous 5
 * ambition_loop_after 10
*/
do_action( 'ambition_after_loop_content' );
?>

【问题讨论】:

    标签: php css wordpress wordpress-theming


    【解决方案1】:

    调试 the_content() var_dump(the_content()); 并检查侧边栏数据,

    你也做错了,只有正文后面的数据你必须写在模板文件中。

    【讨论】:

    • “调试 the_content() var_dump(the_content()); 并检查侧边栏数据,”我不知道这是什么意思。我不会说 PHP。
    【解决方案2】:

    每个 WordPress 主题都提供带有侧边栏和没有侧边栏的页面模板。

    在这里,您可以轻松地使用没有侧边栏的页面模板,只需将其复制到侧边栏中即可,这将是正确的方法。

    通常 WordPress 使用 get_sidebar() 函数来显示侧边栏,因此请检查并将其从模板中删除,或者可以使用以下钩子:

    如果添加到子主题的 functions.php 文件中,这将删除 TwentyTen 主题注册的页脚侧边栏。

    function remove_some_widgets(){
        // Unregister some of the TwentyTen sidebars
        unregister_sidebar( 'first-footer-widget-area' );
        unregister_sidebar( 'second-footer-widget-area' );
    }
    add_action( 'widgets_init', 'remove_some_widgets', 11 );
    

    如果这不起作用,那么您可以简单地使用 css 隐藏侧边栏,方法是在其中获取 body 类,以便仅针对特定页面隐藏侧边栏:

    .sales_page aside {
      display : none;
    }
    

    但这肯定应该是最后的选择。

    【讨论】:

      猜你喜欢
      • 2016-12-29
      • 1970-01-01
      • 2015-11-16
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多