[insert_php]
global $do_not_duplicate; global $post; $arr_magazine = array(); $book = false;
/*Only below categories will show */

/*Magazine name from url*/
$mag = $_GET[‘mag’];

if(!strlen($mag))
{

$arr_magazine = array(); $iterator=0;
$recent = new WP_Query(array(‘posts_per_page’ => -1,’category_name’ => ‘big-project,construction-machinery,me-consultant,truck-and-fleet’ ,’meta_key’ => ‘magazine_preview_id’,’order’ => ‘DESC’ , ‘meta_query’ => array(
array(‘key’ => ‘magazine_preview_id’,’value’ => ”,’compare’ => ‘!=’) ))); while($recent->have_posts()) : $recent->the_post(); $do_not_duplicate[] = $post->ID;
if (isset($do_not_duplicate)) {

$post_title = $post->post_title;
$arr_temp = explode(‘-‘,$post_title);
if(!empty($arr_temp))
{
/*Magazine Name*/
$name = strlen($arr_temp[0]) ? $arr_temp[0] : ”;

/*Month and Year*/
$month_year = strlen($arr_temp[1]) ? trim($arr_temp[1]) : ”;

/*Magazine link*/
$custom_url= get_post_meta( get_the_ID(),’magazine_custom_url’, true);
if(strlen($custom_url))
$link = $custom_url;
else
$link = get_permalink( $post->ID );

/*Magazine Picture*/
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
$feat_image = strlen($feat_image) ? $feat_image : ”;
$mag_array = array(‘name’ => $name , link => $link , ‘image’ => $feat_image );

}

$arr_magazine[$month_year][] = $mag_array;

} endwhile; wp_reset_postdata();

//echo “

"; print_r($arr_magazine);

/*Design*/
foreach($arr_magazine as $key => $individual_month)
{
sort($individual_month,SORT_REGULAR);
echo '

';
echo '

'.$key.'

';
foreach($individual_month as $key => $individual)
{
//$resized_img = "http://meconstructionnews.com/script/timthumb.php?src=".$picture."&h=294&w=235&zc=1";
$name = trim($individual['name']);
$picture = $individual['image'];
$link = trim($individual['link']);
$html = '

';
//$html .= '

';
$html .= '

';
$html .= ''.$name.'';
$html .= '

';
$html .= '

'.$name.'

';
$html .= '

';
// $html .= '

';
$html .= '

';
echo $html;

}
echo '

';

}

}else
{

$arr_magazine = array('truck-and-fleet' => 'Truck&Fleet ME' , 'me-consultant' => 'ME Consultant' ,'big-project' => 'Big Project ME' , 'construction-machinery' => 'Construction Machinery ME');

global $do_not_duplicate; global $post;$iterator = 0;

if($mag == "construction-machinery")
{
/*Sub Categories*/
$crane_report = get_category_by_slug('crane-report')->term_id;
$powered_access = get_category_by_slug('powered-access-report')->term_id;
$construction_machinery = get_category_by_slug('construction-machinery')->term_id;
$earth_moving_report = get_category_by_slug('earthmoving-report')->term_id;

$construction_categories = array($crane_report,$powered_access,$construction_machinery,$earth_moving_report);
$recent = new WP_Query(array('posts_per_page' => -1,'category__in' => $construction_categories ,'meta_key' => 'magazine_preview_id','order' => 'DESC' , 'meta_query' => array(
array('key' => 'magazine_preview_id','value' => '','compare' => '!=') )));
}
elseif($mag == "big-project")
{ /*Condition for Big Project ME */
/*Sub Categories*/
$smart_cities = get_category_by_slug('smart-cities-report')->term_id;
$concrete_report = get_category_by_slug('concrete-report')->term_id;
$fire_safety = get_category_by_slug('fire-safety-building-security-report')->term_id;
$big_project = get_category_by_slug('big-project')->term_id;

$bigproject_categories = array($smart_cities,$concrete_report,$fire_safety,$big_project);

$recent = new WP_Query(array('posts_per_page' => -1,'category__in' => $bigproject_categories,'meta_key' => 'magazine_preview_id','order' => 'DESC' , 'meta_query' => array(
array('key' => 'magazine_preview_id','value' => '','compare' => '!=') )));
}
elseif($mag == "truck-and-fleet")
{
$truckbook = get_category_by_slug('truck-book')->term_id;
$truckfleet = get_category_by_slug('truck-and-fleet')->term_id;

$tfme_categories = array($truckbook,$truckfleet);

$recent = new WP_Query(array('posts_per_page' => -1,'category__in' => $tfme_categories ,'meta_key' => 'magazine_preview_id','order' => 'DESC' , 'meta_query' => array(
array('key' => 'magazine_preview_id','value' => '','compare' => '!=') )));
}
else
{
$recent = new WP_Query(array('posts_per_page' => -1,'category_name' => $mag ,'meta_key' => 'magazine_preview_id','order' => 'DESC' , 'meta_query' => array(
array('key' => 'magazine_preview_id','value' => '','compare' => '!=') )));
}

$magazine_heading = isset($arr_magazine[$mag]) ? $arr_magazine[$mag] : $mag;
if($recent->have_posts())
{
echo "

".$magazine_heading."

";
while($recent->have_posts()) : $recent->the_post(); $do_not_duplicate[] = $post->ID;
if (isset($do_not_duplicate)) {
$post_title = $post->post_title;
$arr_temp = explode('-',$post_title);
if(!empty($arr_temp))
{
/*Magazine Name*/
$name = strlen($arr_temp[0]) ? $arr_temp[0] : '';
/*Month and Year*/
$month_year = strlen($arr_temp[1]) ? trim($arr_temp[1]) : '';
/*Magazine link*/
$custom_url= get_post_meta( get_the_ID(),'magazine_custom_url', true);
if(strlen($custom_url))
$link = $custom_url;
else
$link = get_permalink( $post->ID );
/*Magazine Picture*/
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
$feat_image = strlen($feat_image) ? $feat_image : '';
//$mag_array = array('name' => $name , link => $link , 'image' => $feat_image );
}

if($iterator%4 == 0 )
echo '

';

$magazine_name = strlen($month_year) ? $month_year : $name;
/*Remove text for Fire Safety & Building Security Report */
$magazine_name = str_replace('Fire Safety & Building Security Report','Fire Safety Report',$magazine_name);

$resized_img = "http://meconstructionnews.com/script/timthumb.php?src=".$feat_image."&h=294&w=235&zc=1";

/*Change font size if text is big*/
$css="";
if(strlen($magazine_name)> 18)
$css = "font-size: 12pt !important;";

$iterator++ ;
$html = '

';
$html .= '

';
$html .= '';
$html .= '

';
$html .= '

';
$html .= '

'.$magazine_name.'

';
$html .= '

';
$html .= '

';
echo $html;

if($iterator%4 == 0 && $iterator > 0 )
echo '

';

} endwhile; wp_reset_postdata();

}else
{
echo "Sorry no result found!";
}

}

[/insert_php]

To Top