I'm trying to automate some listings and in doing so need to run some PHP, the PHP is used to detect which category is the same as as the current page's url title then outputs the ID of the category with the same url title.
I then want to apply this ID to a list of products so that it outputs the relevent items (like categories but giving the flexibility of using Structure).
However I'm guessing because i'm defining the variable on the same page it isn't working for some reason, any ideas? My PHP parsing in template is set to "Output".
{exp:channel:entries}
{categories}{if category_url_title == "{last_segment}"}<?php $category = '{category_id}'; ?>{/if}{/categories}
{/exp:channel:entries}
{exp:channel:entries category="<?php echo $category; ?>" dynamic="no" channel="products"}
<h2>{title}</h2>
{/exp:channel:entries}