logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$5
Show Distinct Category Post Count

Hi,

This is my first question to this awesome community, Hope I can get an answer.

I have a situation where I need to show Distinct post count for categories.

Explanation

A post is posted into several categories as these categories are attributes for the post and then also displayed within the post and specific count pages. We are saving region wise data which include Continents and Countries as primary categorization, Apart from that every post has few more categories which are independent and fall in another parent and child categories.

The category hierarchy looks like this ..

Americas
-- United States
-- Canada
-- Mexico
Europe
-- Germany
-- France
-- Spain
Rating
-- Rating 1
-- Rating 2
-- Rating 3
-- Rating 4
Issues
-- Issue 1
-- Issue 2
-- Issue 3
-- Issue 4
-- Issue 5

Now a Post is filed under "Germany" with other categories as Europe, Rating 1, Rating 2, Issue 1, Issue 3, Issue 5 selected.

For Europe I need to create a page which lists all categories and shows count but only for posts filed under Europe.

On the home page, I am following code to display the post count for each parents, here 34 = Issues Parent Category.


<ul>
<?php
$args=array(
'orderby' => 'count',
'order' => 'DESC',
'parent' => '34',
);
$categories=get_categories($args);
foreach($categories as $category) {
echo '<li><a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.' (' . $category->count .')</a></li> ';
}
?>
</ul>


This code works great for me on the home page for each parent category, as there is no segregation and posts are counted within the category. On the Europe page I need to show/count posts in similar manner but posts, which are cross posted in categories along with Europe.

I need to show all Issues and Ratings categories with "Europe's" post count.

How can I add "Europe Category" filter to the code above, or if there is a different workaround.

Thanx

Naveenn | 02/04/13 at 12:19pm Edit
Tutorial: How to assign prize money

Previous versions of this question: 02/04/13 at 12:29pm | 02/04/13 at 12:29pm | 02/04/13 at 12:31pm

(4) Responses

Note: Naveenn felt their question was unanswered, so we granted them a refund.

Note: Naveenn requested a refund. They offered this explanation:

"I was not able to get an answer for this question. "

If no one challenges a refund request, then they are automatically granted and proccessed after 48 hours. Admins of this site only review refund requests if someone challenges the request. If you are curious about how we handled previous refund requests, you may read over all refund requests and their challenges.

See a threaded view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    02/04/13
    12:37pm
    Arnav Joy says:

    can you explain your question by giving an example , please

  • avatar
    Last edited:
    02/04/13
    6:28pm
    Abdelhadi Touil says:

    Hi.
    I'm not sure if I understand what you want, but do you mean that you want display all subcategories of a specific category when you are browsing this category?
    Example: If you are in "Europe" page (Archive), Then you'll see all post under "Europe" categories, and the page also displays all subcategories of "Europe" category with posts count.
    Look at this example:
    http://www.articledir.net/category/developing/
    What I mean is "Subcategories" section, it displays subcategories of current category (Developing in this example).
    Is that what you are looking for?

  • avatar
    Last edited:
    02/04/13
    12:53pm
    Naveenn says:

    Hi Arnav,

    I have already added an example in the question itself, I hope; I was not confusing with the example, I will try again.

    I need to show distinct post count for each category on a region specific page.

    For Europe, I have created a page and I list all "Issues" and "Rating" categories with their counts, but these counts would be wrong as these for the entire database and not just "Europe"

    If the database/site has counts;

    All posts = 50

    Europe Category = 30

    Issues
    Issues 1 = 10
    Issues 2 = 20
    Issues 3 = 10
    Issues 4 = 25
    Issues 5 = 12
    Ratings
    Rating 1 = 10
    Rating 2 = 12
    Rating 3 = 5
    Rating 4 = 8
    Rating 5 = 4

    But for Europe the following counts would be true; (example)
    Issues
    Issues 1 = 6
    Issues 2 = 12
    Issues 3 = 7
    Issues 4 = 2
    Issues 5 = 18

    Ratings
    Rating 1 = 5
    Rating 2 = 6
    Rating 3 = 15
    Rating 4 = 10
    Rating 5 = 9

    This is what wordpress does on url filter /?cat=25

    Posts counts of Category Y in Category X

  • avatar
    Last edited:
    02/04/13
    7:06pm
    Naveenn says:

    No!

    As you can see that "Issues" and "Rating" are not subcategories of Europe, instead they are at a different Parent and Child level.

    If it was for subcategories then the code I already have would easily work, that's not the case.

    I need to show Subcategories of "Issues" and "Ratings" on a "Europe Page" not archive, but the count of these subcategories should only be for posts also filed in "Europe" category.

This question has expired.





Current status of this question: Refunded



Please log in to add additional discourse to this page.





Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.