2017-08-21 41 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

很高兴帮助你配对:) –

相关问题