简体   繁体   中英

Wordpress post category name not working

I want this code on my wordpress page, it should give out the word "KATEGORIE" and directly after that the category name but

<div class="cat_head"><a href="<?php echo get_bloginfo('url')."/?cat=".$cat->term_id;?>">KATEGORIE <?php echo $cat->name; ?>

does only show the word "Kategorie" and nothing behind that.

This is the whole code:

<ul id="start_header">

    <?php 
        $array = array();
        array_push($array, 1);
        array_push($array, 3);
        array_push($array, 4);
        for ($i = 0; $i<3; $i++)
        {
            $query = mysql_query("SELECT name, term_id FROM ".$table_prefix."terms WHERE term_id = '$array[$i]'");
            $cat = mysql_fetch_object($query);
            $query2 = mysql_query("SELECT wp.guid, wp.post_title, wp.post_content FROM ".$table_prefix."terms wt, ".$table_prefix."posts wp, ".$table_prefix."term_relationships wtr, ".$table_prefix."term_taxonomy wtt WHERE wt.term_id = '$array[$i]' AND wt.term_id = wtt.term_id AND wtt.term_taxonomy_id = wtr.term_taxonomy_id AND wtr.object_id = wp.ID AND post_type = 'post' ORDER BY post_date DESC LIMIT 1");
            $post = mysql_fetch_object($query2);
            $gid = substr($post->post_content, strpos($post->post_content, "=") + 1, strpos($post->post_content, "=") - 1 - strpos($post->post_content, "="));
            $query3 = mysql_query("SELECT wg.path, wp.filename, wp.alttext FROM wp_ngg_gallery wg, wp_ngg_pictures wp WHERE wg.gid = '$gid' AND wg.previewpic = wp.pid");
            $pic = mysql_fetch_object($query3);
            ?>
                <li><div class="cat_head"><a href="<?php echo get_bloginfo('url')."/?cat=".$cat->term_id;?>">KATEGORIE <?php echo $cat->name; ?></div></a><a href="<?php echo $post->guid;?>"><img src="<?php if($pic->filename != ""){echo $pic->path."/".$pic->filename;}else{echo "wp-content/themes/Dons/images/img_dummy.jpg";}?>" width="300" height="175" alt="<?php echo $pic->alttext;?>" /><h4><?php echo $post->post_title;?></h4></a></li>
            <?php
        }
    ?>
</ul>

Thanks already!

嘿,您可能想尝试:

 $cat_name = get_category(get_query_var('cat'))->name;

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