将社交图标添加到 PHP 中的 header

Adding Social Icons to a header in PHP

所以我对 HTML 和 CSS 非常熟悉。我正在尝试将社交图标添加到 header.php 的右上角,但它完全是用 PHP 编写的。知道我可以在哪里轻松添加 div 吗?我尝试了几种不同的方法,但都没有成功。

<!DOCTYPE html>
<?php
$lol_responsive_check = ( get_option( 'lol_check_responsive' )  == 'true' ) ? 'yes-responsive' : 'no-responsive' ;
$lol_sticky_check = ( get_option( 'lol_check_sticky' )  == 'true' ) ? 'lol-sticky-header-yes' : 'lol-sticky-header-no';
$lol_blog_layout = ( get_option( 'lol_check_blog_style' ) ) ? 'blog-' . get_option( 'lol_check_blog_style' ) : 'blog-classic';

global $lol_is_transparent;
$lol_is_transparent = '';
$lol_has_not_title = '';
$lol_page_margin_top = '';
$lol_slider = '';

if ( lollum_check_is_woocommerce() && is_shop() ) :

    $lol_shop_page_id = wc_get_page_id( 'shop' );
    $lol_slider =  get_post_meta( $lol_shop_page_id, 'lolfmkbox_slider_rev_alias', true );
    $lol_is_transparent = ( get_post_meta( $lol_shop_page_id, 'lolfmkbox_transparent_header_check', true ) == 'yes' ) ? 'header-transparent' : 'header-no-transparent';
    $lol_has_not_title = ( get_post_meta( $lol_shop_page_id, 'lolfmkbox_headline_check', true ) == 'yes' ) ? 'has-not-title' : '';

elseif ( lollum_check_is_woocommerce() && is_account_page() && ! is_user_logged_in() ) :

    global $post;
    $lol_is_transparent = ( get_post_meta( $post->ID, 'lolfmkbox_transparent_header_check', true ) == 'yes' ) ? 'header-transparent' : 'header-no-transparent';
    $lol_has_not_title = ( get_option( 'lol_bg_my_account' ) != '' ) ? 'has-not-title has-bg' : 'has-not-bg'; 

elseif ( is_home() ) :

    global $wp_query;
    $lol_page_id = $wp_query->get_queried_object_id();
    $lol_slider =  get_post_meta( $lol_page_id, 'lolfmkbox_slider_rev_alias', true );
    $lol_is_transparent = ( get_post_meta( $lol_page_id, 'lolfmkbox_transparent_header_check', true ) == 'yes' ) ? 'header-transparent' : 'header-no-transparent';
    $lol_has_not_title = ( get_post_meta( $lol_page_id, 'lolfmkbox_headline_check', true ) == 'yes' ) ? 'has-not-title' : '';
    $lol_page_margin_top = ( get_post_meta( $lol_page_id, 'lolfmkbox_page_margin_check_top', true ) == 'yes' ) ? 'no-margin-top' : '';

elseif ( is_page() ) :

    global $post;
    $lol_slider =  get_post_meta( $post->ID, 'lolfmkbox_slider_rev_alias', true );
    $lol_is_transparent = ( get_post_meta( $post->ID, 'lolfmkbox_transparent_header_check', true ) == 'yes' ) ? 'header-transparent' : 'header-no-transparent';
    $lol_has_not_title = ( get_post_meta( $post->ID, 'lolfmkbox_headline_check', true ) == 'yes' ) ? 'has-not-title' : '';
    $lol_page_margin_top = ( get_post_meta( $post->ID, 'lolfmkbox_page_margin_check_top', true ) == 'yes' ) ? 'no-margin-top' : '';

elseif ( is_single() ) :

    global $post;
    $lol_is_transparent = ( get_post_meta( $post->ID, 'lolfmkbox_transparent_header_check_post', true ) == 'yes' ) ? 'header-transparent' : 'header-no-transparent';

endif;

if ( $lol_slider != '' ) :
    $lol_has_not_title = '';
