Some variables don't get value when I put php code inside function
<p>I had 3 identical routines for creating wordpress based slides, so I pulled all my php code inside a function. And called this function with a variable.</p>

<p>Unfortunately inside function some variables don't get value, like post->ID;</p>

<p>When I remove function it works fine, can you please explain what is happening?</p>

<pre><code>&lt;?php function create_favorites_slide ($favcatname) { ?&gt;
&lt;li class="slide"&gt;

          &lt;?php

        $postslist = query_posts('posts_per_page=1&amp;post_type=post&amp;cat='.$subcategoryid.'&amp;tag=favorites');
        if ( have_posts() ) :   the_post();
      ?&gt;


     &lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;
        &lt;?php 
            if ( has_post_thumbnail() ) {
                echo get_the_post_thumbnail($post-&gt;ID, 'thumbnail', array('alt' =&gt; the_title('','',false), 'title' =&gt; get_the_excerpt(), 'class' =&gt; 'primarythumb' ));
            } else {
                echo '&lt;img width="120" height="68" class="primarythumb" alt="'.the_title("","",false).'" title="'.get_the_excerpt().'" src="'.get_bloginfo('template_url').'/thumbs/post-thumb-na.png"&gt;';
        } ?&gt;
     &lt;/a&gt;


      &lt;?php endif; ?&gt;

&lt;/li&gt;
&lt;?php } ?&gt;


&lt;?php create_favorites_slide(); ?&gt;
</code></pre>
