Support

Account

Home Forums General Issues Image Doesn't Show Up

Solving

Image Doesn't Show Up

  • Hi,

    I’m currently building my wordpress site locally, and have ACF installed.

    I used this codex to display child pages on their parent page;

    http://codex.wordpress.org/Function_Reference/get_pages#Displaying_Child_pages_of_the_current_page_in_post_format

    Each child page has image fields. I tried to display the images by using this code;

    <img src="<?php the_field('image1'); ?>" alt="" />

    But no image shows up. I’m suspecting it has to do with the above codex I’m using, but can’t figure out what the issue is.

    I’d appreciate your help!

    Best,
    Jaeeun

  • Hi @sleepydada

    Have you read over the documentation for the image field yet? Perhaps go and do that, so you fully understand how the return types effect the front end code.

    Your issue may also be that you need to target the ‘child’ pages using the $post_id parameter of the get_field / the_field function.

    Thanks
    E

  • Hi,

    I tried this code

    <?php the_field('image1', 80); ?>

    But the image still doesn’t show up.

    Also, is there a way to target all the child pages in general, instead of targeting a specific child page by its ID?

    Thanks,
    Jaeeun

  • Hi @sleepydada

    1. What is the return type for the image field?
    2. Where are you using this code? Can you provide full context (eg: wrapping element?)
    3. What is 80?

    All pages? You will need to get these ID’s from a WP query (get_posts) and then loop through them to output the image element.

    Thanks
    E

  • Hi Elliot,

    1. THe return type is URL
    1. I’m using the code in this archive-blog.php that I created a custom post type “blog.” I want to show up the images next to texts. Here;

    http://www.ducklingfarm.com/

    3. 80 is the page is of the child page “Our People”

    Thanks,

    Jaeeun

  • Hi @sleepydada

    Can you confirm that you are editing the correct template file for the URL you expect the images to show on? You can test this by adding some static html to the template:
    <p>test</p>

    It is important that you are 100% sure that the get_field function is being called, before I can help you debug the issue.

  • Hi Elliot,

    I pasted it into the page, as you can see;

    http://www.ducklingfarm.com

    This page is the parent page of the pages “Our Products” and “Our People” from which I’m trying to pull the image fields from.

    Thanks.

  • This is the php file for the page;

    <?php
    /*
    Template Name: Abous Us - Parent
    */
    ?>
    <p>test</p>
    <?php get_header(); ?>
    
     <div id="content" class="group">
    
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    				
    	<?php
    	$mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc' ) );
    
    	foreach( $mypages as $page ) {		
    		$content = $page->post_content;
    		$content = apply_filters( 'the_content', $content );
    	?>
    		<div id="aboutSub"><div class="entryHeader"><?php echo $page->post_title; ?></div>
    		<div class="entry"><?php echo $content; ?><img src="<?php the_field('image1'); ?>" alt="" /></div></div>
    	<?php
    	}	
    ?>	
    
    	<?php endwhile; endif; ?>
    </div><!-- END content -->
    
    <?php get_footer(); ?>

    Child pages use default page templates.

  • Hi @sleepydada

    to load data from another page, you need to specify the post_id parameter. Please read this tutorial:
    http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-another-page/

    Thanks
    E

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘Image Doesn't Show Up’ is closed to new replies.