Wednesday, June 04, 2008

WordPressで独自ページをつくるサンプル

<?php

define('WP_USE_THEMES', false);
require('wp-blog-header.php'); // 共通関数を使うため
get_header();// テンプレートを仕様

$sql = "SELECT category_count FROM " .$wpdb->categories . " WHERE cat_ID=1" ;
echo $wpdb->get_var($sql);
get_footer(); // テンプレートを仕様

?>

-------------------------------
<?php
require('wp-blog-header.php'); // 共通関数を使うため
$option = 'cat=3&showposts=100&year=2008&order=ASC';

?>
<?php query_posts($option); ?>
<?php if(have_posts()):while(have_posts()):the_post(); ?>
<p><?php the_time('Y.m.d'); ?></p>
<p><a href="detail.php?id=<?php the_ID(); ?>"><?php echo $post->post_title ; ?></a>
</p>
<p><?php the_content(); ?></p>

<?php endwhile;endif; ?>

---------

カテゴリ指定の年ごとのリンクの作成

$category_id = 3;
$sort =" ASC";

$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS year, count(ID) as posts
FROM $wpdb->posts, $wpdb->term_relationships
WHERE
$wpdb->posts.ID = $wpdb->term_relationships.object_id
AND $wpdb->posts.post_type = 'post'
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->term_relationships.term_taxonomy_id = '$category_id'
GROUP BY YEAR(post_date) ORDER BY post_date " . $sort);

foreach ($arcresults as $arcresult) {
echo "<li><a href=\"/?year=".$arcresult->year."\">".$arcresult->year."年</a></li>";
}


----
bloggerの投稿するときの文字の確認を入力、読めない

No comments: