|
|
|
// add to footer.php |
|
<div class="recent-posts"> |
|
<?php require_once( trailingslashit( get_template_directory() ). 'footer-posts.php' ); ?> |
|
</div> |
|
|
|
// create template part footer-posts.php |
|
|
|
<?php if (is_page(4)) { ?> // show different title per page |
|
<img src="<?php bloginfo('template_directory'); ?>/images/recent-posts.png" alt="Recent Posts"> |
|
<?php } else { ?> |
|
<img src="<?php bloginfo('template_directory'); ?>/images/related-posts.png" alt="Related Posts"> |
|
<?php } ?> |
|
<?php //wp_nav_menu( array('menu' => 'footer-main' )); ?> |
|
|
|
<ul> |
|
<?php $ID = get_the_ID(); //get the current page ID |
|
//single page per category |
|
//x => y |
|
//category ID => page ID |
|
$pages = array( |
|
"17" => "105", //botox |
|
"8" => "67", //breastaug |
|
"20" => "69", //breastlift |
|
"16" => "91", //buttlift |
|
"9" => "55", //cosmeticsurgery |
|
"11" => "89", //tummytuck |
|
"15" => "58", //recovery |
|
"13" => "113", //facialplasticsurgery |
|
"10" => "53", //plasticsurgery |
|
"21" => "93", //postbariatric |
|
"14" => "132", //skincare |
|
); |
|
//multiple pages per category |
|
$bs = array("99","79","77","87","95","97","103" ); //bodysurgery |
|
$cs = array("55","126","128","130","708","111"); //cosmeticsurgery |
|
$fps = array("113","115","117","124","122","126","128","130"); //facialplasticsurgery |
|
$sc = array("176","607","107","109","621","141","605","132"); //skincare |
|
$mps = array("180","75","73"); //maleplasticsurgery |
|
$fit = array("143","172","17"); //fitness |
|
|
|
//if the ID is in the single page array |
|
if (in_array($ID, $pages)) { |
|
//search for the ID in the single page array, return the key (category ID) |
|
$cat = array_search($ID,$pages); |
|
|
|
if ($cat != false) { |
|
if (is_page(4)) { |
|
//show recent posts on homepage |
|
$the_query = new WP_Query( 'posts_per_page=3' ); |
|
} else { |
|
//show posts by selected category |
|
$the_query = new WP_Query( 'posts_per_page=3&cat=' . $cat ); |
|
} |
|
} |
|
//if the ID is in multi page array |
|
} else if (in_array($ID, $bs)) { |
|
//bodysurgery category |
|
$cat = "18"; |
|
$the_query = new WP_Query( 'posts_per_page=3&cat=' . $cat ); |
|
|
|
} else if (in_array($ID, $cs)) { |
|
//cosmeticsurgery category |
|
$cat = "9"; |
|
$the_query = new WP_Query( 'posts_per_page=3&cat=' . $cat ); |
|
|
|
} else if (in_array($ID, $fps)) { |
|
//facialplasticsurgery category |
|
$cat = "13"; |
|
$the_query = new WP_Query( 'posts_per_page=3&cat=' . $cat ); |
|
|
|
} else if (in_array($ID, $sc)) { |
|
//skincare category |
|
$cat = "14"; |
|
$the_query = new WP_Query( 'posts_per_page=3&cat=' . $cat ); |
|
|
|
} else if (in_array($ID, $mps)) { |
|
//maleplasticsurgery category |
|
$cat = "12"; |
|
$the_query = new WP_Query( 'posts_per_page=3&cat=' . $cat ); |
|
|
|
} else if (in_array($ID, $fit)) { |
|
//fitness category |
|
$cat = "19"; |
|
$the_query = new WP_Query( 'posts_per_page=3&cat=' . $cat ); |
|
|
|
} else { |
|
//no category, recent posts only |
|
$the_query = new WP_Query( 'posts_per_page=3' ); |
|
} |
|
|
|
$cat_name = get_cat_name( $cat ); //get cat name by category ID |
|
$cat_name = preg_replace('/\s+/', '', $cat_name); //remove spaces from category name |
|
|
|
while ($the_query -> have_posts()) : $the_query -> the_post(); ?> |
|
|
|
<li class="<?php echo $cat_name ?>"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a><br><?php the_excerpt(__('(more…)')); ?></li> |
|
|
|
<?php |
|
endwhile; |
|
wp_reset_postdata(); |
|
?> |
|
</ul> |