【问题标题】:feeding custom posts onto template on wordpress将自定义帖子输入到 wordpress 上的模板中
【发布时间】:2014-02-23 21:26:50
【问题描述】:

我希望将自定义帖子类型提供给自定义模板。我基本上希望后端面板上有一些带有自定义(单独)帖子类型的子部分馈送到页面上,比如新闻、博客、推荐之类的东西。

我认为我的想法是正确的,但我相信我正在解决这个错误。请原谅我,因为我通常不使用 wordpess。我基本上希望(比如说新闻页面)提供自定义帖子类型“新闻”中的所有帖子。我有一个链接到一个看起来像这样的模板的博客页面 -

 <?php
    /*
    Template Name:News*/
    ?>
    <?php get_header(); ?>
    <ul id="News">
    <?php global $post; query_posts( 'post_type=newst&orderby=ID&order=desc' ); while (have_posts()) : the_post(); ?>
    <li>

    <div class="fea_del">
        <h1><?php the_title(); ?></h1>
        <p><?php the_field('post_content',$post->ID); ?></p>
        <a <?php $p=get_permalink( $post->ID ); ?> href="<?php echo $p; ?>"class="entire_job">SEE ENTIRE ARTICLE</a>
    </div>
    </li>
     <?php endwhile; wp_reset_query(); ?>
    </ul>
    <?php get_footer(); ?>

我的博客页面中有 [display-posts] 插件,并且在正文中只有 [display-posts],希望它能提供博客中的所有帖子。我一直在努力解决这个问题,但没有成功,我不太在 wordpress 中工作,所以我在这里有点摸不着头脑。

【问题讨论】:

    标签: wordpress wordpress-theming custom-post-type


    【解决方案1】:

    你必须将$args数组传递给WP_Query,试试:

    $args = array( 'post_type' => 'news', 'order' => 'desc' );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
        the_title();
        //rest of you code
    endwhile;
    

    【讨论】:

    • 啊,这太完美了,非常感谢!我只是有一个快速跟进的问题,不管怎样,非常感谢你的帮助!我需要他们提供链接到单个帖子的标题和摘录。我的摘录是正确的,但我似乎无法为标题找出正确的措辞。这是数组中吐出条目的代码,foreach($posts_array as $detail) { echo "
    • ".$detail->post_title."
      ".$detail->post_excerpt."
    • ";我如何正确链接帖子的标题和网址?
  • 你可以使用 get_permalink() ... 当你在循环中使用 get_premalink()论据
  • 猜你喜欢
    相关资源
    最近更新 更多
    热门标签