标签: wordpress

  • Clean up Out-dated Custom Field Data in WordPress Post

    If you ever used a magazine-style theme, you must be familiar with the concept "custom field". In essence, it’s a key-value pair storing post data about what additional info to display in a specific page. In most cases, we take advantage of custom field to display an image related to the post.

    Problems We Have

    There are two major problems with this.

    Firstly, the name of the keys differ among various themes, as a result of which, some custom field data turn to be outmoded when you change the theme.

    Secondly, while a post is becoming out-dated as time goes, there’s little chance for that post to be displayed in any page at all. And the custom field data belonging to that post is getting redundant as well.

    Solutions We Get

    For the first question, the answer is in the following steps:

    Step 1: Go to WordPress admin page and edit whichever post contains that custom field key, then write down the name of the key. In the example below, it is "image".

    Step 2: Go to you phpMyAdmin page and choose the WordPress database from the left column, then click the SQL query window icon.

    Step 3: Type in following query string and "GO". That’s it. (Replace "image" with your key name.)

    # remove entries with "image" as key name
    DELETE FROM wp_postmeta WHERE meta_key = ‘image’

    For the second case, I’ll just provide a way of thinking, instead of a solid answer. For instance, I’ve got five posts with custom fields to show in a specific page, then I should keep the custom fields belonging to the latest five post, and delete the rest of them. A small change of the query string above will do just fine.

    # get the latest post_id
    SELECT @idMax := MAX(post_id) FROM wp_postmeta;
    # keep the latest five and remove the rest of them
    DELETE FROM wp_postmeta WHERE (@idMax – post_id > 5) AND meta_key = ‘image’

    NOTICE: Use the statements above at your own risk, because the value of post_id does not always increase normally.

  • Customize Flickr Photo Album Plugin to Fit Your Theme

    What Is Flickr Photo Album(FPA) Plugin?

    Flickr Photo Album for WordPress is a fantastic plugin that allows you to pull in your Flickr photo sets and display them as albums on your WordPress blog.

    There is a pretty simple template provided, but you can customize the templates 100% to match the look and feel of your own site.

    And this post will guide you through the process of the customization. It’s pretty easy thanks to the great structuring of this plugin. See FPA in action here.

    Preliminaries before We Start

    From the “Look and Feel Customization” part of FPA’s wiki, we know that to customize this thing, we have to make sure the photoalbum-index.php template file (which is located inside the “template” folder in the plugin’s directory) closely match your own theme’s page.php.

    Let’s first take a look at what the photoalbum-index.php file is like:

    <?php
    /*
    Template Name: Photo Album

    More comments here are omitted…

    */
    global $TanTanFlickrPlugin;
    if (!is_object($TanTanFlickrPlugin)) wp_die(‘Flickr Photo Album plugin is not installed / activated!’);

    get_header();

    // load the appropriate albums index, album’s photos, or individual photo template.
    // $photoTemplate contains the template being used
    ?>
    <div id=“content” class=“narrowcolumn”>
    <?php
    include($tpl = $TanTanFlickrPlugin->getDisplayTemplate($photoTemplate));

    // uncomment this line to print out the template being used
    // echo ‘Photo Album Template: ‘.$tpl;
    ?>

    <?php if (!is_object($Silas)):?>
    <div class=“flickr-meta-links”>
    Powered by the <a href=“http://tantannoodles.com/toolkit/photo-album/”>Flickr Photo Album</a> plugin for WordPress.
    </div>
    <?php endif; ?>

    </div>
    <?php

    // uncomment this if you need a sidebar
    //get_sidebar();

    get_footer();
    ?>

    It is just like a standard page template of WordPress theme, isn’t it?

    Then we shall look into the page template as indicated. There should be a page template file sample in your theme’s directory, named page.php or something like that. Take my current theme as an example, the codes inside look like:

    <?php get_header(); ?>

    <div id=“whitewrap”>

    <div class=“wrapper”>

    <div id=“location”>
    <p><a href=<?php echo get_option(‘home’); ?>/” title=<?php bloginfo(‘name’); ?>>Home</a> / <?php the_title(); ?></p>
    </div>

    <div id=“secondary”>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div id=“postcontent”>
    <?php the_content(); ?>
    </div>
    <?php endwhile; else: ?>
    <?php endif; ?>
    </div> <!– end secondary –>

    <?php include (TEMPLATEPATH . ‘/sidebar-page.php’); ?>

    </div> <!– end wrapper –>

    </div> <!– end whitewrap –>

    <?php get_footer(); ?>

    Compare these two code snipplets and you’ll realize that the main structure is nearly the same. Hence what we’re going to do next is pretty simple bearing this in mind. Besides, those comments inside photoalbum-index.php almost have told you everything you need to do(not very much, though ^^).

    Step 1: Merging the two

    First thing’s first, copy everything between <?php get_header(); ?> and <?php get_footer(); ?> from page.php to photoalbum-index.php to replace its counterpart.

    Step 2: Main Replacement

    Our purpose is to make the structure of photoalbum-index.php accords with that of page.php. So we ought to wipe out lines between <div id=“secondary”> and its closing </div>, then add following codes there:

    <?php
    include($tpl = $TanTanFlickrPlugin->getDisplayTemplate($photoTemplate));
    ?>

    <?php if (!is_object($Silas)):?>
    <div class=“flickr-meta-links”>
    Powered by the <a href=“http://tantannoodles.com/toolkit/photo-album/”>Flickr Photo Album</a> plugin for WordPress.
    </div>

    Keep the promotion link as a tribute to the author.

    Step 3: Tiny Moderation

    In fact, we’ve already finished the job. But there’s a little more to be done: Make the patching where necessary. In my sample, the navigation title should be fixed as below:

    <div id=“location”>
    <p><a href=<?php echo get_option(‘home’); ?>/” title=<?php bloginfo(‘name’); ?>>Home</a> / <?php e(‘Gallery’); ?></p>
    </div>

    Mission Accomplished!

    Now the photoalbum-index.php should look like this:

    <?php
    /*
    Template Name: Photo Album

    So many comments…

    */
    global $TanTanFlickrPlugin;
    if (!is_object($TanTanFlickrPlugin)) wp_die(‘Flickr Photo Album plugin is not installed / activated!’);

    get_header();

    ?>

    <div id=“whitewrap”>

    <div class=“wrapper”>

    <div id=“location”>
    <p><a href=<?php echo get_option(‘home’); ?>/” title=<?php bloginfo(‘name’); ?>>Home</a> / <?php _e(‘Gallery’); ?></p>
    </div>

    <div id=“secondary”>
    <div id=“postcontent” class=“narrowalbum”>
    <?php
    include($tpl = $TanTanFlickrPlugin->getDisplayTemplate($photoTemplate));
    ?>

    <?php if (!is_object($Silas)):?>
    <div class=“flickr-meta-links”>
    Powered by the <a href=“http://tantannoodles.com/toolkit/photo-album/”>Flickr Photo Album</a> plugin for WordPress.
    </div>
    <?php endif; ?>
    </div>
    </div> <!– end secondary –>

    <?php include (TEMPLATEPATH . ‘/sidebar-page.php’); ?>

    </div> <!– end wrapper –>

    </div> <!– end whitewrap –>

    <?php get_footer(); ?>

    In case you need more customization like hooking FPA up with Lightbox or any other display libraries, you can find out more info about how to customize this plugin here.

  • OpenID Enabled in RiWiA

    The OpenID logo

    Image via Wikipedia

    Just finished integrating OpenID support into this blog. It’s even more convenient to make comments here now. Without registration or leaving username and email information, a simple line of URL is sufficient for you to say anything you want.

    What is OpenID anyway?

    OpenID is a simple registration solution across Internet. Register once with a trusted Provider and you’ll get a unique URL that identifies you. Then you’ll be able to login to a bunch of sites (including RiWiA) using that URL. No more registration, no more username and password. For a complete list of organizations which support OpenID, check this page out (Wow, look what we’ve got, Digg, Microsoft, AOL, Yahoo, LiveJournal, MediaWiki, WordPress, 37Signals, etc). In a word,

    OpenID eliminates the need for multiple usernames across different websites, simplifying your online experience.

    How to add OpenID support for self-hosted WordPress weblog?

    It’s easy. The OpenID plugin will help you out with this. It’s as easy-to-use as other WordPress plugins. Upload the necessary files and activate it. Then go to “Users” –> “Your Profile OpenIDs” in the admin panel and add your OpenID URL to your account. Now you’ll be able to login to your blog with that URL, and your OpenID Provider will take care of the authentication.

    If you’d like to use your own blog URL as your OpenID instead of the one with Provider info in it, just add following lines of code to the <header> of your theme (take myopenid.com as the Provider for example):

    <link rel="openid.server" href="http://www.myopenid.com/server" />
    <link rel="openid.delegate" href="http://yourname.myopenid.com" />
    <meta content=‘http://www.myopenid.com/xrds?username=yourname.myopenid.com’ http-equiv=‘X-XRDS-Location’ />

    That’s it.

    Why would I use OpenID?

    Er… It’s a good question. I think

    1. It’s fun.
    2. It simplify the process of leaving a comment for those who have an OpenID, so it’s an enjoyable experience for them to comment in your blog.
    3. Everybody else are using it, so why shouldn’t we?
    Enhanced by Zemanta
  • FeatPlug – The Way Your Featured Posts Are Meant to Be Displayed

    It’s been a while since my last post, er…, quite a while. Being busy is not an excuse, I just don’t feel like writing, or am simply getting lazier. Anyway, I see blogging constantly as a way of exercising my patience, so I’ll keep doing it.

    Today’s highlight is cast on FeatPlug, which is

    “a WordPress plugin that can mine your blog’s content and generate ‘featured content’ section for your site using the suitable stories”.

    Anyone ever tried a magazine-style WordPress theme knows what the “featured content” is – a section that makes some of your posts distinguished from the rest and your blog to be more appealing. The only problem with this, is instead of getting everything done automatically, you have to add the custom fields manually. I’ve tried some scripts that will do the job, such as TimThumb, but still, there’re limitations (like, the path to the image must be relative).

    And for now, those problems are in the past, because we have this fantastic plugin FeatPlug (see the RiWiA homepage for a demo). To get the featured content section, just upload and activate the plugin, and put the function call in a proper place among your codes. It then searches the very posts for images and display them in the format you indicate. All you have to do, is to compose the posts as usual, and that’s it, nothing more. The jobs after that are taken care of by this amazing plugin. FeatPlug also brings along 3 completely different templates to show your featured posts: imagemenu, slideshow and banners. And there’s more, you can even create template of your own.

    The features FeatPlug provides include: image caching, template support, layered architecture, image enlarging, broken image checking and WordPress MU support. Check this page for more info about it.

  • Tiny Post URL

    TinyURL

    Image via Wikipedia

    Just found a WordPress Plugin for GO.6.CN written by fairyfish , which generates a shorter URL for every post using service provided by go.6.cn . I started to think that, hey, why not make a similar one using TinyURL? That must be fun. The problem was, I couldn’t find the API on TinyURL’s homepage. Google did help at that time. Surprisingly, TinyURL has a really simple API, which is too simple to describe. Scripting News gave the detail info here .

    Description

    Finally, here it is. A WordPress Plugin named "Tiny Post URL", which adds a TinyURL at the end of the post. Share it, enjoy it, have fun!

    DOWNLOAD

    Installation

    1. Unzip the tiny-post-url.zip file.
    2. Upload the the tiny-post-url.php file to your wp-content/plugins folder. If you’re using FTP, use binary mode.
    3. In your WordPress administration, go to the Plugins page and activate this plugin.
    4. That’s it! No configuration needed.

    Any suggestions or advice, feel free to contact me.

  • Stop Hotlinking with htaccess in WordPress

    I didn’t store any images in my site before, because I don’t want to see any of my bandwidth consumed by others who are hotlinking my files. Even when I started to use magazine-style themes, which require a lot of images, I didn’t upload images here.

    Everything changed when I found a script called timthumb by Darren Hoyt. You can utilize this script to display custom-field image in whatever size you want. The only handcuff of the script is, you’ll have to upload your own image or it won’t work. It is so convenient that I decide to obey the rule.

    Then the hotlinking protection problem comes into my sight. Most of the online articles talk about how to add some rewrite rules into your .htaccess file to stop hotlinking, but they don’t take WordPress into account, neither do they explain the meaning of the rules. Now that WordPress also uses the .htaccess file to achieve the permanent link function, if you don’t put those rules in the proper order, either the protection doesn’t function or the permanent links are not reachable.

    So, if you happen to run into the same problem as I do, let’s figure it out now. Here’s how: simply put these lines below into your .htaccess file and everything is under control. I’ll explain the codes later.

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(.+\.)?ralphdunn\.com/ [NC]
    RewriteRule .*\.(jpe?g|gif|bmp|png)$ – [F]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    EXPLANATIONS

    1. The line “RewriteCond %{HTTP_REFERER} !^$” means allow empty referrals, that is, an image could be shown by opening its link in the address bar.
    2. The line “RewriteCond %{HTTP_REFERER} !^http://(.+\.)?ralphdunn\.com/ [NC]” matches any requests from ralphdunn.com URL. Just replace “ralphdunn” with your own domain name.
    3. The line “RewriteRule .*\.(jpe?g|gif|bmp|png)$ – [F]” matches any files ending with the extension jpeg, jpg, gif, bmp, or png. A 403 Forbidden error code will be displayed instead of an image.
    4. The rest of lines are used to get the permanent link to work.
    5. “NC” in square braces means Not Case-sensitive, while “F” means 403 Forbidden.

    MORE INFO

    • For detail information and alternatives, visit altlab. There is also a strong hotlinking testing tool located at coldlink.
    FOOTNOTES

    Playboy

    Image by delunita via Flickr

    1. Hotlinking protection is implemented through judging the HTTP_REFERER sent by your browser, and if you’re using Firefox, you may simply modify some configuration in about:config or install a certain plugin to hack it. Because it is way out of the current topic, I don’t think further discussion should be made here. Go google it yourself, and you’ll find it’s easy.
    2. The Greek codes are regular expressions. If you plan to get an in-depth understanding of them, here’s a book you may refer to: Mastering Regular Expressions.
    3. For those who have done reading this long post, the photo is your reward. ^^
    Zemanta Pixie
  • 最新发布的WordPress插件(2008年6月5日)

    is_human()

    is_human()是WorPress中最简洁扩展性最强的身份验证系统,有3种验证类型可供用户选择,其脚本也可以在每次页面载入的时候调用。

    WP Comment Remix

    WP Comment Remix允许你回复和引用评论者的链接,同时也在后台提供了一个功能更强的评论编辑页面。

    WP-Help

    WP Help让你可以在WordPress后台创建一个简单的帮助或指引页面,以显示你所选择的特定信息。

    Image Upload HTTP Error Fix

    该插件可以修复WordPress(2.5以上版本)在文件上传中出现的HTTP错误。

    Photo Galleria

    Photo Galleria是一个为影友、设计者打造的简洁优雅的插件,它通过调用jQuery framework生成漂亮的照片展示相册。

    WP Movie Ratings

    WP Movie Ratings使电影评分变得简单,其核心是一个与imdb相连的书签,借助AJAX技术实现一键点击给电影打分的功能。

    Widgetized Admin Dashboard

    Widgetized Admin Dashboard是一个供2.5以上版本WordPress使用的插件,通过它你可以在“设计”-“Widgets”里编辑Wordpress Dashboard的内容。

    原作者:Keith Dsouza

    翻译:Ralph “RAL” Dunn

    原文链接:http://weblogtoolscollection.com/archives/2008/06/04/wordpress-plugin-releases-for-64/

    Technorati Tags: ,
  • Hello, World! Hello, WordPress!

    This is the real "Hello, World!" post of my blog, not that annoying one generated by WordPress automatically. But to tell the truth, I kinda like that post, cos it really helps me out when I tried to set up the whole site and get it run in a proper way.

    Long story short, there’re two major problems that I have to solve.

    (更多…)

  • GaMerZ系列WordPress插件更新

    个人使用WordPress的时间还很短,插件用得也不多,但是不知不觉就用上了GaMerZ的两个插件,wp-postviews和wp-sticky。Lester “GaMerZ” Chan绝对是最敬业和勤奋的插件作者之一。虽然插件作品达15个之多,但随着WordPress 2.5.1的发布,他仍然在很短时间内一一更新了。佩服!

    继两星期前第一波11个更新之后,三天前他又完成了余下4个插件的更新工作。第一波插件更新的详情请看这里,Lester声称并未针对2.5.1以下的WordPress版本进行测试,可能已经放弃了向下兼容的打算。他还表示修正了插件的路径问题,理论上可以使用WordPress新版本带来的插件自动更新特性了。不过既然作者本人只是表示”should work in theory”,那还是等等好了。另外我在插件页并没看到任何自动更新的选项,奇怪。

    第二波的4个插件包括大家常用的WP-DownloadManager、WP-PostViews和WP-DBManager等。除了一些不大的适应性改变外,DownloadManager被赋予了新的搜索特性,详情在这里。另外需要注意的是,这几个插件目前是beta版。

    感谢Lester为我们带来这么多好用的插件,并进行着持续的开发维护工作。比起我们用户手动修改来解决插件的兼容性问题,由作者来完成这些工作显然更令人放心。

    Technorati 标签: ,,,