问题
i have Nice Login Widget which does not have any link to the registration page for non-members (simple visitors). I would like to visualize the Inscription
link on the sidebar, just under the login widget but NOT anymore when someone is logged in !
The idea is that i will visualize the link with echo
and by its css i could position it absolute.
I do not know anything about php, i tried to add some codes in my sidebar.ph
p file but it does not work :
The sidebar.php
is a classic twentyeleven
theme :
<?php
if ( 'content' != $current_layout ) :
?>
<div id="secondary" class="widget-area" role="complementary">
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<?php
if ( is_user_logged_in() ) {
echo '';
else
echo '<a class="inscrip-link" href="http://www.igorlaszlo.com/test/register/">Inscription</a>';
?>
<aside id="archives" class="widget">
<h3 class="widget-title"><?php _e( 'Archives', 'vihegay' ); ?></h3>
<ul>
<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
</ul>
</aside>
<aside id="meta" class="widget">
<h3 class="widget-title"><?php _e( 'Meta', 'vihegay' ); ?></h3>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>
</ul>
</aside>
<?php endif; // end sidebar widget area ?>
</div><!-- #secondary .widget-area -->
<?php endif; ?>
My added codes in above codes are :
<?php
if ( is_user_logged_in() ) {
echo '';
else
echo '<a class="inscrip-link" href="http://www.igorlaszlo.com/test/register/">Inscription</a>';
?>
Then i would add the css to the link class inscrip-link
:
.inscrip-link {
position:absolute;
top:300px;
left: 30%;
z-index:1;
}
Can someone tell me how to do this ? (I accept better solution as well !:))
回答1:
Your code seems to be missing a few curly brackets.
<?php
if ( !is_user_logged_in() )
{
echo '<a class="inscrip-link" href="http://www.igorlaszlo.com/test/register/">Inscription</a>';
}
?>
I have changed your code a bit. The register link will only show when a user is not logged in.
回答2:
Finally i found a better solution for my case to be able to add my link with relative position to the sidebar... if someone has the same problem :
- I added a text widget with my inscription link (#text-7) under my login widget.
- In sidebar.php I added a widget with the same id (#text-7) which gives a classe to the body when users are logged-in (see php codes below).
- In the style.css i give style to the #text-7 widget and i display:none when the body class is "logged-in" (see codes below).
PHP
<aside <?php echo (is_user_logged_in() ? 'class="widget widget_text logged-in"' : ''); ?> id="text-7" class="widget">
<h3 class="widget-title"></h3>
<div class="center"><a href="http://www.igorlaszlo.com/test/register/">Inscription</a></div>
</aside>
CSS
#text-7 {position:relative;margin: -50px auto 30px;z-index:1;}
.logged-in #text-7 {display: none;}
Together with my personal class, i also added all other classes to the widget what a widget should have (widget and widget_text) because if not, it did not work for me... maybe it is just a "handmade" code but it work fine !
来源:https://stackoverflow.com/questions/26328278/add-echo-to-my-wordpress-sidebar-for-non-connected-users