如何在单个页面中显示 wordpress CPT 项目

How to show wordpress CPT items in the single page

我定义了客户 post 类型(Slug = 投资组合)。 投资组合 post 发布后,我单击查看 post,显示找不到页面。这是我的第一个问题。 我希望当用户点击一个投资组合项目时,它会在另一个页面中打开,其中包含更多详细信息。这是我的另一个问题。

这是展示作品集posts的模板页面代码(页面名称:portfolio.php)

<?php
/* Template Name: Portfolio */
$arg = array('post_type'=>'portfolio');
$loop = new WP_Query($arg);
while($loop->have_posts()):
  $loop->the_post();
  ?>
  <a href="<?php the_permalink(); ?>">show post</a>
  <br>
<?php  
endWhile;
?>

我有一个 portfolio.php 和这些代码:

<?php
$arg = array('post_type'=>'portfolio');
$loop = new WP_Query($arg);
while($loop->have_posts()):
  $loop->the_post();
  ?>
  <a href="<?php the_permalink(); ?>">show post</a>
  <br>
<?php  
endWhile;
?>

请帮帮我

您的 single-portfolio.php 代码的内容可能是这样的。

<?php
    while ( have_posts() ) : the_post();
        the_title();
        the_content();
    endwhile; // End of the loop.
?>