วิธีใช้ login ของ wordpress กับ script ที่เราเขียนเอง

Posted on October 15th, 2008

The script below checks if user already logged in, if not, it will redirect to Wordpress Login page then send the user back after they enter the correct username & password.

มีคนถามเรื่องนี้มา ตัวเราก็อยากรู้เองเหมือนกัน เลยไปค้น ๆ ดูแล้วมั่วเอา ได้ สคริปท์แบบนี้

<?php

require_once(’wp-load.php’);
if (!is_user_logged_in())
{
auth_redirect();
}

?>

เป็นการหา cookie ของ wordpress ถ้าไม่เจอจะส่งไปที่หน้า login หลังจากนั้นค่อยส่งกลับมาหน้าเดิม

Check and cut the strings by length in PHP

Posted on February 6th, 2008

function striptext($message, $position)
{
if (strlen($message) > $position) // Check if string length is exceeded
{
$post = substr($message,$position,1);
if ($post !=" ") // If last character is not space
{
while($post !=" ") // Check next character one by one
{
$i=1;
$position=$position+$i;
$post = substr($message,$position,1);
}
}
$post = substr($message,0,$position);
$text = $post . '...'; // Add dots
} else {
$text = $message . '...'; // Or do nothing
}
return($text);
}

Usage: (Allow only 5 characters to display)
striptext(”Blah Blah Blah”, “5″)

Next Page »
© Quando Omni Flunkus Moritati • Powered by Wordpress • Using the Swiss Cool theme.