2016-09-16 5 views
0

アルファベットの投稿には、とにかくまたはプラグインがあります。アルファをクリックすると、そのアルファで始まる内容が表示されます。プラグインのほとんどは、長いリストを既に持っているので、私が望んでいない索引付けされる各アイテムを1つずつ追加する必要があります。例:記事のアルファベット順の記事にWordpressの投稿

A | B | C | D | E

BROS

BROTHER

BEGGIN

Like in this picture but this plugin also wants items add one by one

答えて

0

本当に必要はありませんプラグイン:https://wordpress.stackexchange.com/questions/67271/display-all-posts-starting-with-given-letter

ソリューション(あなたのために上記のリンクから取られた例を使用することも):

あなたがこれに上記のコードを変更することができるように
<ul class="posts"> 
    <?php 
    global $wpdb; 
    $request = "a" // could be any letter you want 
    $results = $wpdb->get_results(
      " 
      SELECT * FROM $wpdb->posts 
      WHERE post_title LIKE '$request%' 
      AND post_type = 'post' 
      AND post_status = 'publish'; 
      " 
    ); 
    if ($results) 
    { 
     foreach ($results as $post) 
     { 
      setup_postdata ($post); 
      ?> 
      <li> 
       ... loop stuff here (the_title, the_permalink) ... 
      </li> 
      <?php 
     } 
    } 
    else 
    { 
     ?> 
     <div class="alert">No clubs found for that letter. Please try again, or use the search at the top.</div> 
     <?php 
    } 
    ?> 
</ul> 

あなたは、$ _GET []を使用してURLを取得することができます:

<ul class="posts"> 
<?php 
    global $wpdb; 
    $request = 'a'; 
    if (isset($_GET[ "bl" ])) { 
     $request = sanitize_text_field($_GET[ "bl" ]); 
    } 
    $results = $wpdb->get_results(
      " 
      SELECT * FROM $wpdb->posts 
      WHERE post_title LIKE '$request%' 
      AND post_type = 'post' 
      AND post_status = 'publish'; 
      " 
    ); 
    if ($results) 
    { 
     foreach ($results as $post) 
     { 
      setup_postdata ($post); 
      ?> 
      <li> 
       //... loop stuff here (the_title, the_permalink) ... 
      </li> 
      <?php 
     } 
    } 
    else 
    { 
     ?> 
     <div class="alert">No content found for that letter.</div> 
     <?php 
    } 
    ?> 
</ul> 
関連する問題