endif;
?>
<!--[if IE 8]> <html class="no-js lt-ie9 <?php echo esc_attr( $lol_responsive_check . ' ' . $lol_sticky_check . ' ' . $lol_is_transparent . ' ' . $lol_has_not_title . ' ' . $lol_blog_layout . ' ' . $lol_page_margin_top ); ?>" <?php language_attributes();?>> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js <?php echo esc_attr( $lol_responsive_check . ' ' . $lol_sticky_check . ' ' . $lol_is_transparent . ' ' . $lol_has_not_title . ' ' . $lol_blog_layout . ' ' . $lol_page_margin_top ); ?>" <?php language_attributes();?>> <!--<![endif]-->
<head>
    <meta charset="<?php bloginfo( 'charset' ); ?>">

    <?php if ( get_option( 'lol_check_responsive' ) == 'true' ) { ?>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
    <?php } ?>

    <title><?php wp_title( '|', true, 'right' ); ?></title>
    <link rel="profile" href="http://gmpg.org/xfn/11">
    <?php // if ( is_singular() && get_option( 'thread_comments' ) ) wp_enqueue_script( 'comment-reply' ); ?>
    <link rel="alternate" title="<?php printf( __( '%s RSS Feed', 'lollum' ), get_bloginfo( 'name' ) ); ?>" href="<?php bloginfo( 'rss2_url' ); ?>">
    <link rel="alternate" title="<?php printf( __( '%s Atom Feed', 'lollum' ), get_bloginfo( 'name' ) ); ?>" href="<?php bloginfo( 'atom_url' ); ?>">
    <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
    <?php if ( get_option( 'lol_custom_favicon' ) ) { ?>
        <link rel="shortcut icon" href="<?php echo esc_url( get_option( 'lol_custom_favicon' ) ); ?>">
    <?php } ?>
    <script>document.documentElement.className += " js";</script>
    <!-- BEGIN WP -->
    <?php wp_head(); ?>
    <!-- END WP -->
    <!--[if lt IE 9]>
    <script src="<?php echo get_template_directory_uri(); ?>/js/ie8.js?ver=1.0" type="text/javascript"></script>
    <![endif]-->
</head>

<body <?php body_class();?>>

<?php
    /**
    * llm_mobile_menu hook
    *
    * @hooked llm_mobile_menu - 10
    */
    do_action( 'llm_mobile_menu' );
?>

<?php
    /**
    * llm_sidebar_cart hook
    *
    * @hooked llm_sidebar_cart - 10
    */
    do_action( 'llm_sidebar_cart' );
?>

<?php
    /**
    * llm_output_content_wrapper hook
    *
    * @hooked llm_output_content_wrapper - 10
    */
    do_action( 'llm_output_content_wrapper' );
?>

<?php
    /**
    * llm_header hook
    *
    * @hooked llm_branding - 10
    * @hooked llm_submenu - 20
    */
    do_action( 'llm_header' );
?>

更新

虽然我能够添加 div,但它隐藏在 header 后面,虽然我尝试更改位置 css,但它不会移动header右上角,有什么建议吗?

在您的主题文件夹中寻找您的 header.php 文件。

在那里你应该可以对 header 进行修改。所有主题都不同,这取决于主题作者,但大多数都使用 header.php 文件。从这里开始。

Theme Development.. Header.php

Desigining Headers in Wordpress

首先,您想将图标添加到 "header" 而不是 "header.php"。 Header.php 是文件,也包含 header 部分。

如果您想在您的网站上显示某些内容,代码应位于 body 标记 (<body> CODE HERE </body>) 之间。所以你的 div 必须在那行之后:<body <?php body_class();?>>

试试这个。 我也更改了下面的 html 标记。

并添加到您的 css。

.container { position:relative; width:100%; }
.social-wrap { position:absolute; z-index:999; top:20px; right:20px; }

您不必使用这些确切的 class 名称,这只是为了示例...

<body <?php body_class();?>>
<!--add your code here-->


 <div class="container">
<div class="social-wrap">
    <ul class="social-icons>
    <li><a href="#">facebook</a></li>
    <li><a href="#">Twitter</a></li>
    </ul>
</div>
    </div>

<!--//end-->

    <?php
        /**
        * llm_mobile_menu hook
        *
        * @hooked llm_mobile_menu - 10
        */
        do_action( 'llm_mobile_menu' );
    ?>

    <?php
        /**
        * llm_sidebar_cart hook
        *
        * @hooked llm_sidebar_cart - 10
        */
        do_action( 'llm_sidebar_cart' );
    ?>

    <?php
        /**
        * llm_output_content_wrapper hook
        *
        * @hooked llm_output_content_wrapper - 10
        */
        do_action( 'llm_output_content_wrapper' );
    ?>

    <?php
        /**
        * llm_header hook
        *
        * @hooked llm_branding - 10
        * @hooked llm_submenu - 20
        */
        do_action( 'llm_header' );
    ?>