Keyword

About k2 attachments

  • Meridies web
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 2 weeks ago #157628 by Meridies web
Replied by Meridies web on topic About k2 attachments
this is what i use now..


<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
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 2 weeks ago #157629 by Meridies web
Replied by Meridies web on topic About k2 attachments
where to add that code here?

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 #157636 by Krikor Boghossian
Replied by Krikor Boghossian on topic About k2 attachments
The end result should be:
  <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>

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 #157638 by Meridies web
Replied by Meridies web on topic About k2 attachments
it doesnt work it show just pdf document not word document, even if i add word document

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 #157639 by Krikor Boghossian
Replied by Krikor Boghossian on topic About k2 attachments
Sorry replace if ($pos === true) {

with if ($pos === false) {

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 #157640 by Meridies web
Replied by Meridies web on topic About k2 attachments
if i do that then i only show word documents...

dont y get it something is bad written.

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 #157642 by Meridies web
Replied by Meridies web on topic About k2 attachments
i manage to get it, when i add custom title, then it dont have that .pdf, but can i create so i get by filetpye not by title?

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
  • Meridies web's Avatar Topic Author
  • Offline
  • Junior Member
More
8 years 2 weeks ago #157643 by Meridies web
Replied by Meridies web on topic About k2 attachments
i managed to solve this, but this is only for word and pdf, do y mybe how to add excel and mybe more?

ty

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 #157644 by Meridies web
Replied by Meridies web on topic About k2 attachments
you know mybe is it possible to add more filetypes, this is only for word and pdf?

ty alot rly man

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 #157653 by Krikor Boghossian
Replied by Krikor Boghossian on topic About k2 attachments
This can serve as a starting point.
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	
}

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