簡體   English   中英

WordPress外觀-無法正常工作

[英]WordPress look - Can't get else to work


已經嘗試了一段時間解決了這個問題,但我不知道問題出在哪里。


這是我的代碼

<?php
//get all post IDs for posts start with letter A, in title order,
//display posts
global $wpdb;
$char_k = 'A';


$postids = $wpdb->get_col($wpdb->prepare("
SELECT      ID
FROM        $wpdb->posts
WHERE       SUBSTR($wpdb->posts.post_title,1,1) = %s
ORDER BY    $wpdb->posts.post_title",$char_a)); 

if ($postids) {
$args=array(
'post__in' => $postids,
'post_type' => 'encyklopedi',
'post_status' => 'publish',
'posts_per_page' => -1,
// 'caller_get_posts'=> 1
);

$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
// echo 'List of Posts Titles beginning with the letter '. $char_a;
while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>



<?php endwhile; }
wp_reset_query(); } ?>



這就是我試圖在代碼末尾更改的內容

    <?php } endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>



我也嘗試更改為

<?php endwhile; } else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>

我不斷收到此錯誤消息

解析錯誤:語法錯誤,意外的“ else”(T_ELSE)

我該如何解決?

if { } else { }阻塞,並且if: else: endif;if: else: endif;不能混合if: else: endif; PHP中的塊。 由於if使用大括號,因此else必須也使用大括號。 嘗試這個:

<?php endwhile; } else { ?>
    <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php }
wp_reset_query(); } ?>

因為您正在將兩種不同的語法相互混合。

使用:

<?php if (condition): ?>
    <?php else: ?>
<?php endif ?>

要么

if (condition) {
    # code...
} else {
    # code...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM