为未连接的用户向我的wordpress侧边栏添加回显 [英] Add echo to my wordpress sidebar for non-connected users

查看:68
本文介绍了为未连接的用户向我的wordpress侧边栏添加回显的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不错的Login Widget,它没有指向非会员(简单访问者)的注册页面的链接。我想在侧边栏上的 Inscription 链接可视化,就在登录小部件下方,但是当有人登录时不再显示了!

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 !

这个想法是我将使用 echo 可视化链接,并通过其CSS可以将其绝对定位。

The idea is that i will visualize the link with echo and by its css i could position it absolute.

我对php一无所知,我试图在我的 sidebar.ph p文件中添加一些代码,但是它不起作用:

I do not know anything about php, i tried to add some codes in my sidebar.php file but it does not work :

sidebar.php 是经典的 twentyeleven 主题:

<?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>';
?>

然后我将css添加到链接类 inscrip-link

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 !:))

推荐答案

您的代码似乎缺少一些花括号。

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.

这篇关于为未连接的用户向我的wordpress侧边栏添加回显的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