
<div id="content-wrapper" class="blog_content-wrapper">
  <div class="blog_container clearfix">
<div id="main" class="wrapper grid_8">
    <div class="page-title"><h2><?php echo $this->__('Blog') ?></h2></div>

	<div id="primary" class="site-content">
		<div id="content" role="main">
			<?php
			$processor = Mage::getModel('core/email_template_filter');
			
			//$post_title_slug = $this->getRequest()->getParam('p');
			$currentUrl = Mage::helper('core/url')->getCurrentUrl();
			$post_title_slug = substr( $currentUrl, strrpos( $currentUrl, '/' )+1 );
			$post_data = $this->getPostDataBySlug($post_title_slug);
			$post_value = $post_data[0];

				?>
				<article id="post-29" class="blog_entry clearfix">
					<header class="blog_entry-header clearfix">
                                          <div class="blog_entry-header-inner">
						<h2 class="blog_entry-title">
							<?php echo $title = $processor->filter($post_value['title']);?>
						</h2>
                                          </div> <!--blog_entry-header-inner-->
					</header> <!--blog_entry-header clearfix-->
					<div class="entry-content">
						<?php echo $blog_content = $processor->filter($post_value['blog_content']);?>
					</div>
					<footer class="entry-meta">
						<?php echo $this->__('This entry was posted') ?>
						<?php
						$categories_selected = $post_value['categories_selected'];
						$categories_selected = explode(',', $categories_selected);
						foreach ($categories_selected as $category_key => $category_id) {
							$category_detail = $this->getCategoryById($category_id);
							//$category_url = $home_url.'blogmate/view/category/c/'.$category_detail[0]['title_slug'].'/';
							$urlKey = $category_detail[0]['title_slug'];
							$curl = Mage::getUrl('blog/view/category/c/'.$urlKey, array('_direct' => $urlKey)); 
							$cnt=Mage::getModel('blogmate/blog')->chkIfExists('index/'.$urlKey,$urlKey);
							$store_id=Mage::app()->getStore()->getId();
							if($cnt==0 && ($urlKey!=''))
							{	
								$curl1=$category_detail[0]['title_slug'];
								$rewrite = Mage::getModel('core/url_rewrite');
								$rewrite->setStoreId($store_id)
								->setIdPath('index/'.$urlKey)
								->setRequestPath($curl1)
								->setTargetPath('blog/view/category/c/'.$urlKey)
								->setIsSystem(true)
								->save();

							}
							$category_url =$curl;
							

							if($category_key==0) echo 'in ';
							else echo ', ';
							?>
							<a href="<?php echo $category_url;?>" title="View all posts in <?php echo ucfirst($category_detail[0]['title']);?>" rel="category tag"><?php echo ucfirst($category_detail[0]['title']);?></a>
						<?php
						}
						
						?>
						<?php echo $this->__('On') ?> <time class="entry-date" datetime="<?php echo date('c', strtotime($post_value['created_at']));?>"><?php echo date('M d, Y', strtotime($post_value['created_at']));?></time>.
					</footer>
				</article>
				<?php
			
			?>
			<div class="comment-content">
				<?php
					$comment_config = Mage::getStoreConfig('blogmate/comment_setting');
					if($comment_config['enabled'] && $post_value['enable_comment']) {
						echo $this->getChildHtml('blog_comments');

					}
				?>
			</div>
		</div>
	</div>

</div> <!--#main wrapper grid_8-->

        <?php
                echo $this->getChildHtml('blog_right');
        ?>

  </div> <!--blog_container clearfix-->
</div> <!--#content-wrapper-->
