Forums

Display custom field post data in grid (6 posts)

  1. jungledsales
    Member
    Posted 3 years ago #

    I have used custom fields for a post image and a couple download links on several posts. I want to display all these posts in a grid format on a page like the homepage.

    This page (http://www.hkties.com/products/modular-precasts-vertical-pour/) will contain posts with images and titles like this page (http://www.hkties.com/standard-8-tie-st200/)

    The site is live but these pages are not being used yet until I can figure out how to pull out a table of the custom field images and their corresponding post titles.

    I have tried all sorts of things but none of them quite work... any direction?

  2. Dgold
    Member
    Posted 3 years ago #

    One method is:

    Create your Table as an HTML table (if you really want it in a Table. If not then position everything with CSS divs).

    Where-ever you want the custom field value (your image) to appear (like say in the top-right box of your table), put the code as described here:
    http://codex.wordpress.org/Function_Reference/get_post_custom_values

    That will call-in your custom field value (say the custom field has the key "My Image" and the value is some HTML code for img src="my-image.jpg").

    Does that help?

  3. jungledsales
    Member
    Posted 3 years ago #

    Well sort of... except I don't know how to call the custom fields from an entire category. I want to be able to add more posts and have this page automatically update and add more fields to the grid.

  4. Dgold
    Member
    Posted 3 years ago #

    Use the get_post_custom_values (that I linked instructions above)

    use it inside a Loop in your theme's custom page template (modular-precasts-page-template.php), and it will keep adding for each post that the query picks up
    http://codex.wordpress.org/The_Loop

    If you want to limit it to a certain category, that's another tweak on the query, but you could save that task until later. For now focus on pulling in allllll the posts that have your "Image For The Post" custom field regardless of category. Next, when you're getting all the images, focus on pulling the Post Title that goes with each image. Next, focus on formatting your title + picture into the grid layout that you want (style, CSS, or table it). Finally, tweak your query if needed to limit the # that shows up, or the category it pulls from.

    I'm mainly able to describe this and give you the Codex links. My perspective is, you'll have to do some studying and try different things. Make some progress, see what you can get to show up, and if you have a specific code question then post again with details.

  5. jungledsales
    Member
    Posted 3 years ago #

    Ok I got this working finally, but then I did an update to 2.6.5 and it broke. The code below was working and now it's not. Any suggestions?

    <?php while (have_posts()) : the_post();
    			$thumb = get_post_meta($post->ID, 'Thumbnail', $single = true);
    			?>
    			<div id="grid">
    			<div class="productsgrid">
    				<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    				    <?php
    					  	if($thumb !== '') { ?>
    						<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
    					  	<img src="<?php echo $thumb; ?>"
    					  	class="grid-thumbnail-class"
    					  	alt="<?php if($thumb_alt !== '') { echo $thumb_alt; } else { echo the_title(); } ?>"
    					  	/>
    						</a>
    						<div style="clear:both;"></div>
    					  <?php }
    					  else { echo ''; } ?>
    			</div>
    			</div>
  6. Adam W. Warner
    Member
    Posted 3 years ago #

    I noticed you've accomplished this, and it looks great! Would you care to share the completed code here?

    I also wonder if you could use the get_the_image template tag instead of a custom field?

    Thanks if you can help:)

Topic Closed

This topic has been closed to new replies.

About this Topic