Get Post Thumbnails for custom menu
-
Hi there,
I’m currently designing my website, and I thought a custom theme is the way to go, so I can implement my ideas as I wish.
I mocked up the website as I want it to be (see here: https://lh3.googleusercontent.com/E5kOO142XCj4DcX0t_SgIJ0HpOFQMndiXscsuDWKylU=w1440-h900-rw), however that is just a static mockup to see how I want the website to look like (at least the left).
Now I want to make things automatic. I have a page structure which will be used to put everything in the right order (and new categories for the menu can be easily added).
So far, I’ve got the pages listed in the order I want; however, I can’t seem to be able to load the featured images (thumbnails).
<!DOCTYPE html > <!-- <div class="left-separator" ></div> --> <html > <?php $post = NULL; $defaults = array( 'child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_date', 'hierarchical' => 1, 'exclude' => array(), 'include' => array(), 'meta_key' => '', 'meta_value' => '', 'authors' => '', 'parent' => -1, 'exclude_tree' => array(), 'number' => '', 'offset' => 0, 'post_type' => 'page', 'post_status' => 'publish', ); $pages = get_pages($defaults); //var_dump($pages); foreach ($pages as $page) { if ($page->post_parent === 0) { // Page is a parent, only has children. // Only do stuff here, ignore the rest... //var_dump($page); die(); $id = $page->ID; $children = get_page_children($id, $pages); //var_dump($children); $_children = ""; $thumbnail = get_the_post_thumbnail($id); foreach ($children as $child) { $_children .= "<li >"; $_children .= $child->post_title; $_children .= "</li>"; } $html = " <div class='left-menu-container' > <ul > <li > $page->post_title <ul > $_children </ul> </li> </ul> </div> <div class='left-separator' ></div> "; echo $html; } else continue; } ?> </html>
That is my code; it’s based off of the code I used to get the posts on the homepage, which works perfectly fine.
Now, to describe the problem a bit more accurately; if I use get_the_post_thumbnail($id), I don’t get any image at all.
If, however, I use the_post_thumbnail($id), I get my little test piggy, which I used to test the post slider.Has anyone experienced this before, and is there a way around it?
Thanks a lot in advance for any help!
Website for previewing is: https://www.ca-softworks.com/?loadPreview=1
- The topic ‘Get Post Thumbnails for custom menu’ is closed to new replies.