[英]How to make, an image that is pulled in by category, link to a parent posts page not to its category page it is located in. Wordpress
我是php新手('仍然在語法上苦苦掙扎:-)')和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
我認為您使用的是未設置的變量$ parent_id。
嘗試更換:
<a href="<?php get_permalink( $parent_id ); ?>"
有:
<a href="<?php get_permalink( $post->post_parent ); ?>"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.