2017-08-21 44 views
0

我正在做一個非常簡單的頁面,顯示多個帖子類型。如何將固定鏈接添加到從the_post_thumbnail返回的值& the_content初學者:如何添加永久鏈接到WP_Query多個自定義帖子類型?

<?php 
$custom_query = new WP_Query( 
    array(
    'post_type' => array('downloads', 'bjd', 'prints'), 
    ) 
); 
if ($custom_query->have_posts()) : while ($custom_query->have_posts()) : $custom_query->the_post(); 

    the_post_thumbnail('productgal-thumb'); 
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> 
    the_content(); 

endwhile; endif; wp_reset_query(); 
?> 

另外,如果我嘗試在簡單<div>元素來放置這些功能格式化它打破了代碼以及風格。

回答

0

簡單地使用這樣的

<?php 
$custom_query = new WP_Query( 
    array(
    'post_type' => array('downloads', 'bjd', 'prints'), 
    ) 
); 
if ($custom_query->have_posts()) : while ($custom_query->have_posts()) : $custom_query->the_post(); ?> 

    <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('productgal-thumb'); ?> </a> 
     <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> 
     <a href="<?php the_permalink(); ?>"><?php the_content(); ?> </a> 
<?php 
endwhile; endif; wp_reset_query(); 
?> 
+0

我做到這一點,它打破了代碼:解析錯誤:語法錯誤,意想不到的 '<' – Spear

+0

嘗試編輯ANS @ Spear – Exprator

+0

這也很精美。非常感謝! – Spear

0

試試這個:

<?php 
    $custom_query = new WP_Query( 
    array(
     'post_type' => array('downloads', 'bjd', 'prints'), 
    ) 
); 
    if ($custom_query->have_posts()) : 
    while ($custom_query->have_posts()) : $custom_query->the_post(); 

    the_post_thumbnail('productgal-thumb'); 
?> 
<a href="<?php echo get_the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> 
<?php 
    the_content(); 

    endwhile; 
    endif; 
    wp_reset_query(); 
?> 
+0

這工作很簡單。非常感謝你。 – Spear

+0

很高興幫助你配對:) –

相關問題