所以我有以下代码:
<h3>
<div class="sellertitle"><a class="allseller" href="#">Something</a> </div>
<?php if ( is_user_logged_in() ) { ?>
<div class="otherseller"> <a class="allotherseller" href="#">Else</a> </div>
<?php } ?>
</h3>
然后,对于“sellertitle”,我有以下CSS:
<--logged in-->
.sellertitle {
float: left;
width: 49%;
}
如您所见,“Something”始终可见,“Else”仅在用户登录时可见。
但是,当用户注销时,我希望“sellertitle”CSS为“float:none”
<--logged out-->
.sellertitle {
float: none;
width: 49%;
}
实现这一目标的最佳方式是什么?
SO网友:Reigel
你可以试试这样的。。。这将在头部添加css
add_action(\'wp_head\', \'add_css_head\');
function add_css_head() {
if ( is_user_logged_in() ) {
?>
<style>
.sellertitle {
float: left;
width: 49%;
}
</style>
<?php
} else {
?>
<style>
.sellertitle {
float: none;
width: 49%;
}
</style>
<?php
}
}
另一个是在登录时更改类。。。
因此,您将有两个css
.sellertitle {
float: none;
width: 49%;
}
.sellertitle.logged {
float: left;
}
然后在你的div上,像这样的。。。
<div class="sellertitle <?php if ( is_user_logged_in() ) {echo \'logged\';}">