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,但是這比我習慣的更復雜一些。任何幫助,將不勝感激。提前致謝!
感謝您的幫助,您的解決方案是,以使其發揮作用需要3樣東西1。首先,變量不是嵌套在函數中!我在函數中嵌套了變量,添加了上面修改的代碼,連接了正確的樣式表,並且完美地工作。謝謝你的幫助! – acro