Forums

[resolved] subcategories posts list (3 posts)

  1. vinuel
    Member
    Posted 9 months ago #

    Hello,
    I’ve found this little piece of code and it’s exactly what I was looking for.
    Now, can anyone help me to get the titles of the posts as links
    and
    to order the posts and subcategory titles as it is usually possible with posts.
    I tried but I’m not so good in coding ...

    Here I’ve found the code:
    http://codex.wordpress.org/User:Siddharta1337/subcategoriespostsList

    and that’s the code:

    <ul>
     <?php
      $categories=  get_categories('child_of=6');  /// Parent Category number
      //echo  count($categories) . "<br />";
      foreach ($categories as $cat) {
     	$var = $cat->cat_ID ;
    	$lastposts = get_posts('category='.$var);
    	echo "<h1>".$cat->cat_name. "  (" .count($lastposts)." posts )</h1>";
    	echo "<ul>";
    		foreach($lastposts as $post){
        		setup_postdata($post);
    			echo "<li>";
    			the_title();
    			echo "</li>";
        	}
     	echo "</ul>";
      }
    
    ?>
     </ul>

    Viktor

  2. MichaelH
    moderator
    Posted 9 months ago #

    The WordPress Default Theme shows posts title as links, so look in wp-content/themes/default/index.php for an example of that.

  3. vinuel
    Member
    Posted 9 months ago #

    thanks michael

    my brother came up with this solution and its perfect for me!
    thanks brother!

    <ul>
     <?php
      $categories=  get_categories('child_of=6&order=desc');  /// Parent Category number
      foreach ($categories as $cat) {
     	$var = $cat->cat_ID ;
    	$lastposts = get_posts('category='.$var.'&orderby=date&order=dsc');
    	echo "<h1>".$cat->cat_name. "  (" .count($lastposts)." posts )</h1>";
    	echo "<ul>";
    		foreach($lastposts as $post){
        		setup_postdata($post);
            $whatweneed = $post->ID;
    			echo "<li><a href=http://www.mywordpressblog.de/archives/" . $whatweneed .">";
    			the_title();
    			echo "</a></li>";
        	}
     	echo "</ul>";
      }
    
    ?>
     </ul>

Reply

You must log in to post.

About this Topic