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 回答