Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 6th Apr 2010, 11:43 AM   #1
BACKLINK MOGUL
War Room Member
 
howudoin's Avatar
 
Join Date: 2008
Location: Warrior Forum
Posts: 743
Thanks: 40
Thanked 67 Times in 37 Posts
Arrow
Please Correct This WordPress (PHP) Code For Showing subcategories on Category page.
Share on: 
fb share twitter share gplus share more share

My site structure is

Category==>> Sub-Category==>> Posts (Under Sub Category)


What I want to accomplish is:

1. When somebody clicks on Category Name, they should see a list of Sub categories on Category Page.

2. Now when somebody clicks on Sub-Category Name, they should see a list of Titles of Posts filed under that Sub category.

The code which I'm using to accomplish this task is as follows:
----------------------------------------------------------------------
Code:
<?php if (is_category()) {
 = get_category();
if (get_category_children() != "") {
echo "<ul>";
wp_list_categories('orderby=id&depth=1&show_count= 0&title_li=
&use_desc_for_title=1&child_of='.);
echo "</ul>";
}
}

else{ ?>
<ul>
<?php 
;
 = get_posts('category=.&numberposts=5&order=desc');
foreach ( as ) : setup_postdata();
?>
<li><a href="<?php the_permalink();?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
<?php } 
?>
----------------------------------------------------------------------

As you can see from above, the IF statement checks whether current category has any child and displays a list of sub categories if it's true.
When IF fails, then the code enters the ELSE loop where it simply prints out the list of all posts filed under that Sub-category ID.

Now the problem is, that the IF loop works fine but when we enter the ELSE loop (That is, when somebody clicks on any Sub category), then nothing is displayed (Even though there are posts filed under that sub-category)

Can somebody help me with this?

Thanks in advance
Bhupinder
howudoin is offline  
Closed Thread


Bookmarks

Tags
category, check, code, page, showing, subcategories, wordpress


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 02:48 AM.