Wordpress帖子类别名称无效

时间:2014-07-11 13:01:48

标签: php wordpress

我希望这个代码在我的wordpress页面上,它应该给出“KATEGORIE”这个词,然后直接给出类别名称,但是

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

只显示“Kategorie”这个词,而后面没有任何内容。

这是整个代码:

<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>

谢谢!

1 个答案:

答案 0 :(得分:0)

嘿,你可能想尝试一下:

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