• Just wondering if there was anyway to set an articles featured image as the first image uploaded to that post if a specific image isn’t specified?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Well, you can do that, but it will take some programming — unless someone has a plugin for it, not too sure — because the default one supplied by WordPress isn’t up to my standards. You can check them out first before continuing.

    https://codex.www.ads-software.com/Function_Reference/the_post_thumbnail

    I’m going to give you an example of a post thumbnail that would be used on the front page for your posts.

    First off, check if your theme supports thumbnail posting.

    To do this, go to the main directory of your current theme.

    Add the code below if it does not already exist in your functions.php file.

    <?
    add_theme_support( 'post-thumbnails' );
    ?>

    This will allow your theme to use the post thumbnails function designated for the post.

    Next, we will setup a function for your custom display. So remain in your functions.php file.

    [code moderated as per forum rules - please use the pastebin]

    https://pastebin.com/atXvJmbw

    For use with this...

    $cat = If your wanting to use the category option, then you need to put a 1. If you do not want to use the category option, display nothing.

    Example usage:

    <?
    	check_thumb('1', '', '', '')
    ?>

    This will display the image that you have set for the category in whichever folder you put down. If the example category was Uncategorized, then the image displayed would be Uncategorized.jpg

    If you do not want to use it, then you need to use the display argument to choose your image, and the alt argument to display the alternative text.

    Example usage:

    <?
    	check_thumb('', '', 'featured.jpg', 'Featured Image')
    ?>

    This would display the image featured.jpg with the alternative text of 'Featured Image'

    Great, let's move on.

    Now, you can also set the size for the thumbnails if one is used via the Dashboard. The sizes are as follows, and must be used like this, if you do not want a size, then leave the argument blank.

    thumbnail - Small Resolution (default 150px x 150px max)
    medium - Medium resolution (default 300px x 300px max)
    large - Large resolution (default 640px x 640px max)

    Example usage:

    <?
    	check_thumb('', 'thumbnail', 'featured.jpg', 'Featured Image')
    ?>

    The above could would do the following.

    If thumbnail is set by Dashboard, show the thumbnail with a max size of 150px x 150px. If there is no image set by the dashboard, display featured.jpg

    You are going to want to display this with your loop. It will not work outside of the loop.

    This is the end of my little coding for you. I did not test this, but it should work. If you have any problems, just let me know.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Auto Featured Image’ is closed to new replies.