Solved

How to use PHP isset and foreach?

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now