0

Can someone help me change this theme to pull the images in the sidebar from the custom field "sidebar" of each post, instead of the featured image, like it is now. The frame and link can stay the same, I just need the image to come from the custom field instead of the featured image.

        <div id="content" class="city_page">
        <div id="inner_sidebar">
            <?php
                $mypages = get_pages( array( 'child_of' => 9, 'sort_column' => 'post_title', 'sort_order' => 'asc' ) );

                foreach( $mypages as $page ) {      
                    $content = $page->post_content;
                    if ( ! $content ) // Check for empty page
                        continue;

                    $content = apply_filters( 'the_content', $content );
                ?>
                <div class="item city">
                    <?php echo get_the_post_thumbnail($page->ID, 'thumbnail'); ?>
                    <a href="<?php echo get_page_link( $page->ID ); ?>"><img class="frame" src="<?php bloginfo('url'); ?>/images/city_image_frame_thumb.png" alt="" /></a>
                    <a class="title" href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a>
                </div>
                <?php
                }   
            ?>
        </div>
0

2 Answers 2

1

As long as your are placing an image URL in the "sidebar" custom field you can replace the entire img src with the following.

<?php echo get_post_meta($post->ID, 'sidebar', true) ?>

You can learn more about the get_post_meta for thumbnail urls here: http://codex.wordpress.org/Function_Reference/get_post_meta#Retrieve_a_Custom_Field_Thumbnail_Url

Hope that helps!

Sign up to request clarification or add additional context in comments.

Comments

0

Personally, I am a huge fan of the Advanced Custom Fields plugin. It is one of the first plugins I install in a new WordPress installation. It is really flexible and has a simple API for getting and setting custom fields.

Check it out!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.