dongpo0409
2014-05-03 21:04
浏览 97
已采纳

在Wordpress中添加自定义PHP页面/帖子以显示基于URL的数据

I am creating a simple db for School Students and want to achieve it in wordpress using any method that is available now.

Every student details like first name, class etc will be saved in database along with ID as primary key.

In PHP, there used to be ONE file like details.php etc and based on QUery passed using GET or POST method, it will display the details. Can we do the same in Wordpress using a SINGLE Page or Post;

Instead of creating seperate Page / Post for every student, i had created PHP Queries in Page / Post using WP Plugin which will display the details of student based on querying ID.

But i am not sure how to make it generalized so that on entering http://mywpsite.com/studentpageorpost/?id=10 i should get the details of student with ID 10; and on entering http://mywpsite.com/studentpageorpost/?id=11, i should get the details of ID 11;

Can anyone please help on this.

图片转代码服务由CSDN问答提供 功能建议

我正在为学生创建一个简单的数据库,并希望使用现在可用的任何方法在wordpress中实现它。

每个学生的详细信息,如名字,班级等都将保存在数据库中,同时ID也作为主键保存。

在PHP中,曾经有过 一个文件,如details.php等,并基于使用GET或POST方法传递的QUery,它将显示详细信息。 我们可以使用SINGLE页面或帖子在Wordpress中执行相同操作;

我没有为每个学生创建单独的页面/帖子,而是使用WP插件在页面/帖子中创建了PHP查询 根据查询ID显示学生的详细信息。

但我不知道如何进行推广以便进入 http://mywpsite.com/studentpageorpost/?id=10 我应该获得ID为10的学生的详细信息; 并且在输入 http://mywpsite.com/studentpageorpost/?id=11 时,我应该 获取ID 11的详细信息;

任何人都可以提供帮助。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douci1615 2014-05-03 21:29
    已采纳

    If I understand well the code would work like this:
    1 Take the id number from url and stored
    1.1 htmlspecialchars() is for converting html tags so you can't be hacked by php injection

    $id = htmlspecialchars( $_GET["id"] );
    

    2 Here we have stored the user info in a object with the wordpress function get_userdata();
    2.1 If ID not found return false.

    $user_data = get_userdata( $id ); 
    

    Accessing Usermeta Data

    $user_data = get_userdata( $id );
          echo $user_data->last_name .  ", " . $user_info->first_name . "
    ";
    

    Results in:

    Doe, John

    If you want to know how to access more user info use print_r($user_data); and will output all the info that the user has.

    Here are some of the useful values in the wp_users and wp_usermeta tables you can access with this function for use in your theme or plugin:

    • users
      • ID
      • user_login
      • user_pass
      • user_nicename
      • user_email
      • user_url
      • user_registered
      • display_name

    • user_meta
      • user_firstname
      • user_lastname
      • nickname
      • description
      • wp_capabilities (array)
      • admin_color (Theme of your admin page. Default is fresh.)
      • closedpostboxes_page
      • primary_blog
      • rich_editing
      • source_domain

    Edit: I think the above system is the easiest still as MarkBlythe sed, no need for individual account, you can use custom post type plugin and custom fields. You could add the students very fast in a loop and array with this function wp_create_user( $username, $password, $email );

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题