Cun Zhang’s Blog

April 15, 2008

How to display posts sorted by date DESC?

Filed under: wp — Tags: , — Cun Zhang @ 10:30

How to display posts sorted by date descending?

What You do just is to add one php code into index.php of wp-theme.

Go to the wp panel-> presentation->Theme Editor,then click “Main Index Template”(or go to theme directory,find index.php). Before the code

<!--the loop-->
<?php while (have_posts()) : the_post(); ?>

add

<?php $posts=query_posts($query_string . ‘&orderby=date&order=desc’); ?>

Here is my theme’s index.php’s code:

<?php get_header(); ?>
<div id="content">
<!--index.php-->
<!--the loop-->
<?php if (have_posts()) : ?>
<!–sort by date desc–>
<?php $posts=query_posts($query_string . ‘&orderby=date&order=desc’); ?>

<!–the loop–>
<?php while (have_posts()) : the_post(); ?>

Thank for fitztrev at #wordpress channel of irc.freenode.net

Reference:

1. query_posts help doc

2.custom order of posts on main page

Change Language in Wordpress

Filed under: wp — Tags: , — Cun Zhang @ 10:24

There is an easy way to change wp admin panel’s language with plugin Language Switcher.

Language Switcher,allow you to switch language of WordPress easily in your WordPress admin panel.

When installing this plugin, changing languanges will become more easier.

You needn’t modify wp-config.php, and you can set your panel to use any language whose mo file are under the directory “wp-content/languages“.

You can download it at http://yskin.net/projects/language-switcher/

wordpress redirection error

Filed under: wp — Tags: , , — Cun Zhang @ 10:21

Today I mistake this wordpress as my local wordpress.I change WordPress address (URL) to “http://localhost/wordpress”,and Blog address (URL) to “http://localhost“.

When I visit this blog, it redirect to http://localhost. AWFULLY!!

How should I solve this problem?

There are two way to solve it :

1.visit wp-admin/options-general.php, then you can get to the wp panel, change it back.

e.g., if you install wordpress at http://localhost/wordpress, then you should visit :

http://localhost/wordpress/wp-admin/options-general.php

2. modify database

find ’siteurl’ and ‘home’ in “wp_options” table of your wp database,then change it back.

Thank for srikat!

it is also simple:
a. contact to mysql database
$mysql -p -u user
then enter your password.If it’s right,then welcome information will display.
b.modify
mysql>use wp
mysql>show tables;
mysql>describe wp_options;
mysql>select * from wp_options where option_name=’home’ or option_name=’siteurl’;
mysql>update wp_options set option_value=’http://apzc2529.raydi.com’ where option_name=’home’;
mysql>update wp_options set option_value=’http://apzc2529.raydi.com/wordpress’ where option_name=’siteurl’;
mysql>exit

Then you can visit my wordpress again

January 11, 2008

wp-slimstat make WordPress database error

Filed under: wp — Tags: , , — Cun Zhang @ 14:44

wp-slimstat is a simple web stats analyser for wordpress.

in the version 0.9.2,it display wordpress database error:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ” at line 3]
SELECT `tp`.`post_title` FROM `wp_posts` AS `tp` WHERE (1 = 1) AND `tp`.`ID` =

I google this problem and find then answer at http://silverfox.name/archive/category/computer/network in Chinese.

I changed wp-slimstat.php as that article said,then it works fine.

at the line 1716 of wp-slimstat.php,the original code as follow:

" AND `tp`.`ID` = " . $myFieldsList [ $aFieldIndex ];

modification:

" AND `tp`.`ID` = " . $myFieldsList [ $aFieldIndex-1 ];

The reason leading this error is:

This plugin will read WordPress’s Option “permalink_structure”,for example,my is “/archive/%post_id%”,so the Regular Expressions  is

$myPermalinkRegEx = "/archive/([0-9]+)"

matching the content of $resource,creating $myFieldsList. For exampl,"/archive/147”,

$myFieldsList = array("0"="/archive/147", "1"="147")

corresponding is :

$myPermalinkArray = array("0"="", "1"="archive", "2"="%post_id%")

so it needs $aFieldIndex -1 to choose the value of  myFieldsList 147. 

Slimstat set local time

Filed under: wp — Tags: , , — Cun Zhang @ 8:45

I install Slimstat(simple web stats analyser ) plugin for my wp.But I find it display this server time,not my local time.
I google and find the answer from http://www.deepjiveinterests.com/2006/08/07/how-to-get-wp-slimstat-to-recognize-your-local-timezone/.
I put a line of code (as follow) into wp-slimstat.php,then it works fine. Thanks for Deep Jive’s share.
I use Beijing time,so I need change timezone to “Asia/Shanghai’.Then the code is:
date_default_timezone_set (”Asia/Shanghai”);

So why can he find the answer?
I think he must find than Slimstat is writed by php,so we can find the answer from php.THIS IS THE KEY.This also can be used to solve any problem!

Thank for Deep Jive. ^_^

here is the original post link:
http://www.deepjiveinterests.com/2006/07/30/about/

Powered by WordPress