Wordpress/頁:修訂版本之間的差異

出自福留子孫
跳轉到: 導覽搜尋
讓頁可以執行php
讓頁可以執行php
第 31 行: 第 31 行:
 
#*解壓縮得 exec-php-zh_TW.mo 和 exec-php-zh_TW.po
 
#*解壓縮得 exec-php-zh_TW.mo 和 exec-php-zh_TW.po
 
#*上傳到「/wp-content/plugins/exec-php/languages」目錄中
 
#*上傳到「/wp-content/plugins/exec-php/languages」目錄中
#到WordPress後台,點擊【設定】→【Exec-PHP】,然後按照自己的需求進行設定。
+
#到WordPress後台,點選「設定/Exec-PHP」,然後按照自己的需求進行設定。
 
#編輯時要用 HTML/TEXT 模式,或直接至 post_content 中去改,才能用 <?php…?>置入PHP程式碼。
 
#編輯時要用 HTML/TEXT 模式,或直接至 post_content 中去改,才能用 <?php…?>置入PHP程式碼。
 +
===應用範例一:測邊欄產生隨機文章列表===
 +
*到WordPress後台,點選「外觀/模組」(或翻成「外觀/小工具」)。
 +
*選擇「文字」小工具,再選「MainSidebar」,按「新增小工具」。
 +
*右側產生新框,在「標題」中加「隨機文章」,「內容」中加<pre>&lt;?php
 +
query_posts(array('orderby'=&gt;'rand','showposts'=&gt;5));
 +
if(have_posts()):
 +
while(have_posts()):the_post();?&gt;
 +
&lt;a href="&lt;?php the_permalink() ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&nbsp;&lt;?php comments_number('','(1)','(%)'); ?&gt;&lt;br/&gt;
 +
&lt;?php endwhile;endif; ?&gt;</pre>
 +
核取「自動增加段落」,按「儲存」。
 +
*去「http://urclass.net/wordpress/?p=1」檢查側邊欄的「隨機文章」段落。

2016年8月27日 (六) 12:17的修訂版本

是 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; ?>

核取「自動增加段落」,按「儲存」。