【问题标题】:How can I fix this code for wordpress theme [duplicate]如何为wordpress主题修复此代码[重复]
【发布时间】:2016-12-30 21:36:27
【问题描述】:

我想在 wordpress 主题中使用此代码。

    <ul>
  <?php
    $args = array( 'numberposts' => '5' );
    $recent_posts = wp_get_recent_posts( $args );
    foreach( $recent_posts as $recent ){
        echo '<li>
                <span class="l-e-right"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php echo the_post_thumbnail('large-thumb'); ?></a></span>
                    <h4><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
                        <time datetime="<?php the_date('j F Y'); ?>"><?php the_date('j F Y'); ?></time>
                <div class="clearfix"></div>
            </li>'
            }
    wp_reset_query();
  ?>
</ul>

但是有问题!

解析错误:语法错误,意外“大”(T_STRING),预期 ',' 或者 ';'在

如何修复此代码?

谢谢...

【问题讨论】:

  • 未转义的单引号
  • 您可以使用echo '&lt;a href="' . the_permalink() . '"&gt;Link&lt;/a&gt; 来避免所有这些&lt;?

标签: php html wordpress


【解决方案1】:

你没有正确地关闭标签。 试试这个:

 <?php
    $args = array( 'numberposts' => '5' );
    $recent_posts = wp_get_recent_posts( $args );
    foreach( $recent_posts as $recent ){ ?>
       <li>
                <span class="l-e-right"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php echo the_post_thumbnail('large-thumb'); ?></a></span>
                    <h4><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
                        <time datetime="<?php the_date('j F Y'); ?>"><?php the_date('j F Y'); ?></time>
                <div class="clearfix"></div>
            </li>
   <?php
            }
    wp_reset_query();
  ?>

【讨论】:

    【解决方案2】:

    作为一般规则,您可以通过以下方式修复难以阅读的代码中的语法错误

    a) 改进代码布局,直到错误明显 b) 删除有问题的代码块并逐渐放回去

    【讨论】:

      【解决方案3】:

      在字符串末尾添加一个;(使用生成的 HTML 代码)。

      【讨论】:

        猜你喜欢
        • 2017-01-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-01
        • 1970-01-01
        相关资源
        最近更新 更多