Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End if else statements

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #35589
    Kortschot
    Member

    Hi there…

    My php knowledge is fairly limited. I can read it, I understand it but typing it is another game for me.
    The thing i’m trying to accomplish is fairly simple for anyone with basic 1 on 1 PHP skills… hence the frustration why i’m not getting the result I was hoping for. Maybe because it’s a sunday… little wine. Anyway lets sketch my thing here…

    Im making a WP theme. With custom fields and some PHP I did the following:

    – if there is a custom field named youtube with a value,
    – inject the video
    – else inject the featured image

    with the code:





    if (get_post_meta($post->ID, "youtube", true))





    // otherwise do nothing or post the featured image
    else { ?>




    ?>

    This is working like a charm, for the PHP masters here this probably can be accomplished much better or easier, but hey… I have to give myself some credit right =) A least it is posting the youtube video if the custom field is populated in the backend and if not it gets the featured image.

    Now I want to add Vimeo. So it has to do the exact same thing. So the accomplishment here is:

    – check for custom field youtube, if there… post it, otherwise post featured image
    – check for custom field vimeo, if there… post it, otherwise post featured image

    Can anybody kick me in the right direction? I probably get this to work with allot of excessive code… like to have a much cleaner function and code. and I know my PHP skills are just not good enough to be confident the code is clean.

    Eventualy I want to add the JW-Player to get content from my own RTMP Server, but that’s the next step, and I think ill manage that if I get this part working.

    Much obliged to anyone who wants to give this some thoughts.

    With regards, Paul

    #92453
    Senff
    Participant

    << - check for custom field youtube, if there... post it, otherwise post featured image
    – check for custom field vimeo, if there… post it, otherwise post featured image >>

    Not sure if this is actually what you want. I would think you meant this?

    – check for custom field youtube, if there… post it, otherwise:
    – check for custom field vimeo, if there… post it, otherwise:
    – post featured image

    With this structure, you will only get a YouTube video, OR a Vimeo one, OR a featured image (in that order), never two or more of those.

    ID, "youtube", true))   { ?>

    // code for posting YouTube goes here

    ID, "vimeo", true)) { ?>

    // code for posting Vimeo goes here



    // code for featured image goes here

    Just doing it from the top of my head so may not be 100% correct syntax but give it a try and see if that does the trick….?

    #92454
    Kortschot
    Member

    Hi Senff,

    Thanks for your reply to this post. I think this is exactly what I needed.
    The content that will be published will be in a “featured” place on the site. So either a YT or a Vimeo movie or just a featured image.

    Thanks a bunch. I will try tonight or tomorrow.

    #92458
    Kortschot
    Member

    awesome! worked like a charm!

    Now when I want to add an additional player, like the JW-player I just make another elseif statement right?

    At least I’m there for 90% now, when I can’t figure out this next step i’ll ask a programmer at work… (I tend to like it when I figure stuff out for myself as a simple css monkey and flabbergast the programmers)

    Thanks again m8, big help.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.