• Hi,
    I am usinga custom Cms for my site and have wordpress as a blog. I want to fetch posts from wordpress blog into my main site according to category.
    For Instance,
    I have a service name tattoos on my main site and I have created the same category of tatoos in the blog. So I want to fetch the posts from tattoos and display that on my main site

    <?php $arra=explode('-',$_GET['page_url']);
    			$test=implode(' ',$arra);
    
    			$SQL = "select <code>post_content</code>, <code>post_title</code>,<code>post_name</code> from <code>blog_posts</code> WHERE  <code>post_type</code>='post' and <code>post_status</code>='publish' and ( post_content like '%".ucfirst($test)."%' or post_title like '%".ucfirst($test)."%') order by <code>post_date</code>";
    
    		if($parent_url == "services")
    		{
    			//echo 'pageurl==='.$page_url.'----';
    			$sql_1  	= "SELECT term_id  FROM <code>blog_terms</code>  where slug like '%".$page_url."%'";
    
    $sql_1.'<br><br>';
    	$data_1 	= $objDB->setQuery($sql_1);
    			$data_res	= $objDB->select();
    
    			$where_clause_1 = array();
    			$c = 0;
    			for($i=0;$i<count($data_res);$i++)
    			{
    				$where_clause_1[] = " <code>term_taxonomy_id</code>='".$data_res[$i]['term_id']."' ";
    				$c++;
    			}
    			if($c > 0){
    				$where_clause_2 =" and ( ". implode(" or ",$where_clause_1)." ) ";
    			}
    			$SQL = "select <code>post_content</code>, ID, <code>post_title</code>,<code>post_name</code> from <code>blog_posts</code>  AS bp, blog_term_relationships AS btr WHERE bp.ID = btr.object_id and <code>post_type</code>='post' ".$where_clause_2." and <code>post_status</code>='publish' order by rand() limit 0,4";
    
    		}
    
    			$objDB->setQuery($SQL);
    			$rs_blog=@$objDB->select();
    			for($i=0;$i<count($rs_blog);$i++)
    			{
    			?>
    			<li> <strong><?php echo $rs_blog[$i]['post_title'];?></strong> <?php echo substr(strip_tags($rs_blog[$i]['post_content']),0,100);?>...</li>
    			<?php
    			}
    			?>

    This is the code. It displays the post but not according to categories. PLs help me someone its urgent.

  • The topic ‘Display Blog Posts on main Site’ is closed to new replies.