且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

仅向注册用户显示 joomla 文章,如果未登录则显示登录屏幕是

更新时间:2023-12-04 10:22:40

我要回答我自己的问题,因为我相信将来人们会需要这个,而我的解决方案只涉及一些额外代码的规则,然后你就可以将每篇文章等...设置为已注册,当用户未登录时,您将看到一个登录字段.

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... 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;
}

祝你好运!