2016-05-25 12 views
0

こんにちはすべて、私はに変数を持つdivを関数に追加しようとしています。私は、HTMLをラップする必要があることを知っている、これを行うための最善の方法は何ですか?ここに関数に追加しようとしているコードを示します。divをwordpress関数に変数で追加するには?

function add_before_sidebar() { 

    <div class="acro-sidebar-preview"> 
     <div class="acro-sidebar"> 
      <div class="image-container"> 
       <div id="profile-picture-preview" class="profile-picture" style="background-image: url(<?php print $picture; ?>)"> 
     </div> 
    </div> 
     <h1 class="acro-username"><?php print $fullname; ?></h1> 
     <h2 class="acro-description"><?php print $description; ?></h2> 
    <div class="icons-wrapper"> 

    <?php print '<a href="' . $twitter . '"><img src="' . plugins_url('img/twitter.png', __FILE__) . '" ></a>' ?> 
    <?php print '<a href="' . $facebook . '"><img src="' . plugins_url('img/facebook.png', __FILE__) . '" ></a>' ?> 
    <?php print '<a href="' . $google . '"><img src="' . plugins_url('img/googleplus.png', __FILE__) . '" ></a>' ?> 

     </div> 
    </div> 
</div> 
} 
add_action('get_sidebar', 'add_before_siderbar'); 

上記のコードはすべて、変数のこのセットに接続されている私は、セットアップ

<?php 
    $picture = esc_attr(get_option('profile_picture')); 
    $firstname = esc_attr(get_option('first_name')); 
    $lastname = esc_attr(get_option('last_name')); 
    $fullname = $firstname . ' ' . $lastname; 
    $description = esc_attr(get_option('user_description')); 
    $twitter = esc_attr(get_option('twitter_handler')); 
    $facebook = esc_attr(get_option('facebook_handler')); 
    $google = esc_attr(get_option('google_handler')); 
    ?> 

コード自体を持っている機能の大外に動作します。私は関数内で変数を持つdivを書くことに精通していますが、これはもうちょっと複雑なので私は慣れています。どんな助けもありがとう。前もって感謝します!あなたはこのように書くことができ

答えて

1

:助けを

function add_before_sidebar() { 
?> 
    <div class="acro-sidebar-preview"> 
     <div class="acro-sidebar"> 
      <div class="image-container"> 
       <div id="profile-picture-preview" class="profile-picture" style="background-image: url(<?php print $picture; ?>)"> 
     </div> 
    </div> 
     <h1 class="acro-username"><?php print $fullname; ?></h1> 
     <h2 class="acro-description"><?php print $description; ?></h2> 
    <div class="icons-wrapper"> 

    <?php print '<a href="' . $twitter . '"><img src="' . plugins_url('img/twitter.png', __FILE__) . '" ></a>' ?> 
    <?php print '<a href="' . $facebook . '"><img src="' . plugins_url('img/facebook.png', __FILE__) . '" ></a>' ?> 
    <?php print '<a href="' . $google . '"><img src="' . plugins_url('img/googleplus.png', __FILE__) . '" ></a>' ?> 

     </div> 
    </div> 
</div> 
<?php } 
add_action('get_sidebar', 'add_before_siderbar'); 
+1

おかげで、あなたのソリューションは、それを動作させるために必要な3つの事の1でした。最初に、変数は関数内にネストされていませんでした!関数の変数をネストし、上で修正したコードを追加して、適切なスタイルシートを接続して、完全に機能しました。ご協力いただきありがとうございます! – acro

関連する問題