views:

69

answers:

2

Can someone tell me what the PHP would look like in order to get a category from Wordpress and then print it where ever I want?

I'm guessing I have to build a PHP function. Something like:

function get_a_category() {

$category = get_the_category(); <-----( not sure how to ge ta specific category )

echo $category;

}

I have no idea I know nothing about PHP

can someone help me please ?

+1  A: 

You don't have to write your own function; you do have to work with the The Loop (WordPress Codex) and a new query (Function Reference/query posts « WordPress Codex) to keep the original WP loop in place. Run this new query in a page template to get the first post from "mycategory". Change showposts to the number of posts you want.

<?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<?php the_title(); ?></a>
<?php endwhile; ?>
songdogtech
dude you're the man thanks so much!!!
Brett
A: 

Try this

function get_a_category() {
    $category = get_the_category();
    foreach ($category AS $key => $value) {
        $category_name[] = $value->cat_name;
    }
    $categories = implode(', ',$category_name);
    echo $categories;
}
Pennywise83