简体   繁体   中英

Wordpress - Listing of categories not working

I have an interesting one. I have a WP site that I need to grab a list of categories for to build a menu from. I've been looking around and it looks like I'm using the most agreed upon working code, and locally, it works just fine. However, once I upload it to my hosting server (MediaTemple), I find that it is NOT generating the list as I expect. I have the two sites (locally, MT) set up nearly identical, the only difference is the site on MT has MORE categories.

Here's what I have:

    <?php 
    $args=array(
      'orderby' => 'name',
      'order' => 'ASC'
      );
    $categories=get_categories($args);
    ?>

and then further down:

            <ul id="categorySubmenu">
                <?php
                foreach($categories as $cat) {
                ?>
                    <li><?php echo "<a href='" . get_category_link($cat->term_id) . "'> $cat->cat_name </a>"  ?></li>
                <?php
                }
                ?>
            </ul>

In the local site, I'm getting a list in the of all the categories I have in WP (just 2 locally), however, in the hosted site, I get nothing returned there (nothing listed, just an empty <ul></ul> )

Seems like pretty basic stuff. Is there something I'm missing?!?!

Thanks everyone!

You could change:

get_category_link($cat->term_id)

To:

get_category_link($cat->cat_ID)

Or you can simply use:

wp_list_categories();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM