简体   繁体   English

Wordpress自定义帖子在单页上显示多个帖子

[英]Wordpress custom post showing more than one post on single page

Thanks for taking a look at my question. 谢谢你看看我的问题。

I have created a custom post that is called "movies" I have managed to get it to show a list of movies and I have created a single page called "single-movies.php" 我创建了一个名为“电影”的自定义帖子,我设法让它显示电影列表,我创建了一个名为“single-movies.php”的单页

I'm also using a plugin called Advanced Custom Fields to add fields, the problem is when I click on a movie to get more details, it shows all the movies details when I only want the one I clicked on. 我也使用一个名为高级自定义字段的插件来添加字段,问题是当我点击一部电影获取更多细节时,它显示所有电影细节,当我只想要我点击的那个。

So for example if I have 4 movies added it with the custom post, it will show all 4 movie details in the single-movies page, example: 例如,如果我有4个电影添加了自定义帖子,它将在单个电影页面中显示所有4个电影详细信息,例如:

mydomain.com/movies/avangers-2 mydomain.com/movies/avangers-2

The above url is suppose to only show me details from the avengers 2 but it shows me every single custom post I have added. 上面的网址只是向我展示了复仇者2的详细信息,但它向我展示了我添加的每一个自定义帖子。

Here's the code for single-movies.php 这是single-movies.php的代码

  <?php
    $args = array(
             'post_type' => 'movies',
             'post_status' => 'publish');

    $loop = new WP_Query( $args );

    if( $loop->have_posts() ):

    while( $loop->have_posts() ): $loop->the_post();?>

    <div class="movie-details">
     <h2><?php the_title(); ?></h2>
     <img href="<?php the_field('movie_img_url'); ?>" />
     <?php the_field('movie_synopsis', $post_id); ?>
     <?php the_field('movie_analysis', $post_id); ?>
    </div>

  <?php
     endwhile;
    endif;
  ?>

</div>

Is this a problem with the query? 这是查询的问题吗? or maybe Advanced Custom Fields is not able to display single records. 或者高级自定义字段无法显示单个记录。

I really hope this question makes sense. 我真的希望这个问题有道理。 I look forward to hearing from you, thank you in advance. 我期待着您的回复,提前感谢您。

The below will query for one post. 以下将查询一个帖子。 However, I think you are asking to get all of the posts, but get custom field info when a post is clicked on, am I right? 但是,我认为您要求获取所有帖子,但在点击帖子时获取自定义字段信息,我是对的吗? You would need javascript for that whether it's vanilla or you use JQuery. 无论是vanilla还是你使用JQuery,你都需要javascript。 I can help further if you clarify :) 如果你澄清:)我可以进一步帮助:)

$args = array(
    'post_type' => 'movies',
    'numberposts' => 1,
    'post_status' => 'publish'
);

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

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