用WordPress打造类Pinterest图片网站

前几天,想搭建一个类似于花瓣的网站……动机(这个……可以先不说么)。那就先义务给神器打个广告Sublime Text2的正式版终于发布了……至于为神马它是个神器,不便多解释……谁用谁知道……有个介绍的帖子在这儿

回归正题,要搭建一个类似于pinterest或者是国内山寨版的——花瓣网的图片分享类的网站的话,首先需要个稳定的后台作为支撑,考虑到对各编程语言的熟悉程度和修改难易程度,选用了PHP的Wordpress。其实还可以选php语言的drupal或者是python语言的Django 框架搭……但是嫌麻烦就算了。

第二,需要个类似的wordpress主题,这里我就借鉴了一下花瓣网的css,然后大体上改了下,就差不多的样子了。至于怎么改主体,这里有篇文章专门讲解wordpress的循环的逻辑框架的。传送门在此……

第三,需要实现几个细节上面的问题。

I.我搭建的这个小站是专门给某人使用的,所以整站加密是不可少的,于是呼,写了个“巨难看”的加密登录界面……有待改进……效果图如下:

实现代码:

编辑主体的目录下的header.php在第一行之前添加以下代码code.php

<?php
session_start();if( isset(_SESSION['authenticated']) ) { if(_SESSION['authenticated'] == 'yes')
{
authenticated = 'yes'; } else {authenticated = 'no';
}
}
else
{
authenticated = 'no'; }if(authenticated != 'yes')
{
// 将localhost 改成你的网站首页地址
header("Location: http://localhost/login.php");
exit();
}
?>

然后新建一个login.php到你的网站的根目录下面内容如login.php

II.介于MM们如果是用wordpress的话会晕头转向的,所以推荐使用wordpress的手机客户端,那么就跟其他的客户端一样了,可以随手拍,随时上传就可以,上传后照片的命名是个大问题,因此上传后,按照当前的时间戳重命名照片。还有个问题,wordpress上传图片是按照文章的形式发布的,我想大多数MM应该是懒得填写标题的,我又不希望看到满篇的Untitled文档,动手改一下wordpress的命名规则:若MM手动输入了文章的标题,则就按照她输入的标题,假若没有输入标题,则将当前的时间戳当作是标题,也方便日后整理照片了。

实现上传后文件重命名功能,对wordpress修改如下:

打开“wp-admin/includes/file.php”文件,找到第327行这段代码:

// Move the file to the uploads dir
new_file =uploads['path'] . "/filename"; if ( false === @ move_uploaded_file(file['tmp_name'], new_file ) ) returnupload_error_handler( file, sprintf( __('The uploaded file could not be moved to %s.' ),uploads['path'] ) );

修改为

// Move the file to the uploads dir
new_file =uploads['path'] . "/".date("YmdHis").floor(microtime()*1000).".".ext; if ( false === @ move_uploaded_file(file['tmp_name'], new_file ) ) returnupload_error_handler( file, sprintf( __('The uploaded file could not be moved to %s.' ),uploads['path'] ) );

同理,实现文章自动命名的功能,将下面的代码添加到博客主题的function.php中:

function creat_status_title( post_ID ){ if(_POST['post_title'] != '') return;//判断是否有标题,如果有则不用生成
_POST['post_title'] = date("YmdHis").floor(microtime()*1000);my_post = array();
my_post['ID'] =post_ID;
my_post['post_title'] =_POST['post_title'];
wp_update_post( $my_post );//更新文章标题
}
add_action('publish_post', 'creat_status_title', 0);//挂上钩子,即在文章发布、更新的时候执行creat_status_title()函数

然后,就算大功告成了……当然好不好看就看前台的Js和Css水平了

最后来张效果图:

(马赛克还是必须要打滴,要不就被人肉了)

当然,如果你想做的好看点的话,可以自己写点js,让你的网站支持动态重排,即,不论浏览器的窗口有多宽,多窄都能完美地显示你的图片。^^

4 Comments

isnowfy says:

我去,那是马赛克吗。。。

* 笑得海潮 says:

必须滴马赛克啊……就是有点大,哈哈哈

link says:

link

用WordPress打造类Pinterest图片网站 | Definite

Webseite besuchen

用WordPress打造类Pinterest图片网站 | Definite

Leave a Reply to link Cancel Reply

Your email address will not be published.

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax