仅向注册用户显示joomla文章,如果未登录,则显示登录屏幕yes [英] Show a joomla article to registered users only, or a login screen if not logged in yes
问题描述
在Joomla 1.6之前,我可以将菜单项设置为公开及其内容:例如注册的文章。
In Joomla prior to 1.6 i could set a menu-item to public, and its contents: an article for example to registered.
这导致这样一种情况,人们可以在未登录时看到菜单中的文章的链接,但是当他们点击它时会得到一个登录组件。然后,他们看到了这篇文章。
This lead to a situation where people could see the link to an article in the menu when not logged in, but got a login component whenever they clicked it. And after that they saw the article.
在1.7这些相同的操作导致一种情况,当我单击链接时,组件屏幕保持为空。
In 1.7 these same actions lead to a situation where when I click the link the component screen just stays empty.
如果前端用户未以足够的权限登录,我如何获得注册文章显示登录屏幕?
推荐答案
我会回答自己的问题,因为我肯定会有人将来需要这个,我的解决方案只涉及一些额外的代码规则,然后你可以设置每个文章等...到注册,你会看到一个登录字段,当用户没有登录。
Im gonna answer my own question, because Im sure people will need this in the future, and my solution only involves a few rules of extra code and then you can set every article etc... to Registered and you'll see a login field when a user is not logged in.
在你的模板中,index.php放在靠近顶部的地方,它会获得你的文章的访问级别。
In your templates index.php place this near the top, it gets your article's access level.
$article =& JTable::getInstance("content");
$article->load(JRequest::getVar('id'));
$cAccLevel = $article->get("access");
然后在组件上面添加一个模块位置,只有当你需要的访问级别> 1
Then add a module position above your component, and only show it when your needed access level is > 1
<?php if($cAccLevel > 1): ?>
<jdoc:include type="modules" name="LOGIN_MODULE_POSITION" />
<?php endif; ?>
然后在模块管理器中将登录模块添加到LOGIN_MODULE_POSITION。
Then add a login module in your module manager to LOGIN_MODULE_POSITION.
Voila ...没有路由需要等等...一切正常工作,我选择风格离开注销框和操作字段像这样:
Voila... no routing needed etc... everything works out of the box, I chose to style away the logout box and action field like this:
.logout-button,
.actions{
display:none;
}
祝你好运!
这篇关于仅向注册用户显示joomla文章,如果未登录,则显示登录屏幕yes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!