如何在WordPress中添加列表


How to add list in WordPress

我正在构建一个WordPress主题。我有这样的列表

<h4>Web Development</h4>
<ul class="menu" id="web_development">
<li><a target="_top" href="http://ajax/index.htm" title="Learn Ajax">Learn Ajax</a></li>
<li><a target="_top" href="http://angularjs/index.htm" title="Learn AngularJS">Learn AngularJS</a></li>
<li><a target="_top" href="http://asp.net/index.htm" title="Learn ASP.Net">Learn ASP.Net</a></li>
<li><a target="_top" href="http://backbonejs/index.htm" title="Learn BackboneJS">Learn BackboneJS</a></li>
<li><a target="_top" href="http://bootstrap/index.htm" title="bootstrap">Learn Bootstrap</a></li>
<li><a target="_top" href="http://css/index.htm" title="Learn CSS">Learn CSS</a></li>

我正在尝试这个列表到WordPress,但我没有得到确切的解决方案。我所做的是添加了自定义Post Type UI和高级自定义字段插件。

我用"课程库"的名字创建了新的帖子类型,在那里我添加了自定义字段,在编码部分我完成了这个

<?php $loop = new WP_Query( array( 'post_type' => 'course_library', 'orderby' => 'post_id', 'order' => 'ASC')); ?>
<?php while ($loop->have_posts() ) : $loop->the_post(); ?>
<div class="col-md-3">
<div style="height: 2572px;" class="featured-box">
<h4><?php echo the_field('main_heading'); ?></h4>
<ul class="menu" id="java_technologies">
<li><a target="_top" href="/"><?php echo the_field('your_topic_title_1'); ?></a></li>
</ul>
</div>
</div>
<?php endwhile; ?>

现在我可以添加新的列表,例如

**学习编程**

但它只允许我创建一个主题。我如何让它在这个标题下创建我想要的主题。

此外,我想为我创建的每个主题添加内容。我该如何为每个主题添加内容。感谢

您需要更紧密地复制第一个示例中的HTML,并且只在<li>元素上循环。它们将对查询返回的每个帖子重复。并不是说the_field()会回显该值,您不需要在代码中包含echo。使用get_field()返回字段值,而不是回显它。

<?php
// fetch courses
$courses = new WP_Query( array( 'post_type' => 'course_library', 'orderby' => 'post_id', 'order' => 'ASC'));
// do we have any courses?
if ( $course->have_posts() ){
?>
    <!-- this goes outside your loop -->
    <h4>Web Development</h4>
    <ul class="menu" id="web_development">
    <?php
    // loop over each course/post
    while ( $courses->have_posts() ){
        $courses->the_post();
        // output the <li> for this course
        ?>
        <li><a target="_top" href="<?php the_permalink(); ?>"><?php the_field('your_topic_title_1'); ?></a>
        <?php
    }
    ?>
    </ul>
    <?php
} else {
    // no courses
}
?>