Category  »  Page

PowenKo > PHP > WordPress > Page > create a list all post by catogories page.

February 1, 2012   ·   0 Comments

Screen Shot 2012-02-01 at 2.56.29 PM

<?php
/**
 * Template Name: Powenko Template
 * Description: A Page Template that adds a sidebar to pages
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */

get_header(); ?>
<style type="text/css">
<!--

ol {

  margin:10px;
  padding: 10px;
  list-style-type: decimal;
	list-style-position: inside;
}
li {

  margin-left: 30px;
  padding-left: 10px;
}

-->
</style>



		<div id="primary">
			<div id="content" role="main">





<?php
function get_cat_hierchy($parent,$args){
 
    $cats = get_categories($args);
    $ret = new stdClass;
 
    foreach($cats as $cat){
        if($cat->parent==$parent){
            $id = $cat->cat_ID;
 
            $ret->$id = $cat;
            $ret->$id->children = get_cat_hierchy($id,$args);
        }
    }
 
    return $ret;
}
$args = array(
        'type'                     => 'post',
        'child_of'                 => 0,
        'hide_empty'               => false,
        'hierarchical'             => true,
        'exclude'                  => '1'
    );

		
	
	$t_parent=0;
	Display_cat_under_posts($t_parent,$args,1);
function Display_cat_under_posts($parent,$args,$i_space){	
	$retarray=get_cat_hierchy($parent,$args);
	
	foreach($retarray as $airport) {
	//   echo "<h1>".$airport->name."</h1><br>";
		foreach($airport->children as $airport2) 
		{
		 	echo "<h".$i_space.">";
			echo "<ol>";
			for($i=0;$i<$i_space;$i++){
					 echo ".";
					}
		//	echo "<a href='?cat=".$airport2->term_id."'>".$airport2->name."</a>";
			echo $airport2->name."<a href='?cat=".$airport2->term_id."'> Cate </a>";
			echo "</h".$i_space.">";
			
			
			$argsposts = array(
    'numberposts'     => 2000,
    'offset'          => 0,
    'category'        => $airport2->term_id,
    'orderby'         => 'post_date',
    'order'           => 'DESC',
    'post_type'       => 'post',
    'post_status'     => 'publish' );
	
			$postslist = get_posts( $argsposts );
			echo "<ol>";
			 foreach ($postslist as $post) :  setup_postdata($post); 
					echo "<li><a href='?p=".$post->ID."'>";
					for($i=0;$i<$i_space;$i++){
					 echo "  ";
					}
					
					
					//$thumbnail_id = get_post_thumbnail_id($post->ID);
					
					//print_r($thumbnail_id);
					//echo "<p>";
                    //$thumbnail_object = get_post($thumbail_id);
					//print_r($thumbnail_object);
					//echo $thumbnail_object->guid;
					
					
				//	$image_url = get_the_post_thumbnail_src(get_the_post_thumbnail());
					
			//echo $thumb = 
			//get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
			
			 $image_url = get_the_post_thumbnail_src(get_the_post_thumbnail( $post->ID));
			echo '<img src="'.$image_url.'" width="60" height="60" alt="'.$post->post_title.'">';
			
			
					echo $post->post_title."</a></li>";
			 endforeach;
			 //////////////
			 
			echo "</ol>";
			 
			 
			$t_space=$i_space+1;
			foreach($airport2->children as $airport3) 
			{
			//echo $airport3->term_id;
			Display_cat_under_posts( $airport->term_id ,$args,$t_space);
			}




			echo "</ol>";
			
	//	echo "<p>-------------------------------------------------------------------<p>";
		}
	}
}

