分類頁面的寫法 例圖和簡易說明

Screen Shot 2016-09-03 at 1.36.27 PM

<?php
/**
* A Simple Category Template
*/




function FunListCategoryPosts($category_id) {
global $post;

    //echo $category_id;
	$category_link=get_category_link($category_id); //取得category 連結
    $category_esc_url= esc_url( $category_link );
    $get_cat_name=get_cat_name($category_id);
    echo '<h1><a href="'.$category_esc_url.'" >'.$get_cat_name.'</a></h1><br>';


	$args = array( 'posts_per_page' => -1,'offset'=> 1, 'category__in' => $category_id);
	query_posts(array('category__in' => array($cat),'paged' => $paged));
    $myposts = get_posts( $args );
  
    if ( sizeof($myposts)<=0 ) : 
    else : 
        foreach ( $myposts as $post ) : setup_postdata( $post );
			echo '<article id="post-196" class="post-196 post type-post status-publish format-standard 	 has-post-thumbnail hentry category-9 clearfix"><div class="entry-thumb">';
			$tPostURL=get_permalink('',false);

				 if ( has_post_thumbnail() ) : 
				    echo '<a href="'.$tPostURL.'" > ';
				    the_post_thumbnail('',false); 
				    echo '</a>';
				 endif;  
			$the_title=the_title('', '', false);	 
			echo '</div>	
			            <div class="inner-content">	
			               <header class="entry-header">	
			                 <h1 class="entry-title">
			                    <a href="'.$tPostURL.'" rel="bookmark">'.$the_title.'
			                    </a>
			                 </h1>';
			$content1 = get_the_content();    //取得內容
			$content2 = strip_tags($content1);  // 把HTML 的標記移除
			$content3 = mb_substr($content2, 0, 100,"UTF-8"); //擷取部分utf-8內容
			echo '			</header>
			    <div class="entry-content">
					<p> 
						<div class="entry">'.$content3.'…</div>
					 </p>
				</div>
	        </div>
        </article>';
 
		endforeach; 
		wp_reset_postdata();
		echo  "<p><p><p>";


		endif; 
	}


////////////////

get_header(); ?> 
	<div id="primary" class="content-area">
		<main id="main" class="site-main" role="main">
		<header class="page-header">


<?php 
  	$category_id =  get_query_var( 'cat' ); 
	FunListCategoryPosts($category_id);   //顯示目前Category 的內容
	// start 找底下的sub ccategory
	$args = array('child_of' => $category_id);
	$categories = get_categories( $args );
	foreach($categories as $category) { 
    	//echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
    	//echo '<p> Description:'. $category->description . '</p>';
    	//echo '<p> Post Count: '. $category->count . '</p>';  

	   FunListCategoryPosts($category->term_id);   //顯示下面Category 的內容


	}
?>

		</main><!-- #main -->
	</div><!-- #primary -->









<?php get_sidebar(); ?>
<?php get_footer(); ?>
wordpress
CH02用戶資料CH03基本APICH05 分類頁面Category.phpCH09Screen Options(顯示選項)CH10外掛pluginsCH11 add_actionCH12 add_filterCH13Meta Box(自訂區塊)CH14widget(自訂模組)CH15 DBCH16AJAXCH17ShortcodeCH20 wordpress muCH30WooCommerce