Chinaunix首页 | 论坛 | 博客
  • 博客访问: 592557
  • 博文数量: 207
  • 博客积分: 10128
  • 博客等级: 上将
  • 技术积分: 2440
  • 用 户 组: 普通用户
  • 注册时间: 2004-10-10 21:40
文章分类

全部博文(207)

文章存档

2009年(200)

2008年(7)

我的朋友

分类: 系统运维

2009-04-29 13:48:56

  • This is the Loop

    1) is perhaps the most important thing one needs to understand when customizing WordPress theme. Any HTML or PHP code placed between where The Loop starts and where The Loop ends will be used for each post. When WordPress documentation states “This tag must be within The Loop”, such as for specific Template Tag or plugins, this is The Loop.

    
    
    // the code inside the loop
    
    
    
    • Further Readings On The Loop


      1)- Sometimes Clients request things like Google ads being displayed after post #2, the top post having a differently colored background, only displaying the title for a few posts. You can’t do any of this inside a single Loop, so here’s how to use multiple loops to display lists of posts differently.How to use multiple loops to display lists of posts differently.

      2)Embed Google Ad in First WordPress Post- One of the more effective places to implement Google Adsense is after the first post, so you want to prevent your ad code from appearing after every single post, as WordPress would just loop and keep showing it. All you need to do is add this code inside the loop.

      
      // Insert your Google AdSense code here
      

      You can also publish the advertisement after the second post or the third etc. Just change:

      “count == 1? to “count == 2?

  • Category Related Techniques

    The first step in modifying what happens when someone visits a is to figure out which of your theme’s files is going to be used to display the posts. This is known as the .

    tells us most of what we need to know about organization of WordPress themes.

    Change the number of posts displayed in Category Page.

    You will need to open index.php file and find the line below,

    then add this line right below it:

    Where number "4" is the number of posts you want to be displayed on every category page.

    Have a different template for specific Category

    So, if you want to make the Category whose ID number is 7 look different from what it is currently (and different from other Category pages), just create a category-7.php template file (or whatever your category ID is) in your current theme folder and customize it as you please. WordPress automatically checks for this, and will use the file if it exists. Please notice how we added the "-" and after it the id number of the category.

    Displaying single post pages differently in specific category

    For example, if you have a category called “News” and a category called “Tutorials” and you want the Stylesheet of the "News" category to be style1.css, and the stylesheet of the “Tutorials” category to be style2.css. provides a simple solution by following the directions below:

    Open single.php file and delete all the content and add the following code

    post;
    if ( in_category('9') ) {
    include(TEMPLATEPATH . '/single2.php');
    } else {
    include(TEMPLATEPATH . '/single1.php');
    }
    ?>

    In the most simple terms, the PHP code issues a query that says: Check the post. If the post is in category ID number 9, display single2.php. If not in category ID number 9, display single1.php.

  • Conditional Tags

    can be used in your Template files to change what content is displayed and how that content is displayed on a particular page depending on what conditions that page matches.

    Styling different categories: If you want to use certain stylesheet for specific category, all you have to do is add the code below to the tag in your index.php file.

    /cat-15.css"
    type="text/css" media="screen" />;
    
    
    

    Dynamic file content If you want to include a file that will only appear on the home page, Place this code in the index.php:

    Better SEO Titles for your pages

  • Creating Navigation Menu

    Menus are an excellent way to create a menu of categories or Pages, highlighting specific areas of interest within your website.

    is a way to give users a reference point with which to navigate. It is like the dot on the map that says “you are here”.

    created a dynamic highlight menu on Best Web Gallery by using the code below:


    • Further Reading on Navigation Menu


      1)- Here is a common navigational scheme, with parent pages on top and child pages (if they exist) on bottom.

      2) Smarter Navigation Menu Mike Cherim has explained how to get a smarter navigation menu using Conditional tags by offering post titles, archive dates, and category names instead of generic terminology.

      
       
  • Query Posts

    can be used to control which posts show up in The Loop. All you have to do is place a call to query_posts() in one of your Template files before The Loop begins.

    Show posts from only one category If you want to display a certain number of posts in specific category

    Here we want to display the latest “10″ post in category whose ID is “15″.

    Exclude Categories From Your Home Page

    Retrieve a Particular Post

    
    
    • Further Readings On Query Posts

      1) - A helpful tutorial to list some of the arguments that you can pass to the query_posts() function.

      
      
  • Get Posts

    is a simple tag for creating multiple loops to allow you list links of posts in different ways. For example if you want to display the last 5 entries, you use this code:

    
    
    
    

    In the above code the variable “numberposts=5? tells WordPress how many posts to retrieve and populate the loop with. WordPress post formatting function, setup_postdata() automatically populates the required variables.

  • Post excerpts

    There are two WordPress template tags, and used within the WordPress Loop to display the content of the post.

    Post excerpt allows you to display only the first part of your blog’s post, a block of content instead of displaying the full post. While many don’t know the real reason behind and just use it to make things more aesthetic, displaying excerpt has got many advantages both in the SEO and traffic area.

    is used to force only excerpts to be seen on the multi-post pages. Also, HTML tags and graphics are stripped from the excerpt’s content.

    So here is how it works when using in the post:

    • 1) If the post uses both the_excerpt() tag and the explicit excerpt that is written in the textarea box on the write post panel,
      Display the explicit excerpt
    • 2) If the post uses the_excerpt() tag only,
      Display 120 words of the post

    And here is how it works when using in the post

    • 1) If the post uses the tag to mark the ending post of the excerpt,
      Display this excerpt
    • 2) If the tag is not used,
      Display the entire post
    • Further Readings on Post Excerpts

      1) - A good way to ensure your posts don’t show up in suplemental results since Google can find them in various places - ensures that the excerpt is shown on all pages except the full post page.

      2) Use the More Tag on Wordpress- Many readers prefer to have full posts on the homepage so that they can read the content right there, without needing to click around. A simple solution to accommodate both sides is to use the “more” tag on Wordpress.

      3)Custom Excerpts for WordPress

      4)Things you should know when using post excerpt- Things you should be knowing and setting up when using post excerpt is described in this article: why use post excerpt?, Different ways of displaying post excerpt, Displaying excerpt on the frontpage, archives and search results page and Displaying full post in feeds.

  • Custom Fields

    WordPress has the ability to allow you assign custom fields to a post by adding extra information to the post which give your blog a lot of flexibility. Custom fields have a name and a value. The Key is the name of the custom field and the Value is the value you want to give to that name. You can display this information in posts, pages, sidebars, or anywhere on your site. WordPress remembers previously used custom field names and can be selected in the drop down list.

  • Getting Custom Field Values

     get_post_meta($post_id, $key, $single);
    ID, 'key name',true) ?>
    

    Where $post->ID to get a post’s ID, $key is a string containing the name of the meta value you want and $single can either be true or false. If set to true then the function will return a single result, as a string. If false, or not set, then the function returns an array of the custom fields.

  • Adding Custom Field in a post

    To illustrate, we’ll start with a very basic example— Lets assume you want to display the author name right below the title of the post and add a direct link to the author’s website. For starters, you’ll need to open a new post and add 2 custom fields with their respective values, see the image below.



    Now you can display these information inside your template file as below:

    
    ID, 'author_name', true); ?>
    
    
    ID, 'author_url', true); ?>
    
    
    

    • Further Readings On Custom Fields


      1)Using WordPress Custom Fields: Introduction- An ongoing tutorial series for practical uses of WordPress custom fields

    • 2)- Adding a photo or image behind a posts title can help to lure a reader into viewing the main excerpt / permalink of your post.

  • Writing Code in Your Posts

    Sometime you might need to add pieces of code like HTML, CSS, PHP, or javascripts in your post and make this code “looks” like code, but “doesn’t behave” like code. WordPress.com changes codes such as <, >, &, “, and ‘ into characters. For example, if you type:

    It will erased from your post when you save it. Or it will try to turn the codes into character entity codes, which can really mess some things up. So

    To make this WordPress template tag code appear, the code must be converted into character entities:

  • <? php query_posts('p=5'); ?>

  • so that it looks like a box of code which may be copied and pasted within other code or template file, you can use the

     HTML tag with  tag.

    • Further Readings On Writing Code in your Posts

      1)Signatures and Writing Code- Lorelle writes an amazing article on posting code in your WordPress.com blogs, listing the most common character codes (character entities) used in HTML/XHTML, PHP, and other programming languages. Also you need to check her other post sharing some of the WordPress Plugins that help you write code and equations in your blogs.

    • 2)Online Code Converters- There are several online converters that transform the text you type into the standard HTML code that every browser can recognize without altering the character encoding to help you change code into something that WordPress blog can display properly.

      • - An ajax online code converter created by
  • Organized and Structured Archives page

    There are many techniques to customize your Archive Index page. Some involve incorporation of plugins or PHP code to create customized lists of archived posts, and others provide more interesting ways of displaying your archives. You can display Archives By Year, month, categories, day, Weighted Categories, etc…

    below illustrats how to create an archives page listed by categories and months.

    
    

    Where displays a list of WordPress categories as links and displays a date-based archives list.

    If you want to retrieve every single page (perhaps for a custom archive page or a full article listing), you can set this to -1.

    
    

    • Further Readings On WordPress Archives page


      1)- Here’s how to create an archives page for archive links listing by categories and months.

      2)

      3)- How to Create Archives with Real Sex Appeal

  • Permalinks

    Setting your desired structure is the first thing you should do after installing your WordPress blog because search engines index your blog based on post URLs and if you change from one to another then you will loose your rankings. You can change the Permalinks setting through Admin > Options > Permalinks.

    WordPress has to option to use , turning the numbered links into sentences.

    So instead of the default ugly permalink

    Use the Pretty Link structure

    
    or
    

    • Further Readings On Permalinks Structure

      1) Configuring WP Permalinks- Weblog Tools Collection has a useful guide on setting up permalinks on your WordPress blog and how to set up a .htaccess file if you don’t have one.

      2) Understanding WordPress Permalinks- Which Permalink Structure Is the Best?

  • Identifying author(s) & guest comments and styling them

    Through intelligent use of CSS, you can exercise absolute control over author and guest comment layout, presenting the reader with comments so rich with style.

    1)How to highlight author comments in WordPress- By default, most themes have comments look the same. Matt Cutts show us a simple: instead of checking the author’s email address, check their user id to see if it’s the user id of the blog owner.


    2)- Here you will be able to identify author(s) & guest comments under WordPress without the need for extraneous plugins, giving you some extra flexibility by adding code to check if the commenter’s email is the same as the email address of the blog’s author.


    3)- Here are three examples to design the guest comments which complements the rest of the site using: Gravatars, Speech Bubble and Alternating Arrows.


  • Separating Trackbacks from Comments

    Trackbacks are the messages displayed in the comments list whenever another blog links back to one of your posts. It is best if they are not mixed with the comments.


    1) Separating Trackbacks from Comments- The method described here will lift out all of the trackbacks, and then display them as a numbered list after the list of comments is finished.

    2) Managing Trackbacks and Pingbacks- This topic covers separating trackbacks/pingbacks from regular comments, and also how to remove trackbacks and pingbacks from a WordPress theme completely.

  • Custom 404 Page

    Reconsider the value of your by thinking of it as your home page. Think of it as a gateway to your site, you will find good ideas here:

    1)Customizing Your 404 Page- You can often retain the traffic that comes to your 404 page by either offering something funny to grab the readers attention or by offering a variety of methods for them to find the post they are looking for.

    2)Customize Your 404 Page- Here are some tips for improving your 404 page on your personal (or even professional) website.

  • Gravatars

    After you sign up for service, every time you leave a comment at a blog with your valid email address, your image will appear next to your name, providing the owner has added a few simple lines of code.

    How to Setup Gravatars for your Blog - Plug-in Free!- This is a guide custom tailored for WordPress users to setup gravatars on their blog without using a plug-in

  • Worth Checking Techniques

    1) When Your WordPress Theme Keeps Reverting To Default- Have you ever been working on your WordPress blog’s design, when you refresh the page only to find that it’s decided to revert to the default theme?



    2) - Want to get your users log in through the front page, Small Potato’s tutorial will show you how.

    3) When Your WordPress Theme Keeps Reverting To Default- Have you ever been working on your WordPress blog’s design, when you refresh the page only to find that it’s decided to revert to the default theme?



    4)- Displays recent comments in the sidebar without the need for a plug-in:


    5) Creating your home.php quite easily on WordPress- Two easy ways to use if you just want a static front page on your blog.


    6) - A simple solution for all your contact form needs. All comments left with this form are displayed in your WordPress administration panel.


    7)WP Date Image Hack- Using dynamic images to replace the date entries of your blog post.


    8 ) - These 2 hacks will increase the usability of WordPress category pages by giving an index of posts instead of a paged overview, and by sorting posts by title instead of post date.


    9)- When we need to have certain articles ’stay at the top’ longer than others.


    10)Show Category Images- How to add some simple PHP code to your WordPress template and make linked images appear instead of text for your categories in posts.


    11) Displaying WordPress Entries on static pages- A simple solution to include the date, headline, and excerpt of the latest entry from your Blog into your website static pages.


    12) - How to make your commenting system submit comment without reloading the whole page.

    13) - This hack is for those who want to open links in a new browser window and don’t want to type out target=”_blank” every single time.


  • Developing a WordPress Theme

    1)- A step by step guide to create a WordPress theme from scratch.


    2) Developing a WordPress Theme- Dezinerfolio wrote a tutorial on how to develop a WordPress theme, you will learn to convert your xHTML CSS site into a Compact WordPress Theme.


    3)How to create WordPress theme?- DevBox Wireframe WordPress theme, which is available for download on their site. This is basically a barebones theme that you can use to easily take a XHTML/CSS layout and convert it into a WordPress theme.

    4)- Technical instructions on updating a theme for use with widgets.


We are going to publish the .pdf-version of this series, so subscribe to our to keep track on our next posts.

阅读(3840) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~