2

i'm new to wordpress, and i don't know how to code. I would like to make a page where all my animes are sorted by alphabet, like in this image Example

I've heard about the wp_list_category function, so i made a separate category for each anime. Now the problem is, i dont know how to use the function to make such alphabetic list, as i dont have any experience in coding, so can someone please tell me how to do that?

Thanks in advance

EDIT= So i've did some search on google, and made this script, but it doesn't work yet, can someone explain what's wrong in this script?

<?php
$args = [
    'category_name' => 'on-going',
    '_name__like'   => 'A'   
$terms = get_terms( 'category', $args );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
    $count = count( $terms );
    $i = 0;
    $term_list = '<p class="my_term-archive">';
    foreach ( $terms as $term ) {
        $i++;
        $term_list .= '<a href="' . get_term_link( $term ) . '" title="' . sprintf( __( 'View all post filed under %s', 'my_localization_domain' ), $term->name ) . '">' . $term->name . '</a>';
        if ( $count != $i ) {
            $term_list .= ' &middot; ';
        }
        else {
            $term_list .= '</p>';
        }
    }
    echo $term_list;
} ?>

This script looks so complicated for me, haven't seen one like this before :/

EDIT: Used this script in the end, thanks for all the help

$terms = get_terms('anime-on-going');

if ( !empty( $terms ) && !is_wp_error( $terms ) ){    
$term_list = [];    
foreach ( $terms as $term ){
    $first_letter = strtoupper($term->name[0]);
    $term_list[$first_letter][] = $term;
}
unset($term);

echo '<ul class="my_term-archive">';

    foreach ( $term_list as $key=>$value ) {
        echo '<h2 class="term-letter">' . $key . '</h2>';

        foreach ( $value as $term ) {
            echo '<li><a href="' . get_term_link( $term ) . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . '</a></li>';
        }
    }

echo '</ul>';
} 
9
  • 3
    >i'm new to wordpress, and i don't know how to code. Step 1st. Learn how to code. php.net & mysql.com offer nice documentation. Commented Jun 9, 2015 at 10:37
  • IIRC this has been answered before. Use the site search Commented Jun 9, 2015 at 10:52
  • Thanks for the advice, i'm also learning as i'm making this website. So far i've made several things on my website, but this wp_list_categories function is a bit complicated, so some assistance would help me to learn :)
    – Yahya98
    Commented Jun 9, 2015 at 10:53
  • Sorry, but i've did search before posting this, but i can't find any answer that fix my problem. I dont know if i were searching with the wrong keyword though.
    – Yahya98
    Commented Jun 9, 2015 at 10:58
  • Maybe taking a look at the codex for a start at wp list categories helps. This get terms gives also info. After that you maybe look here also.
    – Charles
    Commented Jun 9, 2015 at 14:25

1 Answer 1

3

So, i used this script in the end, thanks to Pieter Goosen's post Category Alphabet List Broken

$terms = get_terms('anime-on-going');

if ( !empty( $terms ) && !is_wp_error( $terms ) ){    
$term_list = [];    
foreach ( $terms as $term ){
    $first_letter = strtoupper($term->name[0]);
    $term_list[$first_letter][] = $term;
}
unset($term);

echo '<ul class="my_term-archive">';

    foreach ( $term_list as $key=>$value ) {
        echo '<h2 class="term-letter">' . $key . '</h2>';

        foreach ( $value as $term ) {
            echo '<li><a href="' . get_term_link( $term ) . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">'     . $term->name . '</a></li>';
        }
    }

echo '</ul>';
} 
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.