Wordpress/頁

出自福留子孫
跳轉到: 導覽搜尋

是 wp_posts 中的一筆資料,其 comment_status 欄為 closed

  1. 頁抬頭在 post_title 欄,會秀在整頁的最上方。本欄同時是串接新舊版本的 key
  2. 內容在 post_content 欄
  3. 到達方法:
  4. 最新版本其 post_type 為 page ,post_status 為 publish
  5. 舊版其 post_type 為 revision(調整),post_status 為 inherit(繼承)
  6. 最後更新版本的 id 始終不變,產生新的 id 去永舊版。
  7. 直接改 post_content 欄值一樣生效,這樣就不會產生新的舊版資料。
  8. 直接改 post_title 、 post_name 也生效。

附件

實體是圖照,在 wp_posts 中有一筆說明資料,其 comment_status 欄為 open

  1. 實體在 wordpress/wp-content/uploads/年/月/ 中,由 guid 欄指示路徑
  2. post_title 欄和 post_name 都是圖照的檔名(不含副檔名)
  3. 頁中以 a 標籤內包 img 標籤表達。
  4. post_status 欄值為 inherit
  5. post_content 欄空白
  6. post_parent 為插入此圖照之頁 id
  7. post_type 為 attachment,post_mime_type 欄指示圖照格式,如:image/png

讓頁可以執行php

  1. 安裝 Exec-PHP 外掛
    • 到WordPress後台,點擊【外掛】→【新增外掛】,進入後在搜尋欄位輸入「Exec-PHP」並點擊﹝搜尋﹞。
    • 找到名為「Exec-PHP」的外掛,點擊右方的「安裝」,再點擊﹝立刻安裝﹞。
    • 系統就會開始自動安裝外掛,安裝完成後請點擊「啟用外掛」。
  2. 下載 Exec-PHP 中文語系檔
  3. 到WordPress後台,點選「設定/Exec-PHP」,然後按照自己的需求進行設定。
  4. 編輯時要用 HTML/TEXT 模式,或直接至 post_content 中去改,才能用 <?php…?>置入PHP程式碼。

應用範例一:側邊欄產生隨機文章列表

  • 到WordPress後台,點選「外觀/模組」(或翻成「外觀/小工具」)。
  • 選擇「文字」小工具,再選「MainSidebar」,按「新增小工具」。
  • 右側產生新框,在「標題」中加「隨機文章」,「內容」中加
<?php
query_posts(array('orderby'=>'rand','showposts'=>5));
if(have_posts()):
while(have_posts()):the_post();?>
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a> <?php comments_number('','(1)','(%)'); ?><br/>
<?php endwhile;endif; ?>
  • 注意:上文中,角括號必須在 php 段落外,如果在 php 段落中以 echo 生成角括號會被 wordpress 過濾掉。
  • 核取「自動增加段落」,按「儲存」。
  • 去「http://urclass.net/wordpress/?p=1」檢查側邊欄的「隨機文章」段落。
  • 側邊欄設定存在 wp_options 表中,option_name 為「widget_text」,option_value 則存各個段落,每段落一元素。

應用範例二:在「頁」中 include php程式

  • 到WordPress後台,新增一「頁」,其代稱為stat。
  • 在頁的內容加:
    <?php include(TEMPLATEPATH.'/top10page.php'); ?>
  • 安裝外掛:mobilepress 及 Daily Top 10 Posts
  • TEMPLATEPATH所指的路徑有二:
    1. 桌機在:/wordpress/wp-content/themes/目前選用的theme
    2. 手機在:/wordpress/wp-content/plugins/mobilepress/themes/default
  • 在以上兩處都加入 top10page.php ,內容為
<div id='tab1'>
<?php
	if(function_exists('todays_count_widget')){ 
		todays_count_widget('人次','ol');
	} 
?>
</div>