Solved

How to use PHP isset and foreach?

Posted on 2014-12-05
1
92 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 143

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

827 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