Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Konrad Pilch
Konrad Pilch
2,435 Points

What is wrong with this one?

My images doesnt display, and something gets array in the bottom

<?php get_header(); ?>

<?php
/*
    Template Name: Portfolio
*/
?>

  <!-- Home Page -->
<div class="main-wrapper">
    <div class="container">
        <div class="row">



        <div class="container">
            <div class="" id="portfolio">

                <h1>MY FEATURED PROJECTS</h1>


                <div class="row">

                    <?php
                        $args = array( 
                          'post_type' => 'portfolio'
                        );
                        $the_query = new WP_Query( $args );

                      ?>

                    <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

                        <div class="col-xs-6 col-md-3 new-portfolio">
                            <div class="project-tab">
                                <a href="<?php the_permalink(); ?>"><h4><?php the_title(); ?></h4></a>

                                <a href="<?php the_permalink(); ?>">
                                    <img class="portolio-image" src="assets/img/webpor.jpg">
                                </a>

                                <a href="<?php the_permalink(); ?>">

                                    <img class="portolio-image-secondary" src="assets/img/webpor.jpg">

                                    <?php echo get_field('image');?>

                                </a>

                            </div><!-- /project-tab -->
                        </div><!-- /col-xs-6 col-md-3 -->
                    <?php endwhile; endif;?>



                </div><!-- /row -->
            </div><!-- /portfolio -->
        </div>


<?php get_footer(); ?>
Jeff Kinley
Jeff Kinley
21,207 Points

Hi Dennis, just noticed that you have your answer in the comments section. You should move it over the answer section. I made the same mistake yesterday.

1 Answer

Konrad Pilch
Konrad Pilch
2,435 Points

HI, im using Custome Post Fields. I cant use post thumbnail code since its not from thumbnail. I used custome post types to get an image and i gaved it image nam. What i had to do is to create a variable and well basically this:

 <a href="<?php echo get_field( 'link' ); ?>" target="_blank">
                                <?php 
                                $image = get_field('image');

                                if( !empty($image) ): ?>

                                    <img class="portolio-image" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />

                                <?php endif; ?>

                                </a>


                                 <a href="<?php echo get_field( 'link' ); ?>" target="_blank">
                                   <?php  if( !empty($image) ): ?>
                                    <img class="portolio-image-secondary" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
                                    <?php endif; ?>
                                </a>

And it worked. Its in ACF documentation.

But thank you anyways for the help :)