2013-03-27 66 views
0

我不知道如何将图像放在下面回显的链接中。目前这显示一个链接,但我想让它成为一个可点击的图像,而不是链接。预先感谢您:)用wordpress中的图像替换链接

<div class="back-button"> 
    <?php 
     $this_page = get_post($id); 
     $parent_id = $this_page->post_parent; 
     if ($parent_id) { 
      $parent = get_page($parent_id); 
      echo '<a href="'.get_permalink($parent->ID).'" title="">'.get_the_title($parent->ID).'</a>'; 
     } 
    ?> 

我想通了!这里的解决方案:

   <?php 
       $this_page = get_post($id); 
       $parent_id = $this_page->post_parent; 
       if ($parent_id) { 
        $parent = get_page($parent_id); 
        echo '<a href="'.get_permalink($parent->ID).'" title="">'.'<img src="' . get_bloginfo("template_directory") . '/images/close-icon.png" />'.'</a>'; 
       } 
      ?>    

回答

0

你只需要包含一个标签内的img标签:

echo '<a href="'.get_permalink($parent->ID).'" title=""><img src='myImage.png'/></a>'; 

你只需要你想要的图像的URL来代替myImage.png。

+0

不幸的是这没有奏效。我相信你必须使用像:get_bloginfo(“template_directory”)。 '/images/close-icon.png我只是不知道如何将它纳入回波线。 – davidz 2013-03-27 17:37:47

0
<div class="back-button"> 
<?php 
    $this_page = get_post($id); 
    $parent_id = $this_page->post_parent; 
    if ($parent_id) { 
     $parent = get_page($parent_id); ?> <a href="#" title=""><img src="<?php bloginfo('template_directory')?>/images/imagename.gif"></a> <?php } ?> 

尝试使用这一