2015-12-23 44 views
1

在WordPress中我試圖使用和錨點標籤環繞使用get_Permalink()作爲href的文章。這是我的代碼到目前爲止(這是在一個循環內)。WordPress的永久環繞塊元素

echo '<a href="' .get_permalink(). '">'; 
    echo '<article class="col-xs-6 col-sm-3 port-box"> <!-- portflio article box -->'; 
      the_post_thumbnail('portfolio-thumbnail', array('class' => 'img-responsive')); 
       echo '<div class="port-details focus-box">'; 
        echo'<h3 class="latestnews-title red-border-bottom"><a href="'.get_permalink().'" title="'.get_the_title().'">'.get_the_title().'</a></h3>'; 
         echo'<p>'.get_post_meta($post->ID, 'Portfolio-type', true).'</p>'; 
         echo '<p>'; 
          echo get_post_meta($post->ID, 'Details', true); 
         echo '</p>'; 
        echo '</div>';         
       echo '</article>'; 
      echo '</a>'; 

當我在看輸出代碼它顯示了一個錨標記被輸出,但永久不會將網址放入HREF。

是否可以將文章包裝在「a」標籤中?如果有的話,任何人都有一些關於如何使其工作的指導。

感謝

回答

2

嘗試通過

get_permalink ($post->ID); 

得到的鏈接,你的代碼將

<?php $link = get_permalink ($post->ID); ?> 
    <a href="<?php echo $link ?>"> 
     <article class="col-xs-6 col-sm-3 port-box"> 
     <?php the_post_thumbnail('portfolio-thumbnail', array('class' => 'img-responsive')); ?> 
      <div class="port-details focus-box"> 
      <h3 class="latestnews-title red-border-bottom"><?php the_title(); ?></h3> 
      <p><?php echo get_post_meta($post->ID, 'Portfolio-type', true) ?></p> 
      <p><?php echo get_post_meta($post->ID, 'Details', true); ?></p> 
      </div> 
     </article> 
    </a> 

***(嘗試用這種方式它的很多清潔和保持HTML作爲HTML和PHP PHP和容易讀取和調試)

+0

Thi工作!除了我需要在第一個php行中丟失「var」之外。 – Brendin

+0

你可以建議編輯...對不起它的錯字 –

1

嘗試改變的第一行:

echo '<a href="' .get_permalink(). '">';

要:

echo '<a href="' . get_permalink($post->ID) . '">';

當您使用$post->ID來獲得的代碼位的帖子ID 。更多關於get_permalink

+0

感謝您的幫助!當我嘗試運行這段代碼時,我得到一個無效變量的錯誤。我忘記提到的一件事可能會帶來很大的變化,循環不會尋找具有特定模板的頁面的帖子。有了這個說法,我需要將「($ post-> ID)」改爲其他東西? – Brendin