Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

On my main page I have a few post from two categories, but I only want it to display only one

Here is my code

<?php
/* translators: used between list items, there is a space after the comma */
    $categories_list = get_the_category_list( __( ', ', 'themename' ) );
        if ( $categories_list && themename_categorized_blog() ) :
?>
<?php printf( __( '%1$s', 'themename' ), $categories_list ); ?> 

Is it possible to do it by adding this [0] in the code somewhere, if so, where?

share|improve this question
1  
Could you explain what it is you're trying to do exactly? –  Howdy_McGee Jun 5 at 13:39
    
Yes on my main page i have a few post that show two category(s) but i only want it to show one only –  H3r0k0 Jun 5 at 13:59
    
I have updated your question from your comment, but still it don't make much sense. Check my answer, if it is not what you want, please be more clearer so that I can adjust my answer accordingly –  Pieter Goosen Jun 5 at 14:05
1  
@PieterGoosen Check out the earlier question H3r0k0 asked. –  ialocin Jun 5 at 14:08
    
Thanks PieterGoosen should of linked my other question. –  H3r0k0 Jun 5 at 14:10

1 Answer 1

There are better suited functions to do what you want available.

In reference to your other, similar question, use get_the_category() like you did there. Or you can use get_categories() or wp_list_categories(). What to chose depends on your needs, for example in regards to formatting.

Btw, the question, what the main category is isn't as easy answerable, if we're talking about categories on the same level.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.