function get_the_post_thumbnail_src($img)
{
  return (preg_match('~\bsrc="([^"]++)"~', $img, $matches)) ? $matches[1] : '';
}
////////////////////
 ?>
				
      <?php
	  
	  /*
	  stdClass Object (
	   [ID] => 15
	   [post_author] => 1 
	   [post_date] => 2012-01-29 06:40:54 
	   [post_date_gmt] => 2012-01-29 06:40:54 
	   [post_content] => i love android  content 
	   [post_title] => i love android title 
	   [post_excerpt] => 
	   [post_status] => publish 
	   [comment_status] => open 
	   [ping_status] => open
	   [post_password] => 
	   [post_name] => android 
	   [to_ping] => [pinged] => 
	   [post_modified] => 2012-02-01 07:36:34 
	   [post_modified_gmt] => 2012-02-01 07:36:34 
	   [post_content_filtered] => 
	   [post_parent] => 0 
	   [guid] => http://localhost/wordpress/?p=15 
	   [menu_order] => 0 
	   [post_type] => post [post_mime_type] => [comment_count] => 0 [filter] => raw )
	   
////////////////
       [ID] => 23 
	   [post_author] => 1 
	   [post_date] => 2012-02-01 18:00:34 
	   [post_date_gmt] => 2012-02-01 18:00:34 
	   [post_content] => ios test2 
	   [post_title] => ios test2 
	   [post_excerpt] => 
	   [post_status] => publish [comment_status] => open 
	   [ping_status] => open [post_password] => 
	   [post_name] => ios-test2 
	   [to_ping] => [pinged] => 
	   [post_modified] => 2012-02-01 18:00:34 
	   [post_modified_gmt] => 2012-02-01 18:00:34 
	   [post_content_filtered] => 
	   [post_parent] => 0 [guid] => http://localhost/wordpress/?p=23 
	   [menu_order] => 0 [post_type] => post [post_mime_type] => 
	   [comment_count] => 0 [filter] => raw
 	   
	   
	  */
	            


/*
stdClass Object (
 [3] => stdClass Object ( 
 	[term_id] => 3 
	[name] => IT 
	[slug] => it 
	[term_group] => 0 
	[term_taxonomy_id] => 3 
	[taxonomy] => category 
	[description] => [parent] => 0 [count] => 1 [cat_ID] => 3 
	[category_count] => 1 
	[category_description] => [cat_name] => IT [category_nicename] => it [category_parent] => 0 
	[children] => stdClass Object ( 
	              [4] => stdClass Object ( 
				         [term_id] => 4 
						 [name] => android 
						 [slug] => android 
						 [term_group] => 0
						 [term_taxonomy_id] => 4 
						 [taxonomy] => category 
						 [description] => 
						 [parent] => 3 [count] => 1 
						 [cat_ID] => 4 [category_count] => 1 
						 [category_description] => 
						 [cat_name] => android 
						 [category_nicename] => android 
						 [category_parent] => 3 
						 [children] => stdClass Object ( ) ) 
				  [5] => stdClass Object ( 
				         [term_id] => 5 
						 [name] => iOS 
						 [slug] => ios 
						 [term_group] => 0 
						 [term_taxonomy_id] => 5 
						 [taxonomy] => category 
						 [description] => 
						 [parent] => 3 
						 [count] => 1 
						 [cat_ID] => 5 
						 [category_count] => 1 
						 [category_description] => 
						 [cat_name] => iOS 
						 [category_nicename] => ios 
						 [category_parent] => 3 
						 [children] => stdClass Object ( ) ) ) ) )
*/


echo "<p><p><p><p>";



?>








<?php $image = get_post_meta($post->ID, 'thumbnail', true); ?>
                    <img src="<?php echo $image; ?>" title="<?php the_title(); ?>" />
                    <?php the_post_thumbnail(); ?>
                    
                    




				<?php while ( have_posts() ) : the_post(); ?>

					<?php get_template_part( 'content', 'page' ); ?>

					<?php comments_template( '', true ); ?>

				<?php endwhile; // end of the loop. ?>



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

<?php get_sidebar(); ?>
<?php get_footer(); ?>
shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Wordpress99

Wordpress

Amazon

adsbygoogle

Recent Posts

Categories

Amazon