0
votes

I'm trying to show the featured image or the post thumbnail in every list items < li >. Here's the code:

<div class="row headline">
                <ul class="col-md-12 col-sm-12">
                    <?php 
                    $sql_submenu_produk_sql = $wpdb->get_results("
                        SELECT * from $wpdb->posts 
                        WHERE post_parent=52 AND post_type='page' AND post_status='publish' group by ID;
                    "); 
                    ?>

                    <?php foreach ($sql_submenu_produk_sql as $row_submenu_sql) { ?>
                        <li>
                            <div class="col-md-2 col-xs-12 bordered" style="min-height: 100px;">
                                <a href="" data-featherlight="image">
                                <?php echo get_the_post_thumbnail($post->ID); ?>
                                </a>
                            </div>
                            <div class="col-md-10 col-xs-12">
                                <h2 style="font-weight: normal;"><?php echo $row_submenu_sql->post_title ?></h2>
                                <p style="padding-bottom: 15px;"><?php echo $row_submenu_sql->post_content ?></p>
                            </div>
                        </li>
                    <?php } ;?>
                </ul>
            </div>

but, it's not showing after all while on the other page shows. Please help.

1

1 Answers

0
votes

Should you have get_the_post_thumbnail($row_submenu_sql->ID); and not $row_submenu_sql->ID $post->ID is not defined in that loop.

<div class="row headline">
                <ul class="col-md-12 col-sm-12">
                    <?php 
                    $sql_submenu_produk_sql = $wpdb->get_results("
                        SELECT * from $wpdb->posts 
                        WHERE post_parent=52 AND post_type='page' AND post_status='publish' group by ID;
                    "); 
                    ?>

                    <?php foreach ($sql_submenu_produk_sql as $row_submenu_sql) { ?>
                        <li>
                            <div class="col-md-2 col-xs-12 bordered" style="min-height: 100px;">
                                <a href="" data-featherlight="image">
                                //UPDATE THIS LINE LIKE BELOW
                                <?php echo get_the_post_thumbnail($row_submenu_sql->ID); ?>
                                </a>
                            </div>
                            <div class="col-md-10 col-xs-12">
                                <h2 style="font-weight: normal;"><?php echo $row_submenu_sql->post_title ?></h2>
                                <p style="padding-bottom: 15px;"><?php echo $row_submenu_sql->post_content ?></p>
                            </div>
                        </li>
                    <?php } ;?>
                </ul>
            </div>