Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress管理栏和模板div_Php_Html_Css_Wordpress_Admin - Fatal编程技术网

Php Wordpress管理栏和模板div

Php Wordpress管理栏和模板div,php,html,css,wordpress,admin,Php,Html,Css,Wordpress,Admin,所以我创建了一个wordpress模板,当我登录wordpress时,主菜单上有一个管理栏。此分区包装了网站的其他分区。 我的问题是: 如何设置div margin top:即只有在有管理栏的情况下才设置50像素,因此有用户登录 编辑: 这是我的functions.php代码,它仍然不起作用 <?php function new_excerpt_more( $more ) { return '...<br /><br /><a href="'. get

所以我创建了一个wordpress模板,当我登录wordpress时,主菜单上有一个管理栏。此分区包装了网站的其他分区。 我的问题是: 如何设置div margin top:即只有在有管理栏的情况下才设置50像素,因此有用户登录

编辑:

这是我的functions.php代码,它仍然不起作用

<?php
function new_excerpt_more( $more ) {
    return '...<br /><br /><a href="'. get_permalink( get_the_ID() ) . '">Pročitaj još</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

?>
<?php

if(is_admin_bar_showing() && !is_admin()) {
    function link_to_stylesheet() {
        ?>
            <style type="text/css">#wrapper{margin-top:150px;}</style>
        <?php
    }
    add_action('wp_head', 'link_to_stylesheet');
}

?>

#包装{页边距顶部:150px;}
编辑2:

我也试过这个。。。它不起作用

<?php

if(is_admin_bar_showing() && !is_admin()) {
    function link_to_stylesheet() {
        ?>
        <style type="text/css">body{margin-top:150px;}</style>
        <?php
    }
    add_action('wp_head', 'link_to_stylesheet');
}

?>

正文{页边距顶部:150px;}

若要在前端应用管理栏中的
top:50px
,您可以尝试此操作(将其放入
functions.php

仅为非管理员用户从前端删除管理员栏(将其放入
functions.php

您可以从
Users->your Profile
菜单中删除复选框,从后端(仅限您自己)进行设置

Show Toolbar when viewing site check box

我通过添加

<?php if ( is_user_logged_in() ) { ?>
<style  type="text/css" media="screen">
body{margin-top:28px !important;}
</style>
<?php } ?>

正文{页边距顶部:28px!重要;}

只要有人登录并且前端有一个WPadminbar,就可以访问functions.php

将其添加到函数中。php

function adminbar_theme_setup() {
  add_theme_support( 'admin-bar', array( 'callback' => 'custom_admin_bar_css') );
}
add_action( 'after_setup_theme', 'adminbar_theme_setup' );

function custom_admin_bar_css() { ?>
<style>body{margin-top:28px !important;}</style>
<?php
}
function adminbar\u theme\u setup(){
添加主题支持('admin bar',数组('callback'=>'custom\u admin\u bar\u css');
}
添加动作('after_setup_theme'、'adminbar_theme_setup');
函数自定义\管理\栏\ css(){?>
正文{页边距顶部:28px!重要;}

我尝试了第一个代码,因为这是我想要的…但它不起作用。我的div名为wrapper,所以我把#wpadmin bar改为#wrapper and margin top:50px;但仍然不起作用…#wrapper{margin top:150px;}这将添加
top:50px
adminbar
中,仅当以登录用户的身份查看
front-end
时。它是
top:50px;
,而不是边距。您应该检查错误,这是工作代码,在我的
WordPress版本3.7
中测试。顺便问一句,您能告诉我您想要什么吗?
Show Toolbar when viewing site check box
<?php if ( is_user_logged_in() ) { ?>
<style  type="text/css" media="screen">
body{margin-top:28px !important;}
</style>
<?php } ?>
function adminbar_theme_setup() {
  add_theme_support( 'admin-bar', array( 'callback' => 'custom_admin_bar_css') );
}
add_action( 'after_setup_theme', 'adminbar_theme_setup' );

function custom_admin_bar_css() { ?>
<style>body{margin-top:28px !important;}</style>
<?php
}