【问题标题】:generating links dynamically动态生成链接
【发布时间】:2012-09-18 20:07:33
【问题描述】:

所以我想这对你们大多数人来说很容易,但我想不通。

我试图使链接动态,例如:href="linkname(#1 or #2 etc)"

有什么想法吗?

 <?php if ($top_fundraisers && is_array($top_fundraisers)): ?>
        <?php foreach ($top_fundraisers as $index => $fundraiser): ?>
           <a title="" class="fancybox" href="linkname(GENERATE CODE HERE)">
        <div class="top-fundraiser">

            <div id="newo<?php print htmlentities($index + 1); ?>" class="top-fundraiser-image">
              <img src="<?php
          if($fundraiser['member_pic_medium']) {
                  print htmlentities($fundraiser['member_pic_medium']);
          } else {
            print $template_dir . '/images/portrait_placeholder.png';
          }
              ?>"/>
            </div>
    </div>
    </a>
        <?php endforeach;?>
    <?php endif; ?>

【问题讨论】:

  • GENERATE CODE HERE 应该是什么?
  • @tradyblix href="linkname(#1 or #2 etc)"
  • 试试这个&lt;?php echo myLink; ?&gt;,其中myLink是一个保存链接的变量或&lt;?php echo getLink() ?&gt;,其中getLink是一个返回链接而不是linkname(GENERATE CODE HERE)的函数

标签: php html dynamic-links


【解决方案1】:

假设下面是您需要的。

 <?php if ($top_fundraisers && is_array($top_fundraisers)): ?>
        <?php foreach ($top_fundraisers as $index => $fundraiser): ?>
           <a title="" class="fancybox" href="linkname(#<?php echo $index + 1; ?>)">
        <div class="top-fundraiser">

            <div id="newo<?php print htmlentities($index + 1); ?>" class="top-fundraiser-image">
              <img src="<?php
          if($fundraiser['member_pic_medium']) {
                  print htmlentities($fundraiser['member_pic_medium']);
          } else {
            print $template_dir . '/images/portrait_placeholder.png';
          }
              ?>"/>
            </div>
    </div>
    </a>
        <?php endforeach;?>
    <?php endif; ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-23
    • 1970-01-01
    • 1970-01-01
    • 2011-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-10
    相关资源
    最近更新 更多