2016-02-12 62 views
1

我有下面的代碼獲取與任何類別相關聯的所有媒體附件:如何獲得媒體附件鏈接沒有任何鏈接在WordPress的

<?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 } }  ?> 

但線

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

捐贈遵循HTML

輸出
<a href='http://koncept.org.in/wp-content/uploads/2016/02/vishal.jpg'><img width="150" height="150" src="http://koncept.org.in/wp-content/uploads/2016/02/vishal-150x150.jpg" class="attachment-thumbnail size-thumbnail" alt="vishal" /></a><img class="attachment-portfolio-four wp-post-image" src="" height="200" width="235"></a> 

我只想要媒體附件網址,所以我可以使用我想要的。有人能幫我在這裏嗎?

回答

0

這應該工作

變化

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

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