Want the PHP code to show video or photo depending on the existence of a custom field.
1) Check if there is a video custom filed (has to be video)
2) If there is a video custom field, show the embedded video code that is in that field
3) if there isn't a video custom field, check for image custom field.
4) If there is a image custom field, use the following code to show the image:
<p><a href="<?php echo get_post_meta($post->ID, "imagelink", true); ?>" title="<?php the_title(); ?>"><img style="border:10px solid #000000;" src="<?php echo get_post_meta($post->ID, "image", true); ?>" alt="<?php the_title(); ?>" /></a></p>
NOTE: If there is a video don't check for the image in this code.
The code will be used within a theme so the code has to be standalone.
Basically I want this code to show video the same way that images are shown on this page: http://alexandermalone.com.
Tip will only be awarded if working code is achieved.
TIA
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$3 Answers
<?php if(get_post_meta($post->ID, 'youtube_id', true))
{
$values = get_post_custom_values("youtube_id");
$youtube_id = $values[0];
?>
<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/<?php echo $youtube_id; ?>&hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/<?php echo $youtube_id; ?>&hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>
} ?>
TimThumb PHP Script
http://www.darrenhoyt.com/2008/04/02/timthumb-php-script-released/?cp=2
We talking about popping up the window or displaying the video here?
The window is done with Javascript and the code for that can be gotten from the page's source:
<a href="javascript://" onclick="video_win=window.open('/videos/view-video.cgi?jackson.mov', 'video_win', 'height=335, width=336')">Jackson Mann Skateboarding</a>The contents of the window that's opened are generated via a CGI script that displays the video that's specified.
It was written in CGI since that's probably what the coder was comfortable in. I however have no knowledge, or interest even :P, in CGI. I do however know PHP and can help you with a PHP script for displaying videos.
So, using their site as an example and basis, I'd do this. A file would be called "view-video.php" in the "videos" folder.
You can do the format they did "/videos/view-video.php?jackson.mov", but I'd personally go "/videos/view-video.php?filename=jackson.mov". Makes life a lot easier from a coding standpoint.
Then using that, you can just use this code to get the page they have:
<HTML>
<HEAD>
<TITLE>ZEEG{isbreathing}</TITLE>
<META name="description" content="Quicktime Videos">
<META name="keywords" content="Nick Zegel Documentary">
<link rel="stylesheet" type="text/css" href="../stylesheet.css"/>
</HEAD>
<body bgcolor="#000000" text="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center><br>
<EMBED SRC="<?php echo $_GET['filename']; ?>" WIDTH=320 HEIGHT=256 AUTOPLAY=true CONTROLLER=true LOOP=false PLUGINSPAGE="http://www.apple.com/quicktime/"><BR><BR>
<font style="font-family: arial, helvetica, sans-serif; font-size: 17px; letter-spacing:-1px; line-height : 17px; color: #FFFFFF; font-weight: bold;">ZEEG{isbreathing}</font>
<br>
<font style="font-family: arial, helvetica, sans-serif; font-size: 10px; color: #FFFFFF;">dotcom</font><br>
</BODY>
</HTML>
You could also do some more complex coding like having a file/database that stores the resolution of the video if your videos have varying dimensions as well as some code to make sure that the video file you're calling actually exsists.
Post if you want help with either of those things or anything else.
The sript is:
<OBJECT id='mediaPlayer' width="320" height="240"
classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'
codebase='http://activex.microsoft.com/activex/controls/ mplayer/en/nsmp2inf.cab#Version=5,1,52,701'
standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>
<param name='fileName' value="http://mydomain.com/video.wmv">
<param name='animationatStart' value='1'>
<param name='transparentatStart' value='1'>
<param name='autoStart' value='1'>
<param name='ShowControls' value='0'>
<param name='ShowDisplay' value='0'>
<param name='ShowStatusBar' value='0'>
<param name='loop' value='0'>
<EMBED type='application/x-mplayer2'
pluginspage='http://microsoft.com/windows/mediaplayer/ en/download/'
id='mediaPlayer' name='mediaPlayer' displaysize='4' autosize='0'
bgcolor='darkblue' showcontrols='0' showtracker='1'
showdisplay='0' showstatusbar='0' videoborder3d='0' width="320" height="240"
src="http://mydomain.com/video.wmv" autostart='1' designtimesp='5311' loop='0'>
</EMBED>
</OBJECT>
<?> Copy & paste the following...
<!-- begin embedded WindowsMedia file... -->
<table border='0' cellpadding='0' align="left">
<tr><td>
<OBJECT id='mediaPlayer' width="320" height="285" classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'
codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'
standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>
<param name='fileName' value="http://servername/path/to/media.file">
<param name='animationatStart' value='true'>
<param name='transparentatStart' value='true'>
<param name='autoStart' value="true">
<param name='showControls' value="false">
<param name='loop' value="true">
<EMBED type='application/x-mplayer2'
pluginspage='http://microsoft.com/windows/mediaplayer/en/download/'
id='mediaPlayer' name='mediaPlayer' displaysize='4' autosize='-1'
bgcolor='darkblue' showcontrols="true" showtracker='-1'
showdisplay='0' showstatusbar='-1' videoborder3d='-1' width="320" height="285"
src="http://servername/path/to/media.file" autostart="true" designtimesp='5311' loop="true">
</EMBED>
</OBJECT>
</td></tr>
<!-- ...end embedded WindowsMedia file -->
<!-- begin link to launch external media player... -->
<tr><td align='center'>
<a href="http://servername/path/to/media.file" style='font-size: 85%;' target='_blank'>Launch in external player</a>
<!-- ...end link to launch external media player... -->
</td></tr>
</table>
To autosize, just replace
<OBJECT id='mediaPlayer' width="320" height="285"
by
<OBJECT id='mediaPlayer' autosize='-1'
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$Perhaps negotiating a real rate with Razorboy would be a great way to get exactly what you want? $2 is unreasonable for programming work and while a quick question, fix, or other point in the right direction would certainly warrant a $2 tip, having "criteria" and "reading the rules" says "pay up" to me.
I'm a professional programmer and things like this always irk me a little. It's one thing for someone to ask for help and receive it for free but it's a completely separate thing to devalue the skill and service that freelance programmers can provide.
My complete answer would be to talk to Razorboy first because it looks like he's already done a lot of work to try and solve your problem. Next, I would consult freelance websites like rentacoder.com, elance, and scriptlance. These sites allow you to post your project (exactly as you have done here) and for people to bid on completing it.
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$I agree, M$2 is lunch money for this job.
Agree. You might have to start a new question and offer more for a complete script. This doesn't look all that involved, so maybe something in the $20 or $30 range might entice someone to spend a few minutes on it.....
But as for this $2 tip, razorboy's advisement is likely worth that .... and a decent bit more.
Hmmm.... You may be right. Maybe the "video fit" shouldn't be there and as I said is miss leading. Forget that and assume that code in the video wordpress custom field is what is needed and just needs to be shown. I really think this is a somewhat simple if then else statement that I just don't have the PHP skill to write. If it was another language I would.
I understand this may not be worth the money. If it isn't, don't undertake it. I would totally understand that. There are many questions I don't think would be worth the tip, and so I walk away from them. I am sure there is someone that could write this in there sleep and it will take 2 secs. I there is, I wanted to take the chance to find them!
I ended up hacking this out myself with the help of Google in about 4 hours. For those that are interested, the code is:
------------------------------------------------
<?php
if(get_post_meta($post->ID, 'dailymotion', true)){
$values = get_post_custom_values("dailymotion");
$dailymotion = $values[0];
echo '<center><object width="420" height="339"><param name="movie" value="http://www.dailymotion.com/swf/'.$dailymotion.'" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><embed src="http://www.dailymotion.com/swf/'.$dailymotion.'" type="application/x-shockwave-flash" width="420" height="339" allowFullScreen="true" allowScriptAccess="always"></embed></object></center>';
}elseif(get_post_meta($post->ID, 'youtube', true)){
$values = get_post_custom_values("youtube");
$youtube = $values[0];
echo ''.$youtube.'';
} else {
$values = get_permalink($post->ID);
$youtube = $values;
$values1 = get_post_custom_values("image");
$youtube1 = $values1[0];
$values2 = the_title("","",FALSE);
$youtube2 = $values2;
echo '<p><a href="'.$youtube.'" title="'.$youtube2.'"><img style="border:10px solid #000000;" src="'.$youtube1.'" alt="'.$youtube2.'"/></a></p>
'; } ?>
==============================
This sort of breaks ilaksh thought that it would take 4 hours (I have about .01% PHP knowledge and a lot of the time was getting basic PHP stuff that a more experienced developer would have done in .00001sec) or even days.
I will admit maybe the bit about the centered video through people off. I also understand the arguement that people would want more money for this work but it goes against the MA idea. I put it out here as I was only willing to tip $2. If you thought you could answer it quick or if you wanted the advertisement or points or something, then you might spend a little time on it.
Any way, to finish up. In the interest of good faith (and that people may have been mislead (although to be fair to me, razorboy's answer didn't answer the basic point of doing the if video else image logic that was at the core of the problem)), I will award razorboy the tip even though I said in the question I wouldn't.
Thanks for you time, and I hope we all learnt something about MA here.
can you explain clearly you want to fit video to your to a particular size
I think that if you want him to do all of that work for you then you should increase your tip to at least $60. That's estimating 4 hours of work total at $15/hour, which is an inexpensive outsourcing rate. I actually think he might have easily spent more than that amount of time already. You could probably find a lot of U.S. programmers that would spend all day or even two or three days on this. So really it could cost as much as $800 or more.
Or be happy that he did most of the work already, give him the $2 tip, and next time be more reasonable.
This is a good start, but doesn't meet the criteria to earn the tip. Read the rules again. Sorry to be a hard ass, but I did try to lay it out fully. If there is anything not clear, please ask.