php - WordPress 管理栏和模板 div

标签 php html css wordpress admin

所以我创建了一个 wordpress 模板,当我登录到 wordpress 时,主菜单上有一个管理栏。这个 div 包裹了网站的其他 div。 我的问题是: 我如何设置 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');
}

?>

编辑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');
}

?>

最佳答案

要在前端的管理栏中应用top:50px,你可以试试这个(把它放在functions.php中)

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

要完全删除管理栏,你可以试试这个(把它放在functions.php)

add_filter('show_admin_bar', '__return_false');

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

add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
    if (!current_user_can('administrator') && !is_admin()) {
        show_admin_bar(false);
    }
}

您可以从 Users -> Your Profile 菜单的后端(只为您自己)设置,方法是从

中删除勾选
Show Toolbar when viewing site check box

关于php - WordPress 管理栏和模板 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19941657/

相关文章:

php - mysql 数据导入 Dojo datagrid 表

php - 从 Web 服务器接收数据不起作用( Volley 库 android)

html - 如何在 CSS 中创建点划线和点划线点线和矩形

javascript - CSS/JQuery 链接悬停不会触发

html - 在 CSS 圆圈内居中图标的更好方法

php - 未经网络许可执行php脚本

php - 从 2 个表中选择所有行,其中 field =?

php - 在我的表格中,颜色只出现在偶数行上

html - 将 anchor 标记移动到导航栏的中心

css - JavaFX TableView 更改选定的单元格颜色