Jump to content

arrays, keys, values: help defining value that is dependent on another key


noilding

Recommended Posts

This is working off of a wordpress plug-in that uses a form to insert content into a template. One of the tags (we'll call it [xxx]) in the template automatically inserts a button with a link to a page. Another one of the tags ([yyy]) requires you to paste code into the wordpress form so it can embed the code. I'm working with an array trying to define how these tags (keys) interact.

 

What I have is a key '[xxx]' who's value is some HTML that contains an image that links to a page. The other key, '[yyy]', embeds a video onto the page that [xxx] links to.

 

What I want to do is give [xxx] two choices of images to display based on whether or not [yyy] had any code to embed on the page that [xxx] links to. If [yyy] receives code to embed from the wordpress, [xxx] should use image 2. If [yyy] doesn't have any code from wordpress, [xxx] should use image 1.

 

Could someone help me with writing this code? I'm very inexperienced with php. Just managing a website that someone else built.

 

Thanks!

-Matt

 

Here is the code:

 

function sb_search_results_dictionary() {
return array(
...
'[xxx]' => '<a class="aaa" href="<?php insert_link($link) ?>"><img src="http://www..../image1.jpg" alt="" class="btn" /></a>',
'[yyy_loop]' => '<?php foreach ((array) $media as $media_type => $media_names) { if (is_array($media_names) && $media_type == "Code") { foreach ((array)$media_names as $media_name) { ?>',
'[/yyy_loop]' => '<?php } } } ?>',
'[yyy]' => '<?php print_code($media_name) ?>',
...
);
}

For reference-
Another document which is loaded into the php above contains this:

function print_code($code) {
echo base64_decode($code);
}

and in a different document (again, loaded by the first php document under question): 

return array(		
	'Files' => $file,
	'URLs' => $url,
	'Code' => $code,
);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.