show posts based similar category as the page category in wordpress

I want to show posts, that are in a similar category as the page. Here is my code (just the important php part, not html)? What is wrong?

<?php $pages = get_pages(array('child_of' => 13)); ?> 
    <?php foreach ($pages as $page): ?>
        <?php echo $page->post_title; ?>
        <?php echo $page->post_excerpt; ?>
        <?php echo $page->post_content; ?>
            <?php $categories = get_the_category($page->ID);?>
                <?php query_posts('post_type=projekt&category_name=$categories&showposts=1');?>
                    <?php while (have_posts()) : the_post(); ?> 
                        <?php the_title(); ?></a>
    <?php endforeach; ?>    

Thanx!

Related posts

Leave a Reply

2 comments

  1. try

    <?php $pages = get_pages(array('child_of' => 13)); 
    foreach ($pages as $page) {
        echo $page->post_title;
        echo $page->post_excerpt;
        echo $page->post_content;
        $categories = get_the_category($page->ID);
        query_posts('post_type=projekt&category_name='.$categories.'&showposts=1');
        while (have_posts()) : the_post(); ?>
            <a><?php the_title(); ?></a>
    <?php endwhile;
    endforeach; ?>
    
  2. without testing, this line looks incorrect:

    <?php query_posts('post_type=projekt&category_name=$categories&showposts=1');?>
    

    the $categories variable is being interpreted literally because of the single quotes

    <?php query_posts('post_type=projekt&category_name=' . $categories . '&showposts=1');?>