Keyword

Random and 'Next' Item link = Pulling hair out frustration

  • bringrice
  • bringrice's Avatar Topic Author
  • Offline
  • New Member
More
9 years 6 months ago #142342 by bringrice
Before I go on, THANK YOU for the constant support you've provided thousands throughout the years. A lot of people come on these forums, find their answer, and never give any sort of thanks -- so consider this a GIANT THANKS from everyone that does it!

I'm developing a site (currently located at worldovereasy.com/br3ad) and I'm running into two specific issues:

As you can see at the bottom of the page is the navigation for the site. On the right side of the logo I have 'RANDOM' and 'NEXT.'

When a user clicks 'NEXT,' I want them to be taken directly to the K2 item that is actually previous. So for example, the user clicks NEXT while they're in ID 466 and they will go to 465. Once on 465, they can click it again and it will go to 464...etc.

So essentially the NEXT will be used more of a PREVIOUS.

When users click on 'RANDOM,' they will go to a random K2 page.

My question is, how can I make this happen?

Here's what I've tried:

RANDOM:
- I've tried creating a menu item with K2 categories, then choosing random ordering, then displaying only one article -- then copy/pasting the link to see what wold happen. Essentially nothing happens, I get a blank main content area.

NEXT:
- Since the bottom nav area is actually a custom HTML module, I've I tried the obvious, pasting this in via Sourcer:
<?php if(isset($this->item->previousLink)): ?>
<a class="itemPrevious" href="<?php echo $this->item->previousLink; ?>">
NEXT
</a>
<?php endif; ?>

The error I'm getting is:
Fatal error: Using $this when not in object context in class.php on line ...

Mainly because you can't use "$this" in a static method.

I've tried to be as creative as possible to get this to work, but I'm running out of options.

Anyone else have an novel ideas? Also, I've searched these forums, the closest thing I can get to a solution is this:
www.gavick.com/forums/132/back-next-buttom-in-k2-item-14739

However it doesn't really provide any help.

Can you guys be heroes and help me out with this one? PLEASE! :D

Please Log in or Create an account to join the conversation.

More
9 years 6 months ago #142344 by Joe Campbell
Hello,

I can provide advice for the previous link part of your question. Here are a few solutions:

1) Use the Joomla Language Manager Override to replace "PREVIOUS" language string with "NEXT"

Newer Video (no dialogue)
www.youtube.com/watch?v=rNAAwToolF0

Older Video (with dialouge)
www.youtube.com/watch?v=ngUmO9zoY9A

2) Use a K2 Template Override and hardcode the word "PREVIOUS" into the link

Replace...

<?php if(isset($this->item->nextLink)): ?>
<a class="itemNext" href="<?php echo $this->item->nextLink; ?>">
<?php echo $this->item->nextTitle; ?> &raquo;
</a>
<?php endif; ?>

with...

<?php if(isset($this->item->nextLink)): ?>
<a class="itemNext" href="<?php echo $this->item->nextLink; ?>">
PREVIOUS &raquo;
</a>
<?php endif; ?>

3) Use NoNumber ReReplacer to perform a find & replace
extensions.joomla.org/extension/rereplacer


Lastly, in regards to your random item link, I would suggest that you specify which cats you want the item to be selected from, as you may not want FAQ, About Us or Contact Us to be one of the items that the script randomly selects as a link. Instead if you have a well defined structure for your website, you can then select from specific categories that you want items to be selected from such as Blog, Resources, Products, etc. The question then becomes, what method do you use to define the categories you want to select from? Do you use category names (Blog, Products,...) or category IDs (19, 21,...) to define the range? I am not certain which option would be best (optimization, flexibility, functionality), perhaps someone else can chime in on this.

I hope this helps,

Joe Campbell

Please Log in or Create an account to join the conversation.

  • bringrice
  • bringrice's Avatar Topic Author
  • Offline
  • New Member
More
9 years 6 months ago #142346 by bringrice
JOSEPH! Thank you for the thorough response! I haven't tried any of what you suggested, but I'll have a look at it now!

Thanks once again!

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 6 months ago #142360 by Krikor Boghossian
Replied by Krikor Boghossian on topic Random and 'Next' Item link = Pulling hair out frustration

