文本移出标题标记


Text moves out of Heading Tags

我的h2标记中的文本浮动到除法的顶部。我觉得我的眼睛可能忽略了什么,导致帖子的标题飘到了分区的顶部。不幸的是,我看不到我输出tite的另一个区域。

这是我的HTML/PHP。我为这场混乱道歉。

<!-- locations page array -->
                <?php $args = array( 'post_type' => 'weblizar_portfolio','posts_per_page' => -1 );  
                    $portfolio = new WP_Query( $args );      
                    if( $portfolio->have_posts() )
                    { while ( $portfolio->have_posts() ) : $portfolio->the_post(); ?>           
                            <div class="col-lg-4 col-md-4">
                                <!--<div class="img-wrapper">-->            
                                    <?php $defalt_arg = array('class' => "enigma_img_responsive");
                                        $portfolio_button_link = get_post_permalink( $sample );
                                        $dates = get_post_meta(get_the_ID(), 'date', true);
                                        $postTitle = the_title(); ?>
                                    <?php if(!isMobile()){ ?>
                                        <a href='<?php echo $portfolio_button_link; ?>'>
                                        <div class="author-item">
                                            <div class="imageItem">
                                                <?php if(has_post_thumbnail()): 
                                                    the_post_thumbnail('portfo_4_thumb', $defalt_arg);
                                                    $port_thumbnail_id = get_post_thumbnail_id();
                                                    $image_thumbnail_url = wp_get_attachment_url($port_thumbnail_id);
                                                endif; ?>
                                            </div>
                                            <div class="author-info">
                                                <!-- THIS IS THE AREA NOT WORKING -->
                                                <h2><?php echo $postTitle; ?></h2>
                                                <h4><?php echo $dates; ?></h4>
                                            </div>
                                        </div>
                                        </a>
                                    <?php } else { ?>
                                    <table>
                                        <a href='<?php echo $portfolio_button_link;?>'>
                                        <tr>
                                            <td>
                                                <?php echo $postTitle;?>
                                            </td>
                                            <td>
                                                <?php echo $dates; ?>
                                            </td>
                                        </tr>
                                        </a>
                                    </table>
                                    <?php } ?>

这是执行的html:

<div class="col-lg-4 col-md-4">
                                <!--<div class="img-wrapper">-->            
                                    San Jose                                                                                    <a href="">
                                        <div class="author-item">
                                            <div class="imageItem">
                                                <img width="260" height="160" src="" class="enigma_img_responsive wp-post-image" alt="San Antonio" srcset="" sizes="(max-width: 260px) 100vw, 260px">                                               </div>
                                            <div class="author-info">
                                                <h2></h2>
                                                <h4>April 23rd, 2016</h4>
                                            </div>
                                        </div>
                                        </a>
                                <!--</div>-->
                            </div>

您应该将the_title替换为get_the_title。原因是the_title只是在你使用它的任何地方回显标题,而get_the_title则返回它(这就是你想要的)。

编辑:

另一个解决方案是调用the_title(),其中显示h2标签如下:

 <h2><?php the_title() ?></h2>