get_post_custom
-
I want to grab the name of the icon file from a custom field and display it before the content of a specific post on my homepage. There are only 3 specific posts I want displayed.
After a LOT of trial and error, I have something that works (yay me!), but I would like someone much smarter than I to have a peek and let me know if this is inefficient, or if I am possible opening myself up for trouble later because of a poor attempt.
<div class="col"> <?php $this_post="112"; $custom_fields = get_post_custom($this_post); $icon = $custom_fields['icon']; echo "<img src=\"" . get_bloginfo('template_directory') . "/css/" . $icon[0] . "\" alt='' />" ; $queried_post = get_post($this_post); echo "<h2>" . $queried_post->post_title . "</h2>"; echo $queried_post->post_content; ?> </div> <!-- col --> <div class="col"> <?php $this_post="114"; $custom_fields = get_post_custom($this_post); $icon = $custom_fields['icon']; echo "<img src=\"" . get_bloginfo('template_directory') . "/css/" . $icon[0] . "\" alt='' />" ; $queried_post = get_post($this_post); echo "<h2>" . $queried_post->post_title . "</h2>"; echo $queried_post->post_content; ?> </div> <!-- col --> <div class="col"> <?php $this_post="116"; $custom_fields = get_post_custom($this_post); $icon = $custom_fields['icon']; echo "<img src=\"" . get_bloginfo('template_directory') . "/css/" . $icon[0] . "\" alt='' />" ; $queried_post = get_post($this_post); echo "<h2>" . $queried_post->post_title . "</h2>"; echo $queried_post->post_content; ?> </div> <!-- col -->
The above code is not inside the loop because it seems to work well without it.
- The topic ‘get_post_custom’ is closed to new replies.