简体   繁体   English

初学者:如何将永久链接添加到WP_Query多个自定义帖子类型?

[英]Beginner: How to add permalink to WP_Query multiple custom post types?

I'm making a very simple page that displays multiple post types. 我正在制作一个非常简单的页面,其中显示了多种帖子类型。 How do I add permalinks to the values returned from the_post_thumbnail & the_content ? 如何将永久链接添加到从the_post_thumbnailthe_content返回的值?

    <?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();
?>

Also, if I try to place these functions in simple <div> elements to format the style it breaks the code as well. 另外,如果我尝试将这些函数放在简单的<div>元素中以设置样式格式,则代码也会被破坏。

simply use it like this 像这样简单地使用它

<?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();
?>

Try this: 尝试这个:

<?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();
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM