0

WPテーマで動的ページを作成して、「AZ」からの文字を渡すと、その文字で始まるタイトルのすべての投稿が表示されるようにします。進め方を教えてください。

4

1 に答える 1

1

テーマを使用していて、クエリパラメータを介してインデックスキーを取得している場合は、新しいカスタムテーマファイルを作成し、次のコードを追加して投稿のリストを取得できます。

$thePostIdArray = null;
    $indexkey = $_GET['indexkey']; 
    if ($indexkey!=null){
        $querystr = "
            SELECT wposts.ID 
            FROM $wpdb->posts wposts
            WHERE UPPER(wposts.post_title) like '".$indexkey."%' 
            AND wposts.post_status = 'publish' 
            AND wposts.post_type = 'post' 
            ORDER BY wposts.post_title ASC
         ";
        $thePostArray = $wpdb->get_results($querystr); 
        $i = 0;
        foreach ($thePostArray as $currentPost){
            $thePostIdArray[$i] = $currentPost->ID;
            $i++;
        }

その後、post配列を調べて表示するだけです。

于 2013-01-25T14:59:55.623 に答える