Change permalink from wp_list_categories

UPDATE 23/05

Now im using this, its 95% completed,

Read More

Now i need to put:

<li class="child">Subcategory title </li>

on child elements of this categories, and its done 🙂

Any suggestions?

<?php
$cat_name = 'onde-encontrar';
$category = get_category_by_slug( $cat_name );
$taxonomy_name = 'category';
$term_ids = get_term_children( $category->term_id, $taxonomy_name );
foreach ( $term_ids as $term_id ) {
    $term = get_term_by( 'id', $term_id, $taxonomy_name );
    echo "<li class='cat-item'><a title='title' class='smoothScroll' name='{$term->term_id}' href='#{$term->term_id}'>{$term->name}</a></li>";
}
?>

UPDATE:

This helped me:

$cat_name = 'onde-encontrar';
$category = get_category_by_slug( $cat_name );
$taxonomies = array( 'category' );
$args = array( 'parent' => $category->term_id );
$terms = get_terms( $taxonomies, $args );
foreach ( $terms as $term ){
echo "<a title='title' href='www.era420/category/{$cat_name}/#{$term->term_id}'>{$term->name}</a>";
}

But dont print subcategories, and i want to print subcategories too.

Someone can help me?

Thanks so much

OLD:

I have this code that works perfectly for what I want, but I want the link that shows the wp_list_categories, is the id of the category and not the permalink.
For desire that when you click on the category it scroll down and does not change the main page …

My code:

<?php
$category = get_category_by_slug( 'onde-encontrar' );
wp_list_categories('title_li=&child_of='.$category->term_id);
?>

What shows me:

<a title="title" href="www.era420/category/onde-encontrar/sao-paulo/">São Paulo</a>

What i want:

 <a title="title" href="www.era420/category/onde-encontrar/#33">São Paulo</a>

something like that,

Thanks

Related posts

Leave a Reply

1 comment

  1. I would recommend creating the list using a custom function instead of the wp_list_categories() function.

    $cat_name = 'onde-encontrar';
    $category = get_category_by_slug( $cat_name );
    $taxonomy_name = 'category';
    $term_ids = get_term_children( $category->term_id, $taxonomy_name );
    foreach ( $term_ids as $term_id ) {
        $term = get_term_by( 'id', $term_id, $taxonomy_name );
        echo "<a title='title' href='www.era420/category/{$cat_name}/#{$term->term_id}'>{$term->name}</a>";
    }