Last active
December 15, 2015 16:58
-
-
Save surefirewebserv/5292497 to your computer and use it in GitHub Desktop.
Display ad_id (or anything really) according to category ID. Thank you @garyj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
global $post; | |
$lookup = array( | |
// category ID => ad ID | |
'1084' => '600', | |
'1085' => '601', | |
'1095' => '602', | |
'1086' => '603', | |
'1088' => '605', | |
'1089' => '606', | |
'1090' => '607', | |
'1091' => '608', | |
'1092' => '609', | |
'1093' => '610', | |
'1094' => '611' | |
// ... | |
); | |
// Get all categories that the post is assigned to | |
$categories = get_the_category($post->ID); | |
// Loop through | |
foreach ($categories as $category) { | |
// If category is in the lookup array... | |
if (in_array($category->cat_ID, array_keys($lookup))) { | |
// ...grab the corresponding ad id, then kill the loop | |
$sf_product_id = $lookup[$category->cat_ID]; | |
break; | |
} | |
} | |
// If no ad ID, set a default. | |
$default_ad_id = 604; | |
$sf_product_id = isset( $sf_product_id ) ? $sf_product_id : $default_ad_id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment