Linking to Images with PHP (4 posts)

  1. jlbarnes2
    Posted 1 year ago #

    Hello, all,

    I'm having trouble linking to images in my media library with PHP. On my homepage there is a slider (Flexslider) that should show three different images next to text. Here's my HTML and PHP:

    <div class="grid-8 center flexslider white-bg boxhgt-med">
        	<ul class="slides">
                    $args = array(
                        'post_type' => 'featured',
    		    'orderby'=> 'rand',);
                    $the_query = new WP_Query( $args );
                    $slideshow_query = new WP_Query( $args );?>
                <?php if ( have_posts() ) : while ( $slideshow_query->have_posts() ) : $slideshow_query->the_post(); ?>
                        <div class="grid-4">
                            <?php echo the_content(); ?>
                            <h6 class="button"><a href="<?php echo the_field( 'featured_url' ); ?>">Learn More</a></h6>
                        <div class="grid-4 omega">
                            <img src="<?php the_field( 'event_image' ); ?>">
    			<?php endwhile; else: ?>
                               <p><?php _e('Sorry, no pages here.'); ?></p>
                            <?php endif; ?>

    All the PHP works except the images. Here's a link to one of the images that's supposed to show up.

  2. stephencottontail
    Posted 1 year ago #

    I'm not entirely familiar with how ACF works, but you may want to use print_r() or var_dump() to check the output of the_field() because I get these errors when I visit your site:

    Failed to load resource: the server responded with a status of 404 (Not Found)
  3. jlbarnes2
    Posted 1 year ago #

    How do I use those to check output? I'm not familiar with those commands.

    In the meantime I used the direct URL to get the page at least looking right.

    Thank you for your help!

  4. stephencottontail
    Posted 1 year ago #

    Post the output of var_dump( get_field( 'featured_url' ) ); and var_dump( get_field( 'event_image' ) ). I suspect get_field() is returning more data than you expect.

Topic Closed

This topic has been closed to new replies.

About this Topic