2015-11-04 49 views
0

我正在構建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,但我沒有得到確切的解決方案。我所做的是我添加了Custom Post Type UI和Advanced Custom Field Plugins。

我創造了新話題類型與「課程庫」的名字,確實我加入自定義字段,並在編碼部分,我已經做到了這一點

<?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; ?> 

現在我可以像例如

添加新的列表* *學習編程**

但它只能讓我創建一個主題。我如何讓它在該標題下創建與我想要的主題一樣多的內容。

另外我想爲我創建的每個主題添加內容。我如何讓我爲每個主題添加內容。 謝謝

+0

你使用ACF4或ACF5(專業版)? – doublesharp

+0

版本4.4.3免費 –

+0

您購買了[Repeater Field](http://www.advancedcustomfields.com/add-ons/repeater-field/)附件嗎? – doublesharp

回答

0

您需要更仔細地複製第一個示例中的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 
} 
?> 
+0

太好了。我需要安裝中繼器,然後按照此代碼正確嗎? –

+0

恩,有什麼不對。因爲代碼不起作用。我剛剛安裝了中繼器並創建了行。我在兩者上都添加了文字。但它不工作,即使main_heading也不顯示「your_topic_title_1」顯示任何內容 –