• I am trying to call a specific category post to my front page including the feature image (which becomes the background image in the section) and title. Below are the snippets but for some reason nothing is showing up. Any tips would be appreciated.

    Here is the link to my website

    http://www.johannesterry.ca/joie/

    <!-- FEATURE BLOGS -->
    	<?php
    		$feature_posts = array_reverse(get_posts(array(
                            'posts_per_page'   => 3,
                            'offset'           => 0,
                            'category_name'    => 'feature-posts')));
        ?>
    
        <?php foreach($feature_posts as $feature_post): ?>
    	<?php $post_custom_fields = get_post_meta($feature_post->ID); ?>
    
        <div id="info-box-sect" class="info-box-sect">
    		<div class="expanded row">
    
    		  	<!-- BOXES REPEAT -->
    
    		  	<div class="medium-4 columns box"
    		  		style="background: linear-gradient( rgba(109, 30, 42, 0.4), rgba(109, 30, 42, 0.4) ), url('<?php echo $image[0]; ?>'); background-size: cover;">
    
    		    	<span class="joie-category"><?php echo $post_custom_fields['main_category'][0];?></span>
    
    			    <div class="medium-9 outside-box">
    			      <div class="inside-box blg-title">
    
    			        <h4><?php echo $feature_posts->post_title; ?></h4>
    
    			      </div>
    			    </div>
    
    		  	</div><!-- BOXES END -->
    			<?php endforeach; ?>
    
    		</div>
        </div>
Viewing 3 replies - 1 through 3 (of 3 total)
  • nothing is showing up

    apart from the background images, which are not defined in the code, there is a lot showing up.

    Richard

    (@richardcoffee)

    I see a couple of things:

    The line <h4><?php echo $feature_posts->post_title; ?></h4> has an error in it. It should be <h4><?php echo $feature_post->post_title; ?></h4>.

    Also, as already pointed out, the image url is never defined.

    You shouldn’t need the array_reverse() call. Just add 'order' => 'ASC' to the array.

    Moderator bcworkz

    (@bcworkz)

    You’d typically want to specify what post meta data you want by key name instead of getting all post meta. Perhaps get_post_meta($feature_post->ID, '_thumbnail_id')

    Then you would need to get the image’s URL. wp_get_attachment_url() can be used for this. Finally, you’d need to define the image as a background style by either outputting a <style> block or the ‘style’ attribute of some HTML element.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Calling specific category to front page’ is closed to new replies.