创建自定义帖子类型帖子打开最新的一个
我在常见问题页面上做一个手风琴,当我打开常见问题页面我希望它打开最近的帖子,我已经为它做了一个自定义帖子类型,我不是使用任何手风琴插件,我刚从dreamweaver复制代码。 我使用的代码如下: -创建自定义帖子类型帖子打开最新的一个
<?php $recentPosts = new WP_Query(array('showposts' => 1, 'post_type' => 'FAQ'));
while($recentPosts->have_posts()) :
$recentPosts->the_post(); ?>
<div id="Accordion1" class="Accordion" tabindex="0">
<div class="AccordionPanel">
<div class="AccordionPanelTab">
<?php the_title(); ?>
</div>
<div class="AccordionPanelContent"> <?php the_content(); ?> </div>
</div>
<?php endwhile; ?>
</div>
Function.php
add_action('init', 'cptui_register_my_cpt_faq');
function cptui_register_my_cpt_faq() {
register_post_type('faq', array(
'label' => 'FAQ',
'description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'map_meta_cap' => true,
'hierarchical' => false,
'rewrite' => array('slug' => 'faq', 'with_front' => true),
'query_var' => true,
'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes','post-formats'),
'labels' => array (
'name' => 'FAQ',
'singular_name' => '',
'menu_name' => 'FAQ',
'add_new' => 'Add FAQ',
'add_new_item' => 'Add New FAQ',
'edit' => 'Edit',
'edit_item' => 'Edit FAQ',
'new_item' => 'New FAQ',
'view' => 'View FAQ',
'view_item' => 'View FAQ',
'search_items' => 'Search FAQ',
'not_found' => 'No FAQ Found',
'not_found_in_trash' => 'No FAQ Found in Trash',
'parent' => 'Parent FAQ',
)
)); }
当我使用它被硬编码这样这是工作: -
<div id="Accordion1" class="Accordion" tabindex="0">
<div class="AccordionPanel">
<div class="AccordionPanelTab">
title
</div>
<div class="AccordionPanelContent">content </div>
</div>
<div class="AccordionPanel">
<div class="AccordionPanelTab">
title
</div>
<div class="AccordionPanelContent">content </div>
</div>
</div>
如何我可以改变这个吗?
这不是什么大不了的事我刚放出来的accordion
主要div
从loop
其轻松地完成
<div id="Accordion1" class="Accordion" tabindex="0">
<?php $args = array('post_type' => 'FAQ');
$loop = new WP_Query($args);
while ($loop->have_posts()) : $loop->the_post(); ?>
<div class="AccordionPanel">
<div class="AccordionPanelTab">
<?php the_title(); ?>
</div>
<div class="AccordionPanelContent"> <?php the_content(); ?> </div>
</div>
<?php endwhile; ?>
</div> <!--Accordion1-->
只需更换单独的代码,
<div id="Accordion1" class="Accordion" tabindex="0">
<?php $recentPosts = new WP_Query(array('posts_per_page' => -1, 'post_type' => 'faq'));
while($recentPosts->have_posts()) :
$recentPosts->the_post(); ?>
<div class="AccordionPanel">
<div class="AccordionPanelTab">
<?php the_title(); ?>
</div>
<div class="AccordionPanelContent"> <?php the_content(); ?> </div>
</div>
<?php endwhile; ?>
</div>
在模板文件将这个。这将工作。 的showposts是老年人的..因此,与posts_per_page尝试..
但手风琴仍无法正常工作[你可以在这里看到](http://myluckybottle.fr/faq/) –
你能告诉我手风琴的工作html吗?所以我可以修复它。 –
但我已经提到了问题,事情! –
太好了。正如我看到静态版本找到了解决方案。有美好的一天。将问题标记为已解决。所以其他人可以使用它。 –