DFdou's Blog Life is short,Be yourself.

605/093

WordPress-CMS Hacks and Tricks

Something learned from WordPress CMS Hacks and Tricks

1. Create a static home page 使用一个静态页面作为首页

By default, a WordPress home page shows chronological blog post entries — with the most recent post at the top. If your goal is to have a WP-created Page with static information, WordPress will allow you to select a different page as your home page so that you can display more traditional content like information about yourself or your business.
How To »
In your admin area, just go to Setting » Reading. Here you can decide if your home page will display your blog posts or a static page, if you choose a static page you can also choose which page to be your home page from the select box.
做法很简单,在后台Reading Setting里选择Front Page为你写的Page就可以了。

2. Customized Navigation bar 自定义导航栏

Adding too many pages to a WordPress blog that has a navigation bar in the header can really make your Wordpress blog a mess. There are options to control what pages are shown in the navigation bar and even a way to add external links.
How To »
The Template Tag, wp_list_pages(), displays a list of WordPress Pages as links. It is often used to customize the Sidebar or Header. You can simply edit the header.php file and exclude any page id you want, you can also include the pages you want. So now the code of the top nav bar will look like this:

<ul id="pagenav">
       <li class="<?php if ( is_home() ) { echo 'current_page_item'; } ?>">
             <a href="<?php bloginfo('url'); ?>" title="< ?php bloginfo('name'); ?>">Home</a>
       </li>
       < ?php wp_list_pages('sort_column=menu_order&depth=1&title_li=&exclude=17,38' ); ?>
</ul>

Creating Two-Tiered Conditional Navigation in Wordpress »
A common navigational scheme, parent pages on top and child pages (if they exist) on bottom:父子级菜单形式上下层分布
How To »
Darren Hoyt goes through a nice solution to help us: 1) query the page, 2) determine if there are child pages, and 3) properly highlight both the .current_page_parent and .current_page_item links.

<ul id="nav">
< ?php wp_list_pages('title_li=&depth=1'); ?>
</ul>
< ?php if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
if ($children) { ?>
<ul id="subnav">
< ?php echo $children; ?>
</ul>
< ?php } else { ?>
< ?php } ?>

And then he show us how to use CSS to make sure the :active and :hover states display correctly whether or not subpages exist — if they do, the primary nav uses current_page_parent, if they don’t, it resorts to simply current_page_item.
Use breadcrumbs
Breadcrumbs are great for so many reasons: usability, SEO, etc. In terms of plugins, there are many options, my favorite is Yoast’s Breadcrumbs, because it’s easy to implement. Another breadcrumbs plugin, gives you a new template tag called breadcrumb_trail() that you can place anywhere in your theme. Once that’s done, it’ll display a hierarchical menu of where the current visitor is on your site. It’s quite useful if you have more than a few pages or posts.

3. How to widgetize your theme 关于widgetize的部分

方便调用内容用的,可以自己写些Widgets到Function里,在需要输出的地方输出内容。
WordPress Widgets are also known as “sidebar accessories” which are WordPress Plugins or add-ons to your WordPress blog sidebar. This could come in handy for your client, WordPress Widgets allow the easy addition of design elements, gadgets, content, images, and more to your WordPress sidebar to personalize the blog without knowing HTML, PHP, or any code.

4. Custom post and page templates 很重要的一点,关于模板的问题

有时候我们可能需要对某个分类,或者某个ID的日志进行不同的排版处理,这个时候就需要用到这点了。
关于WP的模板机制,曾经写过一个文章,有兴趣的可以查看“WordPress -Template System模板系统”
下边是补充内容,假设我们要对分类ID为13的分类全部使用不同的single页面,那么代码应该是这样:

< ?php
$post = $wp_query->post;
if ( in_category('13') ) {
include(TEMPLATEPATH . '/single13.php');
} else {
include(TEMPLATEPATH . '/single1.php');
}
?>

如果你想对某一个分类(假设分类ID为13)使用不同的分类展示页,那么应该建立category-13.php的模板页。

5. Permalink Structure 永久链接结构

Permalinks are the permanent URLs to your individual weblog posts, as well as categories and other lists of weblog postings. We won’t go through the usual techniques to how to beautify your links and get rid of the post id at the end of the url, display date, etc…
关于这个其实比较难讲,有些网站使用的是日期+日志标题的格式(比如techcrunch.com),也有使用分类+日志标题的格式(比如noupe.com),nwhy.org使用的是日志标题的形式,用的WP-slug的插件,自己输入slug或者由Google的翻译引擎翻译。
对于分类部分,使用了Top Level Categories+Permalink Redirect,有兴趣的可以参考“WordPress Plugins-nwhy.org使用的插件列表”

6. Create a sitemap for the whole website 建立网站地图

Google XML Sitemaps- This plugin will create a Google sitemaps compliant XML-Sitemap of your WordPress blog. It supports all of the WordPress generated pages as well as custom ones. Everytime you edit or create a post, your sitemap is updated and all major search engines that support the sitemap protocol, like ASK.com, Google, MSN Search and YAHOO, are notified about the update.
这方面使用Google XML Sitemaps就OK了。
===============================================================
PS:删掉了部分个人觉得没有必要的内容,有兴趣的请查看原文。

Some Related Posts

Comments (3) Trackbacks (1)
  1. Hi, cool post. I have been wondering about this topic,so thanks for writing.

    [Reply]

  2. Great, thanks! ^_^

    [Reply]

    DFdou Reply:

    @mai, :meinv

    [Reply]


Leave a comment

:zhuang :xizao :wuwu :wenhao :wc :touxiang :shuaya :shuajian :shengtian :paopao :no :meinv :maonv :loveu :leilei :kua :jrjr :dahan :chi :chaocai :byebye


CommentLuv Enabled