Keyword

About k2 attachments

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 2 weeks ago #157578 by Meridies web
About k2 attachments was created by Meridies web
Hello i have one question , its quite easy one, before every k2 attachments i wanna some icon (best will be font awesome icons), so probably i will use word and pdf, and main thing when i add file lets say pdf in attachments ,k2 recognize its pdf and add that pdf icon or font awesome pdf icon before that title.

ty in advance

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 2 weeks ago #157597 by Krikor Boghossian
Replied by Krikor Boghossian on topic About k2 attachments
Hello,

You can use strpos php.net/manual/en/function.strpos.php in order to search through each filename or title ($attachment->title;) for a specific string like .pdf or .jpg. If it returns true you can then add the markup for an icon font.

Remember to use overrides instead of editing core files getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

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

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

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 2 weeks ago #157608 by Meridies web
Replied by Meridies web on topic About k2 attachments
can y please explain little bit more what to do, letst say i am using font awesome

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

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 2 weeks ago #157609 by Meridies web
Replied by Meridies web on topic About k2 attachments
this is my code but i have problems it wont work dunno why, i am not that good at php, can y alteast look at code.

it always show pdf icon, what i am doing wrong?
______________________________________________________

<?php
$mystring = '$attachment->title';
$findme = '.pdf';
$pos = strpos($mystring, $findme);

// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos !== false) {
echo '<i class="fa fa-file-word-o" aria-hidden="true"></i>';

} else {
echo'<i class="fa fa-file-pdf-o" aria-hidden="true"></i>';
}
?>

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 2 weeks ago #157616 by Krikor Boghossian
Replied by Krikor Boghossian on topic About k2 attachments
What does var_dump($pos); produce?

Also it should be:
$mystring = $attachment->title;

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

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

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 2 weeks ago #157620 by Meridies web
Replied by Meridies web on topic About k2 attachments
as i told i am not that good at php, can y help me and show me how to write this code, i dont know what does this produce var_dump($pos); produce,

as i told need helpw with the code, i just wanna show icon pdf if i have pdf attahcments and word icon if i have word attachments.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 2 weeks ago #157621 by Krikor Boghossian
Replied by Krikor Boghossian on topic About k2 attachments
Try this:
<?php
$mystring = $attachment->title;
$findme = '.pdf';
$pos = strpos($mystring, $findme);

// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos ===  true) {
echo '<i class="fa fa-file-word-o" aria-hidden="true"></i>';

} else {
echo'<i class="fa fa-file-pdf-o" aria-hidden="true"></i>';
}
?>

The quotes made the script to look for a string literally search for $attachment->title instead of the actual title.

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

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

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 2 weeks ago #157623 by Meridies web
Replied by Meridies web on topic About k2 attachments
where i add this code that y send me, this is item.php , where should i add that code so i always add icon before link.

i cant add here item.php code cause it say its spam, but where should i add this code?

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

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 2 weeks ago #157625 by Meridies web
Replied by Meridies web on topic About k2 attachments
and btw if i add new item lets say its docx, it always add that pdf icon

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

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 2 weeks ago #157627 by Meridies web
Replied by Meridies web on topic About k2 attachments
i think this is beacuse k2 attachments dont have that extension

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


Powered by Kunena Forum