• Hello community!

    I am wondering if the following is possible. My client is posting a piece of music every month in form of a post where he also writes things about this piece of music. Each post has the audio in the post. I was wondering if it was possible somehow to have always the latest song displayed in a widget, without him using the audio widget where my client has to separately select the song from the library again. Is there any way of doing this? I thought it would have been a cool feature and I would have liked to implement it for them.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Where there is a will, there is a way ?? Most of the time anyway. If it can be done with PHP, then it is possible. It largely depends on how predictable the links are and how unlikely it is to mistakenly pick up the wrong link. For example, if the music link is always from soundcloud or always from a specific local folder, and no other similar links will ever be used, then this is doable. Even better will be if the music is always uploaded through the media library and inserted into a post. Then there will be an attachment post that is a child of the blog post that refers to the media.

    In the media library case, a widget would query for the latest post, determine the related attachment, get the link and display it. Something is still possible with other ways of embedding links, but it’s more work to extract the right data.

    Thread Starter Foliferous

    (@revs)

    Hi,

    well, the music link would be always from the media library (inside WP). The situation you describe is exactly the case, it’s a post with embedded audio from the media library.

    Do I just need to make a PHP code for this, that I will insert in a PHP-widget, or do I need to make an extra plugin for that?

    Moderator bcworkz

    (@bcworkz)

    Any recommended way of introducing PHP into WP will work. PHP widget, plugin, or child theme. If you already have a site specific custom plugin, you can add to that. Conversely, if you create a plugin for this, you can also use the same for any other additional PHP you end up wanting to do. While a PHP widget is an easy solution, having a custom plugin to throw any desired code into is really worth having IMO.

    Thread Starter Foliferous

    (@revs)

    Alright, thank you very much bcworkz ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Use audio from a post in a widget’ is closed to new replies.