簡體   English   中英

初學者:如何將永久鏈接添加到WP_Query多個自定義帖子類型?

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

我正在制作一個非常簡單的頁面,其中顯示了多種帖子類型。 如何將永久鏈接添加到從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();
?>

另外,如果我嘗試將這些函數放在簡單的<div>元素中以設置樣式格式,則代碼也會被破壞。

像這樣簡單地使用它

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

嘗試這個:

<?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