FrameMarket: Auto fetch featured image

Hi

My posts are not fetching featured image....I have published pages using "blognews template" what could be the problem?

Found this snippet...can I use it in my child theme's function.php code....will it help in anyway

function autoset_featured() {
global $post;
$already_has_thumb = has_post_thumbnail($post->ID);
if (!$already_has_thumb) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
}
}
} //end function
add_action('the_post', 'autoset_featured');
add_action('save_post', 'autoset_featured');
add_action('draft_to_publish', 'autoset_featured');
add_action('new_to_publish', 'autoset_featured');
add_action('pending_to_publish', 'autoset_featured');
add_action('future_to_publish', 'autoset_featured');

  • 3SixtyEvolve

    Hi M.O.R.E.

    Greetings from the WPMU DEV Team!

    Further to your requests above, I've flagged the Developer for feedback. Unfortunately I am not too sure how to achieve the style you're looking for and would rather leave that to the experts.

    I understand your frustration in trying to get this resolved, but I would appreciate it if you allow us some time to get back to you with feedback / or a solution.

    And if you require any further assistance with any other topic/ plugin, please don't hesitate to be in touch.

    Gina :: Multiplicity
    Trying out as WPMU DEV Support Staff - Let me know how I go

  • M.O.R.E.

    Thanks everybody

    I am using only the above mentioned code in blognews template to fetch the thumbnail and nothing else

    <div class="post-meta">
    <?php framemarket_postedon(); ?>
    </div>
    <div class="entry-summary">
    <?php the_post_thumbnail('thumbnail',array('style'=>'float:left;margin-right:10px;'));?>
    <?php the_excerpt(); ?>
    </div>

    The images are not displaying onto the page from the very beginning...I've created one page gave it a title "Blog" and selected the BlogNews Template....that's it....it's showing images when gets inserted in post but it should also fetch the featured image and show it like it's happening with MP products

    Sorry for constantly bugging like this
    :slight_smile:

  • 3SixtyEvolve

    Hi M.O.R.E.

    You're definitely not bugging us :slight_smile: It's a pleasure to try and assist, and of course, that's what we're here for.

    I will ask the Developer, Tammie to pitch in, because I'm not too sure how the code you're using will affect the Theme design. And she's the expert after all :slight_smile:

    (I will play around on a test installation and see if I can find any answers, but I'm more a visual type of gal, so lots of code just gets my head spinning.)

    Will be on standby for any further feedback from Tammie or you.

    Have a good day!

    Gina :: Multiplicity
    Trying out as WPMU DEV Support Staff - Let me know how I go

  • M.O.R.E.

    Gina I'm also a visual person....building my site piece-by-piece with trial and error method....don't understand most of the stuff....eagerly reading everything the team discusses with others in this forum...which I must say is a storehouse of information....apparently this is my first website in wordpress...thought of giving it a try when my coder left (who did my other sites)...and I'm determined to build it no matter what it takes...and all with support from you wonderful people......:slight_smile:

  • Mason

    Hiya M.O.R.E.,

    There's several ways to tackle this one actually. As you're creating a child theme of FrameMarket (nice work by the way) you may want to look at another one of our themes, SimpleMarket:
    https://premium.wpmudev.org/project/simplemarket

    It is also a child-theme of FrameMarket and provides for a featured thumbnail image in the Blog template by default. Check out the code in template-blog.php and in content.php for how this is accomplished.

    You seem to already have code that is working for you in creating thumbnails on the blog template though. If that's working for you then terrific!

    To get the featured thumbnail to display on an individual post, you'll also need to add the code to your child theme's single.php file.

    You can do this in the same way by calling:
    <?php the_post_thumbnail();?>

    I'd also note that you can easily define the size by using one of your 3 preset thumbnail sizes (as set in Settings > Media) for your featured image, or you can dictate a new size altogether. You’ll change the thumbnail call according to which size you want it:
    Large
    <?php the_post_thumbnail('large');?>
    Medium
    <?php the_post_thumbnail('medium');?>
    Thumbnail
    <?php the_post_thumbnail('thumbnail');?>
    Custom size
    <?php the_post_thumbnail( array (width,height) );?>

    For the custom size, replace width and height with the number of pixels that each length should be. For example, to show an image 300 pixels wide and 200 pixels high, use:
    <?php the_post_thumbnail( array (300,200) );?>

    Hope this helps a bit. Just make sure the above code exists inside the loop on your single.php page (or content-single.php if you're following the SimpleMarket example) and you'll be good to go.

    Thanks!

  • M.O.R.E.

    Thank you, Thank you Aecnu, GinaB, Tammie, Masonjames and others....finally its sorted...only wish to know how do I control it's appearence....right now its appearing in this order

    Image > title > meta > text > comment box

    But want to display in this order

    1) Title
    2) Image
    3) Text
    4) Meta & other details

    This is the order in single.php how do I change the order? Or do I have to do it in template-blognews.php

    <?php get_header(); ?>
    <div id="content">
    <?php if($bp_existed == 'true') : ?>
    <?php do_action( 'bp_before_blog_single_post' ) ?>
    <?php endif; ?>
    <?php the_post_thumbnail();?>
    <?php get_template_part( 'content', 'single' ); ?>
    <?php if($bp_existed == 'true') : ?>
    <?php do_action( 'bp_after_blog_single_post' ) ?>
    <?php endif; ?>
    </div>
    <?php get_sidebar(); ?>
    <?php get_footer() ?>

    Thanks once again

  • M.O.R.E.

    Would also love to include

    1) an "avatar" of the person along with name (which is there now) who is posting that article/news....
    2) caption under the image

    <div xmlns="http://www.w3.org/1999/xhtml" class="byline">
    <img width="75" height="75" alt="Member's Name" src="Avatar Link" class="avatar photo avatar-default"/> <p class="store-by">
    Story by member's name </p>
    <p class="published">
    Published on <span class="posted">Month, Date, Year</span> in Read </p>
    </div>

    3) and 4 related item's (image and small text)

    <h4>Related Items</h4>
    <ul class="listings clear">
    <li class="listing-card ">

    <img alt="(Image Title)" src="Image Link"/>

    <div class="listing-detail ">

    <p class="listing-title">
    ()
    </p>
    <p class="listing-maker">
    ()
    </p>
    </div>

    if I use custom field I do have to assign a place for that in the single.php ...how can I call that? And where should I post the code?

    Thanks

  • M.O.R.E.

    Somehow it got missed...so re-posting it.....any advice appreciated....the issue is

    Where can I post a code like this for fetching (underneath the image)
    1) an "avatar" of the person along with name (which is there now) who is posting that article/news....
    2) caption under the image

    <div id="content">
                                    <div id="post-number" class="post-number post type-post status-publish format-standard hentry category-blogs">
                        <h1 class='post-title'>TITLE TO APPEAR</h1>
                        <img src="#" alt="" class="main" />                    <div class='byline'>
                            <img class="avatar photo avatar-default" src="#" alt="" width="150" height="150" >                        <p class='store-by'>
                                Story by <a href="#" class="profile">NAME</a>                        </p>
                            <p class='published'>
    <div class="post-meta">
    Published on <span class="meta-prep meta-prep-author">Posted on</span> <a href="#" title="TIME" rel="bookmark"><span class="entry-date">MONTH DATE, YEAR</span></a> by <span class="author vcard"><a class="url fn n" href="#" title="View all posts by admin">admin</a></span></p>                    </div>

    3) and 4 related item's (image and small text)

    <div class="seller-items clear">
                <h4>Seller's Items</h4>
                <ul class="listings clear">
                                    <li class="listing-card ">
                        <a class="listing-thumb" href="#" title="">
                                                    <img src="#" alt="">
                                                </a>
                        <div class="listing-detail ">
                            <p class="listing-title">
                                <a href="#" title="">TITLE TO COME</a>
                            </p>
                            <p class="listing-maker">
                                <a href="#" title="Check out">SELLER"S NAME</a>
                            </p>
                        </div>
                    </li>

    if I use custom field I do have to assign a place for that in the single.php ...how can I call that? And where should I post the code (if this is the right code that is)?

    Thanks

  • M.O.R.E.

    This also got missed....can anyone help me on this please

    I wish to know how do I control it's appearence....right now its appearing in this order

    Image > title > meta > text > comment box

    But want to display in this order

    1) Title
    2) Image
    3) Text
    4) Meta & other details

    This is the order in single.php how do I change the order? Or do I have to do it in template-blognews.php

    <?php get_header(); ?>
    <div id="content">
    <?php if($bp_existed == 'true') : ?>
    <?php do_action( 'bp_before_blog_single_post' ) ?>
    <?php endif; ?>
    <?php the_post_thumbnail();?>
    <?php get_template_part( 'content', 'single' ); ?>
    <?php if($bp_existed == 'true') : ?>
    <?php do_action( 'bp_after_blog_single_post' ) ?>
    <?php endif; ?>
    </div>
    <?php get_sidebar(); ?>
    <?php get_footer() ?>

    Thanks once again

  • aecnu

    Greetings M.O.R.E.,

    Your not being missed, unfortunately Mason has been out ill for awhile and I happened to stumble upon your thread buried in the support system. I will try to be of assistance.

    <?php get_header(); ?>
    <div id="content">
    <?php the_post_thumbnail();?>
    <?php if($bp_existed == 'true') : ?>
    <?php do_action( 'bp_before_blog_single_post' ) ?>
    <?php endif; ?>
    <?php get_template_part( 'content', 'single' ); ?>
    <?php if($bp_existed == 'true') : ?>
    <?php do_action( 'bp_after_blog_single_post' ) ?>
    <?php endif; ?>
    </div>
    <?php get_sidebar(); ?>
    <?php get_footer() ?>

    Please advise what the results show with this small change. I moved the thumbnail code up three lines.

    Cheers, Joe :slight_smile:

  • 3SixtyEvolve

    Hi M.O.R.E

    Hope you're well.

    I've been following this thread and am glad for the assistance provided by our Senior Support Team.

    Now from your last screenshots and requirements mentioned on it, I believe that it's only the code that needs to be reshuffled and of course a bit of customization for the spacing that you want after Meta and Post.

    Can I have a look at your code for this page again? If it is too long (more than 10 lines), then just add it to pastebin.com and send the link for the code to me.

    I'm sure we can get it sorted for you.

    Have a good day and waiting for your feedback.

    GinaB

  • M.O.R.E.

    Hi GinaB....thank you...and here's the code for the single.php page

    <?php get_header(); ?>
    <div id="content">
    <?php the_post_thumbnail( 'singlepost-thumb', array ('style'=>'margin:0px 0px 20px 0px;' ) );?>
    <?php if($bp_existed == 'true') : ?>
    <?php do_action( 'bp_before_blog_single_post' ) ?>
    <?php endif; ?>
    <?php get_template_part( 'content', 'single' ); ?>
    <?php get_the_term_list( $id, $taxonomy, $before, $sep, $after ) ?>
    <?php if($bp_existed == 'true') : ?>
    <?php do_action( 'bp_after_blog_single_post' ) ?>
    <?php endif; ?>
    </div>
    <?php get_sidebar(); ?>
    <?php get_footer() ?>

  • Mason

    Hiya MORE,

    This is a bit more complex of customization (as you've noticed :smiley:)

    The tricky part is this line:
    <?php get_template_part( 'content', 'single' ); ?>

    That line is pulling in content-single.php (in your theme's root) and display it's content in a specific order.

    So your options are to edit your content-single.php file (which will effect the order for all post types) or you can make a copy of content-single.php with a new title like content-product.php for example.

    Then change the part in your file above to read:
    <?php get_template_part( 'content', 'product' ); ?>

    Now you can edit content-product to move the title and other elements around. Note: you'll need to move the_post_thumbnail portion into the new file in order to get it to appear below the title.

    There's several other ways to do it (you could just copy all the content-product.php in your main file in place of the get_template_part line.

    Hope this helps. It's a customization that goes a bit beyond what we can actually code for you hear in the forums. A little trial and error though, and I bet you can get there.

    Thanks!

  • 3SixtyEvolve

    @Mason
    Thank you for the great feedback and suggestions to M.O.R.E. I've been investigating and researching on what solution I could offer, but nothing came up.

    @M.O.R.E.
    As Mason pointed out, this is more customized coding and a bit beyond the scope that we support here in the forum. I was going through PHP e-books and even asking PHP developers for possible solutions and I couldn't come up with a solution. It seems it is a simple matter of trial and error.

    Hope you get sorted. I tried :slight_smile:

    Have a good day.

    GinaB

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.