如何在Wordpress中没有任何链接获取媒体附件网址

时间:2016-02-12 07:18:30

标签: wordpress

我有以下代码来获取与任何类别相关联的所有媒体附件:

if file.endswith('.log'):
    with open(file,'r') as f:
        for line in f:
            pass  #Do something with each line in the opened file
    print '{} has been closed'.format(file)

但行

<?php
$attachments = get_posts($args);
if ($attachments) {
foreach ($attachments as $post) {
    setup_postdata($post);
?>
<li class='element <?php the_category($post->ID); ?>'>
              <div class="portfolio-image">
                <a href="#">
                  <?php  echo '<img class="attachment-portfolio-four wp-post-image" src="'.the_attachment_link($post->ID,false).'" height="200" width="235">'; ?>
                </a>

                <div class="mask">
                  <div class="links">
            <a data-gal="prettyPhoto[portfolios]" href="<?php the_attachment_link($post->ID); ?>"><i class="icon-resize"></i></a>
                      <a href="#">
                        <i class="icon-link"></i>
                      </a>
                  </div>
                </div>
              </div>

            </li>
<?php    } }        ?>

以HTML格式提供以下输出

<?php  echo '<img class="attachment-portfolio-four wp-post-image" src="'.the_attachment_link($post->ID,false).'" height="200" width="235">'; ?>

我只想要媒体附件网址,以便我可以随心所欲地使用它。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

这应该有效

更改

.the_attachment_link($post->ID,false).

.wp_get_attachment_url( $post->ID, true ).