2017-08-14 10 views
1


これを解決するためにしばらくの間試みてきましたが、私は問題がどこに見えません。WordPressの外観 - 他に働くことができません


これはこれは私がコード

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


の終わりに変更しようとしたものです私のコード

<?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(); } ?> 



です また、私はこのエラーメッセージ

Parse error: syntax error, unexpected 'else' (T_ELSE)

どのように私はこの問題を解決することができますを取得し続けるこの

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

に変更しようとしましたか?

答えて

1

if { } else { }ブロックとif: else: endif;ブロックをPHPで混合することはできません。 ifは中括弧を使用するため、elseには中括弧も使用する必要があります。これを試してください:

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

ありがとうそんなに@rickdenhaan –

1

あなたはお互いに2つの異なる構文を混在させています。

使用のいずれか:

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

または

if (condition) { 
    # code... 
} else { 
    # code... 
} 
関連する問題