【问题标题】:Display a list of custom post types titles显示自定义帖子类型标题列表
【发布时间】:2012-10-17 17:35:44
【问题描述】:

我正在使用此代码显示自定义帖子类型的列表:

    <!-- List post types -->
    <?php $args = array(
        'post_type'=>'artworks_post',
        'title_li'=> __('')
    );
    wp_list_pages( $args ); 
    ?> 

问题是我无法控制该列表,有没有其他方法可以显示自定义帖子类型标题列表,我可以控制它如何制作标记?

【问题讨论】:

  • 我希望能够将:rel="" 添加到项目列表的“a”中

标签: php javascript jquery ajax wordpress


【解决方案1】:

使用普通的WP_Query()

// The Query
$the_query = new WP_Query( 'post_type=artworks_post' );

// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
    echo '<a rel="' .the_permalink(). '" href="' .the_permalink(). ' ">'. the_title() .'</a>';
endwhile;

// Reset Post Data
wp_reset_postdata();

【讨论】:

  • 我们必须在哪个文件中编写此代码。你能告诉文件的路径吗?
  • 这取决于你的主题。如果你把这段代码放在函数文件中,它不会做太多事情。如果你将它包装在一个函数中并在你的主题中的某个地方调用该函数,它会。如果将其放入页面模板中,它将显示在具有该页面模板的任何页面上。
猜你喜欢
  • 2019-07-14
  • 2012-11-11
  • 2022-07-20
  • 1970-01-01
  • 1970-01-01
  • 2013-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多