0

如何在 wordpress 中通过其 ID 获取自定义帖子并显示其缩略图、标题和内容?这是我正在使用的,但内容没有搞砸。

<div class="left-cont1">
        <div class="left-cont1-text">       
            <?php
            query_posts('post_id=790&post_type=homepage');
            while (have_posts()): the_post();
            ?>
            <h1><?php the_title(); ?></h1>
          <div class="cont1-border"></div>
          <p><?php echo(types_render_field("homepage-content", array("raw"=>"true"))); ?></p>
          <h2><a href="<?php the_permalink();?>/more/"><?php echo(types_render_field("homepage-urltitle", array("raw"=>"true"))); ?></a></h2>           
        </div>
        <div class="left-cont1-image1"><?php echo get_the_post_thumbnail($page->ID, 'home-circle'); ?></div>
        <?php endwhile;?>
      </div>

谢谢

4

1 回答 1

1

You should be able to take your current code, change get_the_post_thumbnail($page->ID, 'home-circle') to get_the_post_thumbnail(get_the_id(), 'home-circle'), and replicate your code for each post you want to pull in, modifying the post_id=xxx to match the ID of the post you want to pull in.

This is not the most attractive solution, but from the information you gave, it should at least work. Just so you know, there is an entire StackExchange site devoted to Wordpress: https://wordpress.stackexchange.com/ where you should be able to get more Wordpress-specific answers. If your question is about PHP, please feel free to ask here, but if it is Wordpress-specific, your better bet would be the dedicated Wordpress site.

Since you're new to PHP, I would recommend getting an introductory book or two and try to get some of the basic concepts down pat before working with WordPress. While there will be a larger up-front investment of time, it will pay off in the long run. Good luck!

于 2012-07-02T19:31:04.750 回答