Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

How to display images from custom fields in a block grid #257

Closed
JuliaRietveld opened this issue Mar 4, 2015 · 2 comments
Closed

How to display images from custom fields in a block grid #257

JuliaRietveld opened this issue Mar 4, 2015 · 2 comments

Comments

@JuliaRietveld
Copy link

Hi, many thanks to you who wants to help me solve this challenge!
So I have a row with 4 columns in a block grid. I want to display the title and an image of 4 child pages of a specific parent page. I'm using custom fields pair 'img_thumb' - 'path/to/image' to set up the image. But the image is not showing up and I get a black screen most of the times. I must be doing something wrong.
Thank you again for your help!

http://pastebin.com/gdnZbMjH

@ghost
Copy link

ghost commented Mar 5, 2015

MrsColombo,

here's a function I've been using to list childpages of the current page. No need for custom image fields, just use WP core featured image.

See difference between $post->ID (current page) and $pageChild->ID ?

You can easily modify this function/query to work on any page just by editing post_parent.

<ul class="small-block-grid-2 medium-block-grid-3 large-block-grid-4">

<?php $pageChildren = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$post->ID' AND post_type = 'page' AND post_status='publish' ORDER BY menu_order", 'OBJECT'); 
if ( $pageChildren ) : foreach ( $pageChildren as $pageChild ) : setup_postdata( $pageChild ); ?>

<li><a href="<?php echo get_permalink($pageChild->ID);?>" title="<?php echo ($pageChild->post_title); ?>"><?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($pageChild->ID), 'post-thumbnail' );$url = $thumb['0']; ?><img class="fade" src="<?php echo esc_url($url); ?>" alt="" /></a><h3 class="pagechild-title"><a href="<?php echo get_permalink($pageChild->ID);?>" title="<?php echo ($pageChild->post_title); ?>"><?php echo ($pageChild->post_title); ?></a></h3></li>

<?php endforeach; endif; ?>

</ul>

@olefredrik
Copy link
Owner

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants