- Posts: 11
COMMUNITY FORUM
- Forum
- K2 Community Forum
- English K2 Community
- [SOLVED] Premium Content Items Invisible IF Not Logged In
[SOLVED] Premium Content Items Invisible IF Not Logged In
- Mars Cureg
-
- Offline
- New Member
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Chris Hogan
-
- Offline
- Premium Member
- Posts: 80
1) Where does this code below need to be put in the components/com_k2/templates/default/item.php file.
<!-- Start K2 Item Layout --> Does it go Here?......or is there a line number!
$user = JFactory::getUser();
if ($user->guest) {
echo "<p>You must login to see the content. I want your email address.</p>";
} else {
// do sth
}
2) I understand I have to: COPY THE CONTENTS of the folder /components/com_k2/templates/ and PASTE it into /templates/YOURJOOMLATEMPLATE/html/com_k2/. for the above code to work?
BUT as I don't seem to have the /com_k2 folder in my sites template folder do I just create a single directory myself and drop the CONTENTS of the folder /components/com_k2/templates in to it??
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
/templates/YOURJOOMLATEMPLATE/html/com_k2/default.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Chris Hogan
-
- Offline
- Premium Member
- Posts: 80
As for the code below, where should this be pasted to in the /components/com_k2/templates/default/item.php file - for an unregistered user to be able to view the text before the read more button.
$user = JFactory::getUser();
if ($user->guest) {
echo "<p>You must login to see the content. I want your email address.</p>";
} else {
// do sth
}
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
This post will give you a nice insight about overrides.
www.joomlaworks.net/blog/item/194-k2-inheritance-sub-templating
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Chris Hogan
-
- Offline
- Premium Member
- Posts: 80
/public_html/new/templates/MYSITESTEMPLATE/html/com_k2
BUT I still don't know how to get my Registered Content to display before a read more button?
Please any advise is welcome as I'm at a complete dead-end with this!
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Chris Hogan
-
- Offline
- Premium Member
- Posts: 80
It also says somewhere on this thread to put the code into /default/item.php file
But I cannot figure out exactly where I'm supposed to put it??
$user = JFactory::getUser();
if ($user->guest) {
echo "<p>You must login to see the content. I want your email address.</p>";
} else {
// do sth
}
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
This code is a starting point but you need a basic understanding of coding.
As to "where to put the code" you need to place it in the blocks you need to hide from public users.
Inside the else statement instead of the placeholder you should put the blocks you want hidden.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Chris Hogan
-
- Offline
- Premium Member
- Posts: 80
So which blocks are these?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
In the item.php file you can identify each block by the HTML comments.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Chris Hogan
-
- Offline
- Premium Member
- Posts: 80
I have the code below just need to know which bit to change...
<?php if($this->item->params->get('itemFullText')): ?>
<!-- Item fulltext -->
<div class="itemFullText">
<?php echo $this->item->fulltext; ?>
</div>
<?php endif; ?>
<?php else: ?>
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
<?php $user = JFactory::getUser();
if ($user->guest) {
echo "<p>You must login to see the content. I want your email address.</p>";
} else { ?>
<?php if($this->item->params->get('itemFullText')): ?>
<!-- Item fulltext -->
<div class="itemFullText">
<?php echo $this->item->fulltext; ?>
</div>
<?php endif; ?>
<?php else: ?>
<?php } ?>
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Chris Hogan
-
- Offline
- Premium Member
- Posts: 80
It also displays the intro text twice (above & below) the login text screenshot . Furthermore it has also made the item registered without myself even changing the access level to be Registered in that particular item!?
However, this in not the main issue - Because on my K2 category page, it still doesn't display my items which are set to the Registered Access level & because of this, there are no items displaying to show guests a bit of sample text with a 'register to read more button...' just like on a normal Joomla setup.
This is basically what I'm trying to replicate.
Thanks again!
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
It does not check for any specific groups.
If you need extra functionality take a look at this.
docs.joomla.org/Accessing_the_current_user_object
Now, you can replace the " echo "<p>You must login to see the content. I want your email address.</p>";" part with code that generates a module or simply enter a link.
Now as for the other blocks. The logic is:
Anything that goes inside the else block must be removed from everywhere else.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Chris Hogan
-
- Offline
- Premium Member
- Posts: 80
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
The groups (Set to the user's group ids.) is what you are looking for.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Chris Hogan
-
- Offline
- Premium Member
- Posts: 80
This has basically given me some other options via a plugin to setup in the best possible way for my site with some free areas some paid...
However, my question is to do with the way users can click an 'image' or the 'title' of an Item to get to the Items Full Text.
Now with the changes I managed so far with the item.php file, I may still be able to implement them in a way for guest users who ''click on an Items Title or Image'' for them to see my 'login message' inside of that item BUT I would need to remove the duplicate text problem I had with this before. Screenshot - goo.gl/2b8neA
Below is the item.php code which displays the login/link message and after that (in the code) is the <!-- Item text -->
Can you advise me about which part I need to look at to remove this duplicate text
<?php $user = JFactory::getUser();
if ($user->guest) {
echo '<a href="https://mysite.com/join-now">You must login to see the content!</a>';
} else { ?>
<?php if($this->item->params->get('itemFullText')): ?>
<!-- Item fulltext -->
<div class="itemFullText">
<?php echo $this->item->fulltext; ?>
</div>
<?php endif; ?>
<?php } ?>
<!-- Item text -->
<div class="itemFullText">
<?php echo $this->item->introtext; ?>
</div>
<?php endif; ?>
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
The final code should include the introtext BEFORE the full text.
<?php $user = JFactory::getUser();
if ($user->guest) {
echo '<a href="https://mysite.com/join-now">You must login to see the content!</a>';
} else { ?>
<?php if($this->item->params->get('itemFullText')): ?>
<!-- Item fulltext -->
<div class="itemFullText">
<?php echo $this->item->fulltext; ?>
</div>
<?php endif; ?>
<?php } ?>
As for linking different elements of the template (providing that you use the K2 image) you can add links manually in the category_item.php override.
<a href="<?php echo $this->item->link; ?>">
ELEMENT YOU WANT LINKED
</a>
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Forum
- K2 Community Forum
- English K2 Community
- [SOLVED] Premium Content Items Invisible IF Not Logged In