2017-06-28 14 views
0

我是新來的PHP('仍然與語法鬥爭:-)')和WordPress的,我正在建立一個網站,我正在循環到我的類別頁面的所有圖像標記與該類別。我需要將圖像自動鏈接到其父文章,本質上應該是客戶端頁面。我現在使用的代碼將我鏈接到相同的類別頁面,而不是客戶端頁面。如何製作,按類別拉鍊的圖片,鏈接到父貼文頁面,而不是它所在的分類頁面。WordPress的

這是我現在用來拉圖像的代碼。

<?php 
    $query_images_args = array(
     'cat' => 3, 
     'post_type'  => 'attachment', 
     'post_mime_type' => 'image,video',//img & video files include 
     'post_status' => 'inherit', 
     'orderby'  => 'ACS', 
     'posts_per_page' => 30, 
    ); 

    $query_images = new WP_Query($query_images_args); 

    if($query_images->have_posts()) : 
     while($query_images->have_posts()) : 
      $query_images->the_post(); 
?> 


<a href="<?php get_permalink($parent_id); ?>" rel="bookmark" title="<?php the_title(); ?>"> 

     <?php echo $images = wp_get_attachment_image($query_images->posts->ID, 'thumbnail'); ?> 

</a> 

     <?php endwhile; ?> 
    <?php else : ?> 
     <p>No media file yet</p> 
    <?php endif; 

    /* Restore original Post Data */ 
    wp_reset_postdata(); ?>  

我希望這部分<a href="<?php get_permalink($parent_id); ?>將鏈接到我的客戶端頁面,但它仍然連結我的類別頁。

我認爲我的層次結構或連接方式有問題。

我還檢查該資源,但它似乎並沒有做任何事情: https://wordpress.stackexchange.com/questions/188736/get-the-title-and-url-of-the-attachment-parent-post

回答

0

我認爲你是使用未設置變量$ PARENT_ID。

嘗試更換:

<a href="<?php get_permalink($parent_id); ?>" 

有:

<a href="<?php get_permalink($post->post_parent); ?>" 
相關問題