When a user clicks 'NEXT,' I want them to be taken directly to the K2 item that is actually previous. So for example, the user clicks NEXT while they're in ID 466 and they will go to 465. Once on 465, they can click it again and it will go to 464...etc.


The next item/ previous item link is the next/ previous item in this given category.

I think you need a custom K2 plugin which will pull the next/ items per ID and not per category. as for the random link I would suggest that you pull it from the 100 - 200 latest so you won't slow your site down.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • bringrice
  • bringrice's Avatar Topic Author
  • Offline
  • New Member
More
9 years 6 months ago #142472 by bringrice

Krikor wrote:

When a user clicks 'NEXT,' I want them to be taken directly to the K2 item that is actually previous. So for example, the user clicks NEXT while they're in ID 466 and they will go to 465. Once on 465, they can click it again and it will go to 464...etc.


The next item/ previous item link is the next/ previous item in this given category.

I think you need a custom K2 plugin which will pull the next/ items per ID and not per category. as for the random link I would suggest that you pull it from the 100 - 200 latest so you won't slow your site down.


Thanks Krikor! Good advice about the random link, whenever I can get it to work :D

Please Log in or Create an account to join the conversation.

  • bringrice
  • bringrice's Avatar Topic Author
  • Offline
  • New Member
More
9 years 6 months ago #142473 by bringrice
Thanks for the advice Joseph.

Essentially what I want to do is move the itemnavigation to the default.php instead of the item.php that it resides in. Specifically, I want to place it in a module position.

That's ultimately what I want to do. I've tried doing it, and it simply won't render.

Joseph wrote: Hello,

I can provide advice for the previous link part of your question. Here are a few solutions:

1) Use the Joomla Language Manager Override to replace "PREVIOUS" language string with "NEXT"

Newer Video (no dialogue)
www.youtube.com/watch?v=rNAAwToolF0

Older Video (with dialouge)
www.youtube.com/watch?v=ngUmO9zoY9A

2) Use a K2 Template Override and hardcode the word "PREVIOUS" into the link

Replace...

<?php if(isset($this->item->nextLink)): ?>
<a class="itemNext" href="<?php echo $this->item->nextLink; ?>">
<?php echo $this->item->nextTitle; ?> &raquo;
</a>
<?php endif; ?>

with...

<?php if(isset($this->item->nextLink)): ?>
<a class="itemNext" href="<?php echo $this->item->nextLink; ?>">
PREVIOUS &raquo;
</a>
<?php endif; ?>

3) Use NoNumber ReReplacer to perform a find & replace
extensions.joomla.org/extension/rereplacer


Lastly, in regards to your random item link, I would suggest that you specify which cats you want the item to be selected from, as you may not want FAQ, About Us or Contact Us to be one of the items that the script randomly selects as a link. Instead if you have a well defined structure for your website, you can then select from specific categories that you want items to be selected from such as Blog, Resources, Products, etc. The question then becomes, what method do you use to define the categories you want to select from? Do you use category names (Blog, Products,...) or category IDs (19, 21,...) to define the range? I am not certain which option would be best (optimization, flexibility, functionality), perhaps someone else can chime in on this.

I hope this helps,

Joe Campbell

Please Log in or Create an account to join the conversation.

More
9 years 6 months ago #142479 by Joe Campbell
Howdy,

Now I know why you're pulling your hair out...

You can not move the K2 item navigation code from item.php into your template default.php file.
K2 code can only live in K2 template files [and] K2 Content Modules.

Krikor, please chime if I am incorrect.

The solutions I previously mentioned are your best bet for modifying the link within the item.php file:
www.joomlaworks.net/forum/k2-en/40827-random-and-next-item-link-pulling-hair-out-frustration/reply#142344

As for a module solution, you can try this:
extensions.joomla.org/extensions/extension/extension-specific/k2-extensions/bnr-content-for-k2

Or you can try cloning the html rendering for the link using jquery:
techjoomla.com/beyond-joomla/add-multipal-html-element-using-jquery.html

I hope this helps,

Joe Campbell

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 6 months ago #142512 by Krikor Boghossian
Replied by Krikor Boghossian on topic Random and 'Next' Item link = Pulling hair out frustration
You are correct, each component's code only executes within that component. That is a Joomla! thing not a K2 one.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum