Keyword

Display social sharing buttons in category items

  • oshyne
  • oshyne's Avatar Topic Author
  • Offline
  • New Member
More
6 years 7 months ago - 6 years 7 months ago #163878 by oshyne
I am having issues getting the correct link to a category item when a social media button is clicked in
order to share the item to a given social media network.

Below is my url code and the result i get if for e.g. the twitter button is clicked:
url=<?php echo JURI::root() .(JRoute::_($link)) ;?>')"

The result:
Butter strawberry birthday cake http://localhost/liliesbeyond2017//liliesbeyond2017/index.php/birthday-cakes/item/6-butter-strawberry-birthday-cake

This is the variable <?php $link = K2HelperRoute::getItemRoute($this->item->id.':'.($this->item->alias)); ?> that is appended to JURI::root()
It was copied from com_k2/models/item.php around line 78 though i made some minor modifications.

My initial thinking was that i will be able to modify the variable to remove the additional domain name that is added after JURI::root() in the link but to no avail.

In another try, I read where @Krikor advised a user who had some related problem to hardcode the domain to e.g. $this->item->link but it is not working in my case.

If i enter anything other than,
JURI::root(), JURI::base(), JURI::current()
, etc the sharer popup window doesn't return any link.

Please, your assistance is highly welcomed.

Thanks in advance!
Last edit: 6 years 7 months ago by oshyne.

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

  • oshyne
  • oshyne's Avatar Topic Author
  • Offline
  • New Member
More
6 years 7 months ago - 6 years 7 months ago #163881 by oshyne
With a little looking around here and there, the code below works for category items:
<?php echo (JRoute::_($link,true, -1)) ;?>

But with a little modification to the $link variable below - removing $this-> before item:
<?php $link = K2HelperRoute::getItemRoute($item->id.':'.($item->alias)); ?>

I get the following incomplete url in tag view:

Round cottage pink birthday cake http://localhost/liliesbeyond2017/index.php/more-cakes/cakes-for-girls/item/-(incomplete without id and alias)

Please, i will need your help getting the item ID and item alias to complete the url above.

Thanks in advance!
Last edit: 6 years 7 months ago by oshyne. Reason: elaborate reply

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

  • oshyne
  • oshyne's Avatar Topic Author
  • Offline
  • New Member
More
6 years 7 months ago - 6 years 7 months ago #163889 by oshyne
Finally figured it out.

I have attached the codes and steps for anyone who needs a similar solution for category items, tag listing and item view.

if you are using "https" change <?php echo (JRoute::_($link,true, -1)) ;?>
to
<?php echo (JRoute::_($link,true, 1)) ;?>

Goodluck!!!

www.dropbox.com/s/jfhudr65ug8wqgi/k2%20social%20media%20sharing%20buttons.txt?dl=0
Last edit: 6 years 7 months ago by oshyne.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
6 years 7 months ago #163901 by Krikor Boghossian
Replied by Krikor Boghossian on topic Display social sharing buttons in category items
Kudos :)
Remember to use overrides.

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

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

More
6 years 4 months ago #165994 by Franz Heine
Replied by Franz Heine on topic Display social sharing buttons in category items
Hi oshyne

ive tried your solution, but receive a syntax error.

1. i got my code from addthis and pasted it into "'Social button' code"
2. i took the file com_k2/models/item.php.
3. row 78 i got this code:
//Read more link
$link = K2HelperRoute::getItemRoute($item->id.':'.urlencode($item->alias), $item->catid.':'.urlencode($item->category->alias));
$item->link = urldecode(JRoute::_($link));

when i put your code from dropbox, i receice a syntax error ">"

Hope you have aidea.

Thanks anyway

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

More
6 years 4 months ago #165995 by Franz Heine
Replied by Franz Heine on topic Display social sharing buttons in category items
SOLVED:

ive put following code in the category_item.php:

<?php if($this->item->params->get('itemSocialButton') && !is_null($this->item->params->get('socialButtonCode', NULL))): ?>
<!-- Item Social Button -->
<li>
<?php echo $this->item->params->get('socialButtonCode'); ?>
</li>
<?php endif; ?>


Works perfect!

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
6 years 4 months ago #166009 by Krikor Boghossian
Replied by Krikor Boghossian on topic Display social sharing buttons in category items
Nice one Franz :)

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