gumara

เหนือกว่าเหตุผล ผมไม่มีเหตุผล

Drupal views arguments

Submitted by gumara on Tue, 05/01/2010 - 14:17

โจทย์คือ ต้องการดึงข้อมูลของ node type ที่ต้องการขึ้นมาแสดง โดยมีเงื่อนไขว่า node ที่จะแสดง ให้แสดง node ที่คนนั้นๆ เขียน ในหน้าของ user นั้นๆ คือสั้นๆว่า ให้แสดง node ที่ตัวเองเขียน ในหน้า user account ของตัวเองนั้นเอง

ไอเดียคือ ปรับ thaiopensource ใหม่ แล้วก็ แต่เดิมมันเคยมีข้อมูลของผู้ประกอบการ Open Source อยู่ ซึ่งในหน้านั้นก็จะมี Site Reference ว่าเคยไปทำให้ที่ไหนมาบ้าง ซึ่งมันดูลอยๆ ก็เลยปรับใหม่ โดยเอามาผู้กับเรื่อง Success Story โดยให้ผู้ประกอบการเขียนเป็นเชิงบทความไปเลย แล้วค่อยให้ Drupal ดึงข้อมูลขึ้นมาแสดงให้ โดยอิงว่า ถ้าอยู่ในหน้า gumara ก็ให้แสดง Success Story ที่ gumara เขียน แค่นี้เอง

ฟังดูเหมือนจะง่าย ซึ่งจริงๆก็ง่าย ถ้ารู้ แต่ถ้าไม่รู้ก็ไม่ง่าย (งงเลย)

เอาสั้นๆว่า ผมแค่จะมา note ขั้นตอนไว้ ว่าต้องทำยังไง ครั้งหน้าจะได้ไม่ลืม

วิธีคือ ใช้ Module Views กำหนดค่าตามนี้

  • View arguments -> User: Name
  • Action to -> Provide default argument
  • Default argument -> PHP Code
  • PHP argument code ->

    $args = drupal_get_title();
    return $args;

ตัวอย่างดูได้ที่ http://stylelurf.com/id/panbd

เท่านี้ก็ได้ละคับ ขอบคุณ คุณมานพ แล้วก็ drupal.in.th ครับ

Post new comment

The content of this field is kept private and will not be shown publicly.
Mollom CAPTCHA (play audio CAPTCHA)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated.


Let's chat

Comment

Tags

tweets

Software tracking

del.icio.us/~

Another ~

The Ubuntu Counter Project - user number # 5754
Add to Technorati Favorites