Can you tell me how can I insert a whole category into the specific post. for example: have 4 posts in a category "zanimljivosti" and I want to put that category to be shown inside another post not as a link but to show all 4 inside that new post. Can I do that?

  • A category is a relation, not content. Please explain better what you want.
    – fuxia
    Feb 13 '13 at 12:23
  • here is example mask.hr/?cat=62 this is a category shown but I want to show all of that inside a single post here mask.hr/?p=1320 is that posible without changing the code?
    – manic
    Feb 13 '13 at 12:38

I haven't tested the code below, but I think you could use something like it.

add_shortcode( 'show_posts_from_cat', 'wpse_85708_posts_from_cat' );

function wpse_85708_posts_from_cat( $atts ) {
        'id' => ''
    ), $atts));

    $args = array( 'category' => $id );
    $cat_posts = get_posts( $args );

    foreach( $cat_posts as $cat_post ) {
        setup_postdata( $cat_post );

        // Display code here.
        return apply_filters( 'the_excerpt', get_the_excerpt() );

In this case [show_posts_from_cat id="1"] will show all excerpts from the posts of category with id 1.

  • is there any easyer way to do that. I have a category 62 and I have a sigle new post do I have to write code every time for something like that or is there easyer way to write some shortcode inside the post so it will show post from that category inside that new post? dont know programing so well that is why I ask this. :)
    – manic
    Feb 13 '13 at 12:11
  • Are you saying that you want to add all posts from category 62 in every new post, automatically? You can always add [show_posts_from_cat id="62"] to the content of a new post to show all posts from category 62. Feb 13 '13 at 12:21
  • not in all new posts, only in post that I choose and dosent have to be always a category 62
    – manic
    Feb 13 '13 at 12:36
  • In the posts where you want to show posts from a category, add [show_posts_from_cat id="62"] to the posts content, replacing 62 with the category ID of your choice. You can use this shortcode in every posts you want. Read this article for more information about shortcodes and the use of them. Feb 13 '13 at 12:40
  • thank you wery much, I see that you understand what I want to do. :)
    – manic
    Feb 13 '13 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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