- Posts: 38
COMMUNITY FORUM
About k2 attachments
- Meridies web
-
Topic Author
- Offline
- Junior Member
ty in advance
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
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
Please Log in or Create an account to join the conversation.
- Meridies web
-
Topic Author
- Offline
- Junior Member
- Posts: 38
Please Log in or Create an account to join the conversation.
- Meridies web
-
Topic Author
- Offline
- Junior Member
- Posts: 38
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
-
- Offline
- Platinum Member
- Posts: 15920
Also it should be:
$mystring = $attachment->title;
Please Log in or Create an account to join the conversation.
- Meridies web
-
Topic Author
- Offline
- Junior Member
- Posts: 38
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
-
- Offline
- Platinum Member
- Posts: 15920
<?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.
Please Log in or Create an account to join the conversation.
- Meridies web
-
Topic Author
- Offline
- Junior Member
- Posts: 38
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
-
Topic Author
- Offline
- Junior Member
- Posts: 38
Please Log in or Create an account to join the conversation.
- Meridies web
-
Topic Author
- Offline
- Junior Member
- Posts: 38
Please Log in or Create an account to join the conversation.
- Meridies web
-
Topic Author
- Offline
- Junior Member
- Posts: 38
<ul class="itemAttachments">
<?php foreach ($this->item->attachments as $attachment): ?>
<li>
<a title= "<?php echo K2HelperUtilities::cleanHtml($attachment->titleAttribute); ?>" href="<?php echo $attachment->link; ?>"><?php echo $attachment->title; ?></a>
<?php if($this->item->params->get('itemAttachmentsCounter')): ?>
<span>(<?php echo $attachment->hits; ?> <?php echo ($attachment->hits==1) ? JText::_('K2_DOWNLOAD') : JText::_('K2_DOWNLOADS'); ?>)</span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
Please Log in or Create an account to join the conversation.
- Meridies web
-
Topic Author
- Offline
- Junior Member
- Posts: 38
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
<ul class="itemAttachments">
<?php foreach ($this->item->attachments as $attachment): ?>
<li>
<a title="<?php echo K2HelperUtilities::cleanHtml($attachment->titleAttribute); ?>" href="<?php echo $attachment->link; ?>">
<?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>';
}
?>
<?php echo $attachment->title; ?>
</a>
<?php if($this->item->params->get('itemAttachmentsCounter')): ?>
<span>(<?php echo $attachment->hits; ?> <?php echo ($attachment->hits==1) ? JText::_('K2_DOWNLOAD') : JText::_('K2_DOWNLOADS'); ?>)</span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
Please Log in or Create an account to join the conversation.
- Meridies web
-
Topic Author
- Offline
- Junior Member
- Posts: 38
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
with if ($pos === false) {
Please Log in or Create an account to join the conversation.
- Meridies web
-
Topic Author
- Offline
- Junior Member
- Posts: 38
dont y get it something is bad written.
Please Log in or Create an account to join the conversation.
- Meridies web
-
Topic Author
- Offline
- Junior Member
- Posts: 38
cause this way it only see title of document, and its ulgy if title is written with extension
Please Log in or Create an account to join the conversation.
- Meridies web
-
Topic Author
- Offline
- Junior Member
- Posts: 38
ty
Please Log in or Create an account to join the conversation.
- Meridies web
-
Topic Author
- Offline
- Junior Member
- Posts: 38
ty alot rly man
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
It checks for xls and pp (s or t) files.
$attitle = $attachment->title;
// Filenames
$pdf = '.pdf';
$doc = '.doc';
$xls = '.xls';
$ppt = '.pp';
// Check to see which filename is found
$foundpdf = strpos($pdf, $attitle);
$founddoc = strpos($doc, $attitle);
$foundxls = strpos($xls, $attitle);
$foundppt = strpos($ppt, $attitle);
// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($foundpdf === true)
{
echo '<i class="fa fa-file-pdf-o" aria-hidden="true"></i>';
}
elseif ( $founddoc === true )
{
echo'<i class="fa fa-file-word-o" aria-hidden="true"></i>';
}
elseif ( $foundxls === true )
{
// DO SOMETHING
}
elseif ( $foundppt === true )
{
// DO SOMETHING
}
else
{
// DEFAULT BEHAVIOUR
}
Please Log in or Create an account to join the conversation.