Recent Global Posts: Featured Image and Custom Fields?

Hi there. I'm a newbie here to hello to you all.

I'm playing about with the Recent Global Posts plugin and was wondering if there was a way to:

a) Return the Featured Image of posts/custom posts;
b) With CustomPress, return custom fields;
c) To what extent can the layout of the content be changed? The documentation only shows Avatar, Title and Text., which is a bit limited. As well a custom fields, the ability to add a Read More button would be helpful as I found this helped improve page views.

Thanks. Gavin.

  • Luís

    Hi @gavingwebb,

    Hope you're doing well today and welcome to the WPMUDEV Community!

    Regarding to your questions:

    a) The plugin doesn't display images out of the box currently. But you can do it by editing the plugin code. The following thread should hopefully get you going.

    https://premium.wpmudev.org/forums/topic/featured-image-in-recent-global-posts-widget

    b) Following the above question, try use the functions "get post custom values" or "get post meta":

    https://codex.wordpress.org/Function_Reference/get_post_custom_values

    https://developer.wordpress.org/reference/functions/get_post_meta/

    c) The plugin only have those options, we need to change it to show other features.

    Regarding to the Read More button, you can try add this code in wp-content/plugins/recent-posts/recent-posts.php:

    $html .= '<a href="' . network_get_permalink() . '" >' . 'Read More' . '</a>';

    below of:

    $the_content = network_get_the_content();
    $html .= substr(strip_tags($the_content),0,$tmp_content_characters);

    I hope this information has been helpful. If I can help you in this or other questions, please let me know!

    Cheers, Luís

  • Gavin

    Hi again. I've played about with the php file and got the Read More link sorted - that was easy.

    However, not being much of a coder (which is why I use plugins) and after a few hours I can't get the Featured Image element to work.

    I haven't even had a go at the custom fields bit.

    So first, could you provide some code for this file and plugin (the reference link is about the recent global posts widget) so I can just get on with what I want to do.

    Second, it appears to me that the one-size-fits-all shortcode approach is really quite basic and restrictive. There is a free plugin that can do more - https://wordpress.org/plugins/network-posts-extended/ (it can return Featured Images without messing about with the php file) but again this approaches the layout as a one-size-fits-all, developer-led shortcode, predefined in the plugin.

    Perhaps a better approach would be to have individual shortcode for each element of Title, Excerpt, Content, Featured Image, Post Type, Permalink, etc and give users the opportunity to create their own layout in the admin area, for example:

    <div>[wpmu-post-featured-image]</div>
    <div>Posted at [wpmu-blog-title] by [wpmu-author]</div>
    <h2>[wpmu-post-title]</h2>
    <div>[wpmu-post-excerpt]</div>
    <div><a href="[wpmu-post-url]">Read More</a></div>

    This is the sort of approach used with the excellent Toolset Views plugin - https://wp-types.com/documentation/user-guides/#views-topics which is such a help for coding numpties like me, and which allow me to get on with things I really want and need to do.

    Of course, there'd probably be different layouts for different post types - this is certainly true in my case - so perhaps in the admin UI allow users create different 'Layouts'/'Views' based on post type (I would have thought linked with CustomPress?) including the ability to pull in data from custom taxonomies.

    So, rather than having:
    [globalrecentposts number="2" content_characters="200" global_before="<h3>Here are our most recent posts. Enjoy!</h3>" before="<div class='custom-li'>" after="<hr></div>" show_avatars="yes" avatar_size="48" title_before="<h4>" title_after="</h4>"]
    ...everything could be laid out in the admin UI, and then called using a shortcode like:
    [wpmu-layout="layout-name"]

    Thanks. Gavin.

  • Gavin

    Hi - I trust you're all well. I was wondering if there was any more comment or thoughts on this?

    I haven't had a chance to play with this much since my last post, but another thing I noticed that was quite limiting (and I'm sure is part of the design of the plugin, given its name) is that there is no way to randomise the post that is displayed.

    Furthermore, there doesn't appear to be a clear option to return custom post types.

    Thanks. Gavin.

  • Luís

    Hi Gavin ,

    Hope you're doing well today!

    Firstly, sorry for my late reply and all the problems it may have caused.

    Thanks for all your suggestions, I've just moved this over to our Features and Feedback, so it can be taken into consideration for the next plugin updates.

    Regarding to pull the post featured image, after search a little more, I found a solution. Please try this procedure:

    1) Edit p-content/plugins/recent-posts/recent-posts.php

    2) In the line 83, you will see:

    while( network_have_posts()) {
    	network_the_post();
    	$html .= $tmp_before;

    3) Insert this after the above code:

    $n_post = network_get_post();
    switch_to_blog($n_post->BLOG_ID);
    $html .= get_the_post_thumbnail( $n_post->ID, array( 100, 100) );
    restore_current_blog();

    Regarding to the custom post type, have you tried the parameter, as mentioned in the plugin usage?

    [globalrecentposts posttype=”post-type” ]

    The custom post type, should be added in the Default Post Types field of Post Indexer global settings (network admin -> Settings -> Post Indexer -> Global Settings).

    I hope this information has been helpful. If I can help you in this or other questions, please let me know!

    Cheers, Luís

  • Gavin

    Hi Luís (et al.) - do you have a suggestion on how to randomize the returns for this plugin?

    Also, as queried before, if I mess with the template, it will be overwritten by any updates. Is that correct?

    To be honest, everyone seems to rave about wpmudev, but I'm finding it quite disappointing. I signed up months ago to do a simple thing - pull in content from subsites, from a specific CPT, in a format I wanted. This plugin requires tinkering with.

    I've now changed my plans to have content pulled from the main site, from a specific CPT, to display just the featured image, seven posts randomly. Again, I'll have to mess with code.

    I just want to get something done, which is why I decided to take the leap and pay for the wpmudev service. Although I like much of what wpmudev provides, I frustrated that I can't get a simple thing done.

    So, any help will be appreciated.

    Thanks. Gavin.

    PS - one of the main concerns I have with messing with the template as advised above, it that it is a global change. Therefore, I won't be able to use the plugin as is for other things. Instead, if I understand this correctly, I'd have to make a copy of the plugin - or is that the intention anyway?

  • Jude

    Hey Gavin

    Also, as queried before, if I mess with the template, it will be overwritten by any updates. Is that correct?

    Yup this will be the case if you edit plugin core files, not much we can do as this is not something the plugin can do out of the box.

    I just want to get something done, which is why I decided to take the leap and pay for the wpmudev service. Although I like much of what wpmudev provides, I frustrated that I can't get a simple thing done.

    We have a policy where in we wont be able to code the solution for members where it takes us more than 10 mins.

    https://premium.wpmudev.org/manuals/using-wpmu-dev/support-vs-custom-development/

    I see you mention you're not much of a programmer yourself, I strongly suggest you get this custom developed. You can try our Jobs Board where you can find access to some quality talent to help you with this.

    Therefore, I won't be able to use the plugin as is for other things. Instead, if I understand this correctly, I'd have to make a copy of the plugin - or is that the intention anyway?

    Yup this is true if you proceed as is. IF you however get this custom developed, you can add site specific flags and have the default behaviour for other sites.

    Cheers
    Jude

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.