Solved

How to use PHP isset and foreach?

Posted on 2014-12-05
1
88 Views
Last Modified: 2015-01-12
This code gives me the PDF button link. I need to replicate it for a Word button link to go next to it.

The variable for the word is field_word_document_upload

The PDF variable I'm using here is field_upload

(not concerned about the CSS right now, just trying to understand how to modify it to accommodate the second button link)

  <?php if (isset($content['field_upload']['#items'])): ?>
  <div class="list-right">
    <?php foreach($content['field_upload']['#items'] as $downloads): ?>
    <div class="resultTools"><div class="label-text"><span>Downloads: </span><span class="label-text"><?php print $downloads['download_count']; ?></span></div>
      <div class="rtTop">
        <a href="<?php print file_create_url($downloads['uri']); ?>" title="Bookmark" target="_blank" class="btn btn-sm btn-danger">
          <span class=" fa fa-file-pdf-o"></span>
          <span class="icon-text">Download<span class="grid-hide"> PDF Format</span></span>
        </a>
        <!-- file_create_url(uri) -->
      </div>
    <?php endforeach; ?>
    </div>
  </div>
  <?php endif; ?>
</div>
<?php
else:
?>

Open in new window

pdf.PNG
word.PNG
0
Comment
Question by:sandshakimi
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 40484710
so, you may add this behind: ?

  <?php if (isset($content['ield_word_document_upload']['#items']))  ?>
  <div class="list-right">
    <?php foreach($content['ield_word_document_upload']['#items'] as $downloads): ?>
    <div class="resultTools"><div class="label-text"><span>Downloads: </span><span class="label-text"><?php print $downloads['download_count']; ?></span></div>
      <div class="rtTop">
        <a href="<?php print file_create_url($downloads['uri']); ?>" title="Bookmark" target="_blank" class="btn btn-sm btn-danger">
          <span class=" fa fa-file-doc-o"></span>
          <span class="icon-text">Download<span class="grid-hide"> DOC Format</span></span>
        </a>
        <!-- file_create_url(uri) -->
      </div>
    <?php endforeach; ?>
    </div>
  </div>
  <?php endif; ?>
</div>
           

Open in new window

note sure if the listing shall have both links next to each other or not...
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
php simple error message 4 24
PHP AJAX Wordpress 9 21
Display images from mysql blob type (Not working) 9 30
Cookie not unsetting 7 20
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question