通过其ID(WordPress)发布帖子

时间:2012-07-02 18:52:46

标签: php wordpress

如何通过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>

由于

1 个答案:

答案 0 :(得分:1)

您应该能够获取当前代码,将get_the_post_thumbnail($page->ID, 'home-circle')更改为get_the_post_thumbnail(get_the_id(), 'home-circle'),并为您要提交的每个帖子复制代码,修改post_id=xxx以匹配ID你要引进的帖子。

这不是最有吸引力的解决方案,但根据您提供的信息,它至少应该起作用。您知道,有一个完整的StackExchange站点致力于Wordpress:https://wordpress.stackexchange.com/您应该能够获得更多Wordpress特定的答案。如果您的问题是关于PHP的,请随时在这里询问,但如果它是Wordpress特定的,那么您最好的选择是专用的Wordpress网站。

由于您是PHP的新手,我建议您先阅读一两本入门书,然后尝试在使用WordPress之前先了解一些基本概念。虽然时间上会有更大的前期投资,但从长远来看会有所回报。祝你好运!