Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter drmarkwomack

    (@drmarkwomack)

    Here’s a solution:

    <?php
    $categories = get_categories();
    echo '<ul>';
        foreach($categories as $category) {
            echo '<li><a href="' . get_category_link( $category->term_id ) . '">' . $category->name.'</a>';
            echo '<span class="cat-count"> ' . $category->count . _n(' Entry', ' Entries', $category->count ) . '</span></li>';
        }
    echo '</ul>';
    ?>

    Not ideal. This code lists categories alphabetically without preserving sub-category hierarchy. But it does sort singulars from plurals.

    Thread Starter drmarkwomack

    (@drmarkwomack)

    I think I can use the _n function to sort singular and plural.

    I guess that would look something like: _n( '1 Entry', '%s Entries', $count )

    But I don’t know where or how to insert that into my code.

    Thread Starter drmarkwomack

    (@drmarkwomack)

    I know I need to replace
    Entries</span>
    with a variable that returns
    Entry</span>
    when the category count=1 and
    Entries</span>
    when the count >1.

    But I don’t know PHP well enough to figure out how to make this work.

Viewing 3 replies - 1 through 3 (of 3 total)