When you say a new content type, do you mean you’ll have a taxonomy or category that stores this information somewhere?
From what I see, the easiest way to do this would be to build an array like this:
<pre>
<?php
// Paste this code in functions.php
// coke pepse sprite are shown like slugs here, you can also just use IDs (that would be easier)
$category_extra_info = array(
'coke' => array(
'link' => 'http://domain.com',
'image' => 'http://domain.com/logo.png'
),
'pepsi' => array(
'link' => 'http://domain2.com',
'image' => 'http://domain2.com/logo.png'
),
'sprite' => array(
'link' => 'http://domain3.com',
'image' => 'http://domain3.com/logo.png'
),
);
// And then use it like this anywhere in template
echo '<a href="' . $category_extra_info['coke']['link'] . '" rel="nofollow"><img src="' . $category_extra_info['coke']['image'] . '" alt="logo" /></a>';
?>
</pre>
If you want to autoreplace words and make things even more dynamic, you can do it this way:
<?php
// Paste this code in functions.php
// coke pepse sprite are shown like slugs here, you can also just use IDs (that would be easier)
$category_extra_info = array(
'coke' => array(
'link' => 'http://domain.com',
'image' => 'http://domain.com/logo.png'
),
'pepsi' => array(
'link' => 'http://domain2.com',
'image' => 'http://domain2.com/logo.png'
),
'sprite' => array(
'link' => 'http://domain3.com',
'image' => 'http://domain3.com/logo.png'
),
);
function category_extra_info_parsing( $text ){
// make it accessible
global $category_extra_info;
// loop and build the $replace array
foreach ( $category_extra_info as $cat => $info ) {
$replace[ $cat ] = '<a href="' . $category_extra_info['coke']['link'] . '">' . $cat . '</a>';
}
// replace words now
$text = str_replace(array_keys($replace), $replace, $text);
//return modified content
return $text;
}
add_filter('the_content', 'category_extra_info_parsing');
// add_filter('the_excerpt', 'category_extra_info_parsing'); // Uncomment this line for parsing the category words
// And then use it like this in your template
// echo '<a href="' . $category_extra_info['coke']['link'] . '"><img src="' . $category_extra_info['coke']['image'] . '" alt="logo" /></a>';