• Resolved aaronbennett2097

    (@aaronbennett2097)


    Great plugin, really really good, but am wondering if it’s possible to have the thumbnail image pulled from a custom field rather than the featured image.

    Am also having a small problem getting the plugin to display the way I want – I need 4 posts in a row to be displayed across the width of a page, but justified (left post justified to left side of site, right post aligned to right side of the page. But hoping I can figure this out myself.

    Thanks for your help!

    https://www.ads-software.com/extend/plugins/network-latest-posts/

Viewing 15 replies - 1 through 15 (of 22 total)
  • Plugin Author Jose Luis SAYAGO

    (@iluminatus)

    Hello Aaron,

    Well I thought that’s a good idea so I implemented it. I have just uploaded version 3.2 which includes two new parameters: thumbnail_custom and thumbnail_field this will allow you to pull thumbnails from custom fields.

    Here is an example how you could use them:

    [nlposts thumbnail=true
             thumbnail_custom=true
             thumbnail_field=my_custom_thumbnail_field
             thumbnail_wh=300x150
    ]

    Concerning the styling issues, just play with the CSS styles, you could use display_type=block which puts articles inside divs then play with div widths and floats. Here you can find a quick example I made to show someone who asked how to display content in columns: CSS Columns

    I’ve tested the new feature and it works, once you have tested it let me know what you think.

    Cheers.

    Thread Starter aaronbennett2097

    (@aaronbennett2097)

    Hi Jose.

    You are AMAZING for acting on this so quickly. Seriously! Thank you!!

    Am going to try it out and if I have any problems I’ll get straight back to you.

    Ten thumbs up!! ??

    Thread Starter aaronbennett2097

    (@aaronbennett2097)

    Hi Jose.

    Have updated the plugin and set the Thumbnail Custom Field to the name I have (hero_shot).

    At the moment all I’m getting is the question mark graphic because the image cannot be found, but going to persevere and see if I can figure it out.

    I set my custom field using the Advanced Custom Fields plugin by the way, incase that helps.

    The plugin is being used on my homepage of a multisite install, which is pulling the posts from a sub blog (if thats the right terminology).

    The excerpts are there, so its finding the posts, just not the image (yet).

    Thanks again!
    Aaron

    Plugin Author Jose Luis SAYAGO

    (@iluminatus)

    Hello Aaron,

    I forgot to mention, the value in that custom field should be the URL pointing to the image. Check if your custom fields are registering images that way, otherwise we will have to hack it ;)…

    Cheers.

    Thread Starter aaronbennett2097

    (@aaronbennett2097)

    Hi Jose.

    Have checked and the custom field is set to return the value as a url, but still no joy.

    To check, I did add a featured image to the post and it still seems to be using that, even though I set the widget to use a custom field.

    Am gonna keep trying, am sure its something on my setup – which is sadly being developed locally so can’t share the url.

    Any further thoughts would be really appreciated.
    Aaron

    Plugin Author Jose Luis SAYAGO

    (@iluminatus)

    Hi again Aaron,

    Well, here is how I get the data:

    $thumbnail_custom_field = get_post_meta($field->ID, $thumbnail_field, true);
    // Get custom thumbnail
    $thumb_html = "<img src='".$thumbnail_custom_field."' width='".$thumbnail_size[0]."' height='".$thumbnail_size[1]." />";

    So what it basically does is look inside the wp_x_postmeta table the field passed through the thumbnail_field parameter. Check if the hero_shot field is there.

    If you see the image missing, check the source code and see what’s returning (maybe an empty url?).

    Let me know if there’s something else I can help you with.

    Cheers.

    Thread Starter aaronbennett2097

    (@aaronbennett2097)

    Hi Jose.

    I’ve checked the code and here is what it’s returning.

    <img src=”93″ width=”202″ height=”202 /><h3 class=” nlposts-block-title’=””>

    The img src=”93″ is where I suspect it’s failing.

    I’ve also tried ‘hacking’ your file to hard code the hero_shot field, but that didn’t work either.

    To eliminate other errors I created a new custom field, uploaded a new image and changed the widget to point to the new custom field, but still no gravy.

    Any other ideas?

    Thanks
    Aaron

    Plugin Author Jose Luis SAYAGO

    (@iluminatus)

    Hello,

    It seems like it’s returning an ID instead of a URL so I’m wondering where is that plugin storing data.

    I used the custom fields functionality provided by WordPress, when you add a new custom field it saves data to the _postmeta table.

    I guess I will have to check that plugin to see where it’s storing values. If I find something I will let you know.

    Cheers.

    Thread Starter aaronbennett2097

    (@aaronbennett2097)

    Hi Jose.

    So you suspect Advanced Custom Fields is saving the data other than the _postmeta table?

    Shall I try using the built in custom fields and see if that works?

    I really appreciate all your help on this – do let me know if theres anything I can try to narrow down the problem.
    Aaron

    Plugin Author Jose Luis SAYAGO

    (@iluminatus)

    Hi Aaron,

    Well I don’t really know how to use that plugin but I found under settings you have a field called Return Value which presents 3 different choices, Image Object, Image URL and Image ID (check this image: https://postimage.org/image/ok30yw1tn/ )

    If what is being shown is <img src=”93″ width=”202″ height=”202 /> it makes me think 93 must be the image ID so, I guess if you set the Return Value to image URL it should be ok (maybe?)…

    Cheers.

    Thread Starter aaronbennett2097

    (@aaronbennett2097)

    Hi Jose.

    I already made sure I had image URL selected, but no joy.

    Interestingly, when I look at the returning code…

    <img src=”93″ width=”202″ height=”202 /><h3 class=” nlposts-block-title’=””>

    …if I click on the “93” it gives me the full url of where this image is supposed to be.

    This is where it gets confusing…

    The full URL is to my main blog (call it BLOGA) whereas the image is actually saved in a post in BLOGB.

    Does that make sense? I think it’s looking in the wrong blog for the image.

    Thanks
    Aaron

    Plugin Author Jose Luis SAYAGO

    (@iluminatus)

    Well, it’s a shame I can’t test the plugin because is paid :D… But I guess it must be using the _postmeta table, check if the hero_shot (or the name of your custom field) exists in that table and check its value.

    Check also if there are additional tables created by that plugin, if so then I think we will have to hack it. Try to find inside the _postmeta the url pointing to your image and check what’s the name of the field.

    Thread Starter aaronbennett2097

    (@aaronbennett2097)

    Hi Jose.

    It’s def not a paid plugin (https://advancedcustomfields.com) or at least I’ve never paid for it.

    From what I have just read, Advanced Custom Fields uses it’s own table in the database, so that may be why its not picking up in the _postmeta.

    https://support.advancedcustomfields.com/discussion/72/-very-important-information-about-the-new-v1-1-acf-update/p1

    I’m going to dig into my database and see where the hero_shot table is stored.

    Thanks again for all your time.
    Aaron

    Plugin Author Jose Luis SAYAGO

    (@iluminatus)

    Hello Aaron,

    Hehe well I installed that one from the WordPress repository and it ask for license codes to activate some functionalities :D….

    Anyway I’ve checked the documentation and it seems there’s no way to pass post IDs to functions so you could try this:

    Comment out all occurrences for this line:

    $thumbnail_custom_field = get_post_meta($field->ID, $thumbnail_field, true);

    Then look for this one:

    $thumb_html = "<img src='".$thumbnail_custom_field."' width='".$thumbnail_size[0]."' height='".$thumbnail_size[1]." />";

    And replace all occurrences by this one:

    $thumb_html = "<img src='".the_field($thumbnail_field)."' width='".$thumbnail_size[0]."' height='".$thumbnail_size[1]." />";

    I did not test this (because I can’t make the plugin work for me), but in theory “it should work”.. Based on these examples: https://www.advancedcustomfields.com/docs/getting-started/code-examples/

    Let me know if it works..

    Thread Starter aaronbennett2097

    (@aaronbennett2097)

    Have looked through my database (bit out of my knowledge / depth) and although I found the _postmeta, I couldnt see anything that refers to hero_shot.

    I must admit, I don’t really know what I’m doing with the database!

    Will keep researching and testing.
    Thanks!!
    Aaron

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘Pulling image from custom field’ is closed to new replies.