2012-12-03 25 views
0

我已經創建了一個名爲「培訓」 &一個自定義分類爲同一命名爲「內容表」創建頁面Templete以顯示錶內容進行自定義分類

一個自定義後類型我需要創建一個頁面模板顯示錶的內容什麼的這樣

<div id="TableOfContents"> 
    <ul class="sections"> 
    <li> <a>Custom Taxonomy 1</a> 
     <ul class="sidenav"> 
     <li class="selected"> Child Taxonomy 1 
      <ul class="items"> 
      <li> Post Title 1 </li> 
      <li> Post Title 2 </li> 
      <li> Post Title 2 </li> 
      </ul> 
     </li> 
     <li class="selected"> Child Taxonomy 2 
      <ul class="items"> 
      <li> Post Title 1 </li> 
      <li> Post Title 2 </li> 
      <li> Post Title 2 </li> 
      </ul> 
     </li> 
     </ul> 
    </li> 
    <li> <a>Custom Taxonomy 2</a> 
     <ul class="sidenav"> 
     <li class="selected"> Child Taxonomy 1 
      <ul class="items"> 
      <li> Post Title 1 </li> 
      <li> Post Title 2 </li> 
      <li> Post Title 2 </li> 
      </ul> 
     </li> 
     <li class="selected"> Child Taxonomy 2 
      <ul class="items"> 
      <li> Post Title 1 </li> 
      <li> Post Title 2 </li> 
      <li> Post Title 2 </li> 
      </ul> 
     </li> 
     </ul> 
    </li> 
    </ul> 
</div> 

這裏是functions.php的PHP代碼,用於創建自定義分類

// Custom Taxonomy for Training 
$labels = array(
    'name'       => 'Table of Content', 
    'singular_name'     => 'Table of Content', 
    'search_items'     => 'Search Table of Content', 
    'popular_items'     => 'Popular Table of Content', 
    'all_items'      => 'All Table of Content', 
    'parent_item'     => 'Parent Table of Content', 
    'edit_item'      => 'Edit Table of Content', 
    'update_item'     => 'Update Table of Content', 
    'add_new_item'     => 'Add New Table of Content', 
    'new_item_name'     => 'New Table of Content', 
    'separate_items_with_commas' => 'Separate Table of Content with commas', 
    'add_or_remove_items'   => 'Add or remove Table of Content', 
    'choose_from_most_used'   => 'Choose from most used Table of Content' 
    ); 

$args = array(
    'label'       => 'Table of Content', 
    'labels'      => $labels, 
    'public'      => true, 
    'hierarchical'     => true, 
    'show_ui'      => true, 
    'show_in_nav_menus'    => true, 
    'args'       => array('orderby' => 'term_order'), 
    'rewrite'      => array('slug' => 'table-of-content', 'with_front' => false), 
    'query_var'      => true 
); 
register_taxonomy('tableofcontent', 'training', $args); 

謝謝小號&問候

回答

0

這裏是最後的代碼,我設法工作了:

<div class="content" role="main"> 
    <?php $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); 
     echo '<h3 class="tax-title">' . $term->name . '</h3>'; 
    ?> 
    <div id="TableOfContents"> 
     <div class="ui-boxmenu"> 
     <ul class="sections"> 
      <?php 
$taxonomyName = "tableofcontent"; 
$parent_terms = get_terms($taxonomyName, array(
    'parent' => $term->term_id, 
    'orderby' => 'menu_order', 
    'hide_empty' => false 
)); 

foreach ($parent_terms as $pterm) { 
    //Get the Child terms 
    $terms = get_terms($taxonomyName, array(
     'parent' => $term->term_id, 
     'orderby' => 'menu_order', 
     'hide_empty' => false 
    )); 
    foreach ($terms as $term) { 
     echo '<li><a>' . $term->name . '</a>'; 

     $childs = get_terms($taxonomyName, array(
      'parent' => $term->term_id, 
      'orderby' => 'menu_order', 
      'hide_empty' => false 
     )); 
     echo '<ul class="sidenav">'; 

     foreach ($childs as $child) { 
      echo '<li>' . $child->name . ''; 
       $wpq = array ('taxonomy'=>'tableofcontent','orderby' => 'menu_order','order' => 'ASC','term'=>$child->slug); 
        $myquery = new WP_Query ($wpq); 
        $article_count = $myquery->post_count; 
        if ($article_count) { 
        echo "<ul class=\"items\">"; 
        while ($myquery->have_posts()) : $myquery->the_post(); 
         echo "<li><a href=\"".get_permalink()."\">".$post->post_title."</a></li>"; 
        endwhile; 
        echo "</ul>"; 
        } 

      echo '</li>'; 
     } 

     echo '</ul>'; 


     echo '</li>'; 
    } 
} 

?> 
     </ul> 
     </div> 
    </div> 
    <script language="javascript"> 
     $('.ui-boxmenu').boxmenu(); 
    </script> 
    <script type="text/javascript"> 
     // Default add class selected to First Item in Box Menu 
     jQuery(document).ready(function($) { 
      $("ul.sections li:first").addClass("selected"); 
      $("ul.sections li:first .sidenav li:first").addClass("selected"); 
      $("ul.sections li:first .sidenav li ul.items").addClass("selected"); 
      $("ul.sections li:first .sidenav li ul.items li:first").addClass("selected"); 
     }); 
    </script> 

<?php 
$singleterm = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); 
    $args = array(
     'post_type'   => 'training', 
     'tableofcontent' => $singleterm->slug, 
     'orderby'   => 'menu_order', 
     'showposts'   => 1, 
     'order' => 'ASC', 
    ); 

    $posts = get_posts($args); 
    foreach ($posts as $post) : setup_postdata($post); 

?> 

<h2 class="content-subhead"><?php the_title() ?></h2> 
<?php the_content() ?> 

<?php endforeach; wp_reset_postdata(); ?> 

    </div> 

問候

相關問題