Wordpress常用コード解釈
11874 ワード
1.最新記事
2.TABページチェックメニューを呼び出す:
3.すべてのページのアーカイブ
Wordpress wp_get_archvies
. :
<?php get_archives('postbypost', 10); ?> ( 10 )
<?php wp_get_archives('type=postbypost&limit=20&format=custom'); ?>
20 , format=custom
。
- wp_get_archvies。(fromat=custom , UL
。)
: WP query_posts() ,
, Loop , 。
。
2.
<?php
$rand_posts = get_posts('numberposts=10&orderby=rand');
foreach( $rand_posts as $post ) :
?>
<!-- Loop-->
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
: query_posts 。
3.
Wordpress ,
。 。 LIMIT 10
。 。
<?php
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID,
comment_post_ID, comment_author, comment_date_gmt, comment_approved,
comment_type,comment_author_url,
SUBSTRING(comment_content,1,30) AS com_excerpt
FROM $wpdb->comments
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
$wpdb->posts.ID)
WHERE comment_approved = '1' AND comment_type = '' AND
post_password = ''
ORDER BY comment_date_gmt DESC
LIMIT 10";
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
foreach ($comments as $comment) {
$output .= "
<li>".strip_tags($comment->comment_author)
.":" . " <a href=\"" . get_permalink($comment->ID) .
"#comment-" . $comment->comment_ID . "\" title=\"on " .
$comment->post_title . "\">" . strip_tags($comment->com_excerpt)
."</a></li>";
}
$output .= $post_HTML;
echo $output;?>
2.TABページチェックメニューを呼び出す:
head : js
<?php if ( is_home() ){ ?>
<script type="text/javascript" src="<?php
bloginfo('template_url'); ?>/tab/easytabs.js"></script>
<?php } else { ?>
<script type="text/javascript" src="<?php
bloginfo('template_url'); ?>/tab/easytabs1.js"></script>
<?php } ?>
css
l <!--tab css-->
l #tab{
l text-align:left;
l position:relative;
l }
l .menu {
l background-color:#ececec;
l color:#272727;
l border-bottom:1px solid #d7d7d7;
l height:23px;
l width:450px;
l vertical-align:middle;
l }
l .menu ul {
l margin:0px;
l padding:0px;
l list-style:none;
l text-align:left;
l }
l .menu li {display:inline;
l line-height:23px;}
l
l .menu li a {color:#000000;
l text-decoration:none;
l padding:4px 5px 6px 5px;
border-left:1px solid #ececec;
l border-right:1px solid #ececec;
l }
l .menu li a.tabactive {border-left:1px solid #d7d7d7;
l border-right:1px solid #d7d7d7;
l background-color:#CCCCCC;
l font-weight:bold;
l position:relative;}
l
l #tabcontent1,#tabcontent2,#tabcontent3,#tabcontent4 {
l border:1px solid #ececec;
l width:450px;
l text-align:left;
l padding:6px 0px;
l font-size:12px;
l margin:2px 0 5px 5px;
l }
l
l
l #container1 #newcomment,#container #newcomment{
l
l position: relative;
l margin-left:30px;
l width:350px;
l }
l
l #container1 #reping,#tabcontent1 #reping{
l position: relative;
l margin-left:30px;
l width:350px;
l }
l
l #container1 #rand li, #tabcontent2 #rand li{
l margin-left:30px;
l padding:0;
l }
l
l <!--tab css-->
tab
<div id="tab"><h2> </h2>
<!--Start of the Tabmenu 1 -->
<div class="menu">
<ul>
<li><a href="#" onmouseover="easytabs('1', '1');" onfocus="easytabs('1', '1');"
onclick="return false;" title="" id="tablink1"> </a></li>
<li><a href="#" onmouseover="easytabs('1', '2');" onfocus="easytabs('1', '2');"
onclick="return false;" title="" id="tablink2"> </a></li>
<li><a href="#" onmouseover="easytabs('1', '3');" onfocus="easytabs('1', '3');"
onclick="return false;" title="" id="tablink3"> </a></li>
</ul>
</div>
<!--Start Tabcontent 1 -->
<div id="tabcontent1">
<div id="newcomment">
<?php
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID,
comment_post_ID, comment_author, comment_date_gmt, comment_approved,
comment_type,comment_author_url,SUBSTRING(comment_content,1,30) AS
com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON
($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved =
'1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC
LIMIT 10"; $comments = $wpdb->get_results($sql); $output = $pre_HTML; foreach
($comments as $comment) { $output .=
"
<li>".strip_tags($comment->comment_author).":" . "<a href=\"" .
get_permalink($comment->ID). "#comment-" . $comment->comment_ID . "\"
title=\"on " . $comment->post_title . "\">" .
strip_tags($comment->com_excerpt)."</a></li>"; } $output .= $post_HTML;
echo $output;?> </div>
</div>
<!--Start Tabcontent 2-->
<div id="tabcontent2">
<div id="reping">
<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM
$wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 10");
foreach ($result as $topten) {
$postid = $topten->ID;
$title = $topten->post_title; $commentcount = $topten->comment_count;
if ($commentcount != 0) { ?>
<li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo
$title ?>"><?php echo $title ?></a></li>
<?php } } ?>
</div>
</div>
<!--End Tabcontent 2 -->
<!--Start Tabcontent 3-->
<div id="tabcontent3">
<div id="rand">
<?php
$rand_posts = get_posts('numberposts=10&orderby=rand');
foreach( $rand_posts as $post ) : ?>
<!-- Loop--> <li><a href="<?php
the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</div>
</div><br/><br/>
</div>
js
/*
EASY TABS 1.2 Produced and Copyright by Koller Juergen
www.kollermedia.at | www.austria-media.at
Need Help? http:/www.kollermedia.at/archive/2007/07/10/easy-tabs-12-now-with-autochange
You can use this Script for private and commercial Projects, but just leave the two credit lines, thank
you.*/
//EASY TABS 1.2 - MENU SETTINGS
//Set the id names of your tablink (without a number at the end) tab
var tablink_idname = new Array("tablink")
//Set the id name of your tabcontentarea (without a number at the end) tab id
var tabcontent_idname = new Array("tabcontent")
//Set the number of your tabs// tab
var tabcount = new Array("2")
//Set the Tab wich should load at start (In this Example:Tab 2 visible on load)
var loadtabs = new Array("1")
//Set the Number of the Menu which should autochange (if you dont't want to have a change menu
set it to 0)
var autochangemenu = 0;
//the speed in seconds when the tabs should change
var changespeed = 3;
//should the autochange stop if the user hover over a tab from the autochangemenu? 0=no 1=yes
var stoponhover = 0;
//END MENU SETTINGS
/*Swich EasyTabs Functions - no need to edit something here*/
function easytabs(menunr, active) {if (menunr == autochangemenu){currenttab=active;}if ((menunr
== autochangemenu)&&(stoponhover==1)) {stop_autochange()} else if ((menunr ==
autochangemenu)&&(stoponhover==0)) {counter=0;}menunr = menunr-1;for (i=1; i <=
tabcount[menunr];
i++){document.getElementById(tablink_idname[menunr]+i).className='tab'+i;document.getEleme
ntById(tabcontent_idname[menunr]+i).style.display =
'none';}document.getElementById(tablink_idname[menunr]+active).className='tab'+active+'
tabactive';document.getElementById(tabcontent_idname[menunr]+active).style.display =
'block';}var timer; counter=0; var totaltabs=tabcount[autochangemenu-1];var
currenttab=loadtabs[autochangemenu-1];function
start_autochange(){counter=counter+1;timer=setTimeout("start_autochange()",1000);if (counter ==
changespeed+1) {currenttab++;if (currenttab>totaltabs)
{currenttab=1}easytabs(autochangemenu,currenttab);restart_autochange();}}function
restart_autochange(){clearTimeout(timer);counter=0;start_autochange();}function
stop_autochange(){clearTimeout(timer);counter=0;}
window.onload=function(){
var menucount=loadtabs.length; var a = 0; var b = 1; do {easytabs(b, loadtabs[a]); a++; b++;}while
(b<=menucount);
if (autochangemenu!=0){start_autochange();} }
3.すべてのページのアーカイブ
function BX_archive(){
global $month, $wpdb;
$now = current_time('mysql');
$arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS year,
MONTH(post_date) AS month, count(ID) as posts FROM " . $wpdb->posts . " WHERE post_date <'" .
$now . "' AND post_status='publish' AND post_type='post' AND post_password='' GROUP BY
YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC");
if ($arcresults) {
foreach ($arcresults as $arcresult) {
$url = get_month_link($arcresult->year, $arcresult->month);
$text = sprintf('%s %d', $month[zeroise($arcresult->month,2)], $arcresult->year);
echo get_archives_link($url, $text, '','<h3>','</h3>');
$thismonth = zeroise($arcresult->month,2);
$thisyear = $arcresult->year;
$arcresults2 = $wpdb->get_results("SELECT ID, post_date, post_title, comment_status
FROM " . $wpdb->posts . " WHERE post_date LIKE '$thisyear-$thismonth-%' AND post_status='publish'
AND post_type='post' AND post_password='' ORDER BY post_date DESC");
if ($arcresults2) {
echo "<ul class=\"postspermonth\">
";
foreach ($arcresults2 as $arcresult2) {
if ($arcresult2->post_date != '0000-00-00 00:00:00') {
$url = get_permalink($arcresult2->ID);
$arc_title = $arcresult2->post_title;
if ($arc_title) $text = strip_tags($arc_title);
else $text = $arcresult2->ID;
echo "<li>".get_archives_link($url, $text, '');
$comments = mysql_query("SELECT * FROM " . $wpdb->comments . "
WHERE comment_approved='1' and comment_post_ID=" . $arcresult2->ID);
$comments_count = mysql_num_rows($comments);
if ($arcresult2->comment_status == "open" OR $comments_count > 0)
echo ' ('.$comments_count.')';
echo "</li>
";
}
}
echo "</ul>
";
} } }}