Trying to pull the URL for a file upload from Settings Page using Shortcode
Support › MB Settings Page › Trying to pull the URL for a file upload from Settings Page using ShortcodeResolved
- This topic has 7 replies, 2 voices, and was last updated 4 years ago by
[email protected].
-
AuthorPosts
-
April 22, 2021 at 3:20 PM #27502
[email protected]
ParticipantI am trying to display some images in a Beaver Themer HTML module. I have settings page where the site owner can upload a logo ( and some other images ) using the File Upload field type. I have tried many things I have found here in the forum but can't seem to get it to work. Here's where I am now with the shortcode:
<img src="[rwmb_meta id='business-info#info_business_logo' attribute='url']">
I have also tried it without the settings page id:
<img src="[rwmb_meta id='info_business_logo' attribute='url']">
Can you help me figure out what I'm doing wrong? THanks so much.
April 22, 2021 at 4:02 PM #27506[email protected]
ParticipantUpdating with more information:
I decided to try and see if I could just create a view and then use the short code. I started with only using "site" fields. The only ones that would show on the front end of the site are the default "site" fields. Example: {{site.title}}
I cannot get any of the custom fields to show up on the front end of the site. I must have made some mistake in setting this up that I don't know about or don't understand. Hoping this makes sense to someone and that you can point me in the right direction. Thanks, again.
April 23, 2021 at 6:14 AM #27542Long Nguyen
ModeratorHi Chris,
The
multiple
setting is always set totrue
for the field typefile_upload
, which means the return of the helper functionrwmb_meta()
is an array so you need to loop through the array to get each element.Get more details in the documentation https://docs.metabox.io/fields/file-upload/#template-usage
April 23, 2021 at 11:18 AM #27556[email protected]
ParticipantThanks for the reply. Forgive my ignorance here but do I need to create a shortcode using a form of the code on the page you linked? Would one of the other upload options allow for a single file upload without using the media library uploaded? I don't want the user to see the media library in the upload process. Thanks again.
April 24, 2021 at 10:34 AM #27588Long Nguyen
ModeratorHi,
No need to create a custom function, you just need to create a loop in View, see more on this topic https://support.metabox.io/topic/display-multiple-media-files-connected-to-a-user/
{% for item in post.file_upload_id %} <img src="{{ item.url}}"> {% endfor %}
There is a file type
image
that works similar tofile_upload
, it allows the user to upload the image file without accessing the Media Library but themultiple
setting also set totrue
for this field.April 24, 2021 at 2:02 PM #27595[email protected]
ParticipantThere must be something else that I am doing wrong. I moved the site over from LocalHost to a live server but still can't get this to work.
I created a new View and have set it up as a Type: Shortcode.
Here's the code in the View:
<h1> This is a test. </h1>{% set group = attribute( site, 'business-info' ) %} {% for item in group.info_business_logo %} {{ item.url }} {% endfor %} {% set group = attribute( site, 'business-info' ) %} {% for item in group.info_business_logo %} <a href="{{ item.url }}">{{ item.title }}</a> {% endfor %} {% set group = attribute( site, 'business-info' ) %} <img src="{{ group.single_image_zd6n6bftlti.thumbnail.url }}" width="{{ group.single_image_zd6n6bftlti.thumbnail.width }}" height="{{ group.single_image_zd6n6bftlti.thumbnail.height }}" alt="{{ group.single_image_zd6n6bftlti.thumbnail.alt }}"> {% set group = attribute( site, 'business-info' ) %} {% for clone in group.image_upload_egw66lpdlun %} {% for item in clone %} <img src="{{ item.thumbnail.url }}" width="{{ item.thumbnail.width }}" height="{{ item.thumbnail.height }}" alt="{{ item.thumbnail.alt }}"> {% endfor %} {% endfor %}
And here's the output: https://base.m11design.dev/test-page/
I've checked and rechecked the code and I am obviously missing something or just don't know what I'm doing. I've used Pods Framework for years and years but I just purchased MB and this is my first time using it.
April 24, 2021 at 8:54 PM #27608Long Nguyen
ModeratorHi,
Please take a look at my screen record to know how to show the image from the settings page https://share.getcloudapp.com/ApuYXd8N.
If it still troubles you, please share the code that creates the settings page and custom fields, I will help you to check.
April 26, 2021 at 10:38 PM #27661[email protected]
ParticipantThanks for your response. I fought with this for several more hours. I finally decided to just try changing the "key" for the Tab settings on each tab in my Settings Page setup. I had used numbers for those and I changed the to words. Now the fields show up using views as they are supposed to. Is that really what was wrong? I mean is the correct setup for the Key on the tabs in Settings Pages supposed to be words and not numbers?
-
AuthorPosts
- You must be logged in to reply to this topic.