前幾天,我從容斌的(鏈接已過期)友情鏈接頁面看到,他在每個鏈接前都放了一張圖片。這些圖像是從網(wǎng)站圖標(biāo)以編程方式生成的,并且具有很多特征。后來查了一下,發(fā)現(xiàn)也有可以實現(xiàn)類似功能的程序。有人說程序不穩(wěn)定,不完整,但我注意到我在使用這樣的功能,覺得還不錯,所以決定使用它。
看來容斌為了讓網(wǎng)站看起來更整潔,把他的鏈接頁面去掉了,所以不能讓大家看到效果。我只記得他當(dāng)時提到過這樣的事情,但我忘記了他從哪里得到的。因為我用的是另一種方法,所以我就不多介紹了。有興趣的可以看這里(鏈接已過期)。它似乎是 的發(fā)源地。
這里是使用提供的 -to-image 功能創(chuàng)建鏈接頁面的完整過程和方法。
內(nèi)容目錄:
一、理念介紹
先說一下我的想法,做一個整體的介紹。
我大家看到的“站外資源”頁面包括3個部分,前2個部分和內(nèi)置的鏈接管理(可惜Codex上只有英文介紹,中國人好像不太喜歡參與在本次開源創(chuàng)作中,可能是使用“免費(fèi)”軟件的習(xí)慣),后半部分是直接通過編輯頁面手動添加(就像寫普通文章一樣),全部改成直接調(diào)用()顯示內(nèi)置鏈接數(shù)據(jù)庫。
這種設(shè)計的優(yōu)點(diǎn)是您可以通過鏈接管理單元創(chuàng)建和管理您的附屬鏈接,當(dāng)您不想使用這樣一個單獨(dú)的頁面但在動態(tài)側(cè)邊欄上放置一個小部件時可以輕松切換沒有它需要太多的勞動;也可以編輯頁面單獨(dú)列出一些其他的內(nèi)容,隨時可能更改,或者放入鏈接管理比較復(fù)雜不方便。
二、準(zhǔn)備一個單獨(dú)的頁面模板
既然您需要創(chuàng)建特色內(nèi)容,您自然需要自己創(chuàng)建。幸運(yùn)的是,這一步非常簡單。 Codex 說默認(rèn)主題中有一個 links.php 模板,但我的沒有。不過沒關(guān)系wordpress 自定義鏈接,我們可以從默認(rèn)的 page.php 中創(chuàng)建一個。這里以當(dāng)前的默認(rèn)主題為例。
1、新建頁面模板
在您的主題文件夾中復(fù)制 page.php 并將其重命名為 links.php。
2、修改新模板的頭部信息。
使用文本編輯器打開 links.php(建議使用 ++),并使前幾行類似于以下內(nèi)容:
修改為:
暫時不要移動其他內(nèi)容。保存!
注意不同主題的模板寫法不同,不能通用;也就是說,如果你想改變主題,你可能需要以這種方式重新創(chuàng)建友好鏈接的頁面模板。
三、添加代碼生成鏈表
現(xiàn)在,讓我們在這個模板中添加代碼,從數(shù)據(jù)庫中讀取鏈接信息并顯示出來。
1、編輯剛剛保存的links.php文件
定位到以下位置:
/*我們需要在這里插入本文后面提供的代碼*/
/* Run the loop to output the page.
* If you want to overload this in a child theme then include a file
* called loop-page.php and that will be used instead.
*/
get_template_part( 'loop', 'page' );
?>
這樣,我們可以在保留頁面內(nèi)容的同時,在頁面內(nèi)容前面插入和顯示友好鏈接。如果不想保留原靜態(tài)頁面的內(nèi)容,只需刪除上面代碼片段中標(biāo)記為綠色的部分即可。
2、完成頁面。
這個主題挺變態(tài)的,一個頁面模板居然分為2個文件。將主循環(huán)單獨(dú)放在loop-page.php文件中,然后在page.php中調(diào)用主循環(huán)(上面代碼中綠色部分就是完成這個功能)。
這樣正好,這樣我們就可以看清楚頁面文件的結(jié)構(gòu)了。為簡單起見,我們在這里修剪這部分。有兩種情況:
如果您以后不需要像我一樣手動添加一些雜亂的鏈接(即部分),您可以刪除標(biāo)記為綠色的部分;如果你想保留它,你需要做一些改變。例如,您可能不想在頁面中保留頁面標(biāo)題wordpress 自定義鏈接,對嗎?和評論,還想要嗎?如果你想保留它,你可以跳過這一步,直接跳到下面的3。否則,請按照以下步驟操作:將上面標(biāo)記為綠色的部分替換為與page.php在同一文件夾中的loop-page.php中的代碼;刪除部分代碼:
還有wordpress做網(wǎng)站,
前半部分顯示頁面標(biāo)題,后半部分顯示評論等。
注意,如果使用其他主題,方法類似??赡芤话愕闹黝}不會單獨(dú)拿出主循環(huán),所以就跟著2.B去操作吧。
3、嵌入代碼
在橙色文字標(biāo)記的位置插入如下代碼,包含樣式、代碼、執(zhí)行語句等。
// 輸出負(fù)責(zé)顯示鏈接對應(yīng)網(wǎng)站 Favicon 的代碼
// 這一部分是設(shè)置 wp_list_bookmarks 的參數(shù)
// 如果在 WordPress 中的鏈接管理里面設(shè)置了多個分類,每個分類
// 都將以一個 div 單獨(dú)包圍起來
1, // 是否分類別顯示鏈接表
'category' => null, // (string) Comma separated list of numeric Category IDs to be displayed. If none is specified, all Categories with bookmarks are shown. Defaults to (all Categories).
'exclude_category' => null, // (string) Comma separated list of numeric Category IDs to be excluded from display. Defaults to (no categories excluded).
'category_name' => null, // (string) The name of a Category whose bookmarks will be displayed. If none is specified, all Categories with bookmarks are shown. Defaults to (all Categories).
'category_before' => '', // 分類別顯示時,分類名稱前置代碼
'category_after' => '
',
'class' => '', // (string) The class each category li will have on it. Defaults to 'linkcat' . (This parameter was added with Version 2.2)
'category_orderby' => 'id', // (string) Value to sort Categories on. Valid options:'name' - Default; 'id'; 'slug'; 'count'; 'term_group' (not used yet)
'category_order' => 'ASC', // (string) Sort order, ascending or descending for the category_orderby parameter. Valid values: ASC - Default; DESC
// When categorize set to 0, the following 3 params become active
'title_li' => null, // (string) Text for the heading of the links list. Defaults to '__('Bookmarks')', which displays "Bookmarks" (the __('') is used for localization purposes). Only used when categorize are set to 0 [false] (else the category names will be used instead). If 'title_li' is set to null (0) value, no heading is displayed, and the list will not be wrapped with tags (be sure to pass the categorize option to 0 [false] to this option takes effect).
'title_before' => '', // (string) Text to place before each Category description if 'categorize' is 1 [true], or text defined in "title_li" if 'categorize' is 0 [false]. Defaults to ''.
'title_after' => '
', // (string) Text to place after each Category description if 'categorize' is 1 [true], or text defined in "title_li" if 'categorize' is 0 [false]. Defaults to '
'.
// Overall sets for individual bookmark
'show_private' => '', // (boolean) Should a Category be displayed even if the Category is considered private. Ignore the admin setting and show private Categories (TRUE) or do NOT show private Categories (FALSE). 1 (True); 0 (False) - Default
'include' => null, // (string) Comma separated list of numeric bookmark IDs to include in the output. For example, 'include=1,3,6' means to return or echo bookmark IDs 1, 3, and 6. If the include string is used, the category, category_name, and exclude parameters are ignored. Defaults to (all Bookmarks).
'exclude' => null, // (string) Comma separated list of numeric bookmark IDs to exclude. For example, 'exclude=4,12' means that bookmark IDs 4 and 12 will NOT be returned or echoed. Defaults to (exclude nothing).
// Per category
'orderby' => '', // (string) Value to sort bookmarks on. This can be a COMMA separated list of values. Defaults to 'name' unless you pass the value of '' (empty), in which case it sets to 'id'.
'order' => 'DESC', // (string) Bookmarks display sorting order, ascending or descending as defined in the 'orderby' parameter. Valid values: ASC - Default; DESC
// Overall
'limit' => -1, // (integer) Maximum number of bookmarks to display. Default is -1 (all bookmarks).
// Overall sets for individual bookmark
'before' => '', //
'after' => '', // (string) Text to place after each bookmark. Defaults to ''.
'link_before' => '', // (string) Text to place before the text of each bookmark, inside the hyperlink code. There is no set default. (This parameter was added with Version 2.7)
'link_after' => '', // (string) Text to place after the text of each bookmark. There is no set default. (This parameter was added with Version 2.7)
'between' => '', // (string) Text to place between each bookmark/image and its description. Defaults to '\n' (newline).
'show_images' => 0, // (boolean) Should images for bookmarks be shown (TRUE) or not (FALSE). 1 (True) - Default; 0 (False)
'show_description' => 1, // (boolean) Should the description be displayed (TRUE) or not (FALSE). Valid when show_images is FALSE, or an image is not defined. 1 (True); 0 (False) - Default
'show_name' => 0, // (boolean) Displays the text of a link when (TRUE). Works when show_images is TRUE. (This parameter was added with Version 2.7) 1 (True); 0 (False) - Default
'show_rating' => 0, // (boolean) Should rating stars/characters be displayed (TRUE) or not (FALSE). 1 (True); 0 (False) - Default
'show_updated' => 0, // (boolean) Should the last updated timestamp be displayed (TRUE) or not (FALSE). Note that link_updated does not track local modifications. It tracks when whatever the link points to is updated via remote requests to pingomatic. 1 (True); 0 (False) - Default
'hide_invisible' => 1, // (boolean) Should bookmark be displayed even if it's Visible setting is No. Abides by admin setting (TRUE) or does no abide by admin setting (FALSE). 1 (True) - Default; 0 (False)
'echo' => 1, // (boolean) Display bookmarks (TRUE) or return them for use by PHP (FALSE). 1 (True) - Default; 0 (False)
);
?>
說明:
一個。代碼使用2.1.0版本中引入的()函數(shù)從數(shù)據(jù)庫中查詢和顯示鏈接。
b.如果在鏈接管理中建立了多個分類,如 和 ,每個分類都會使用分類名稱作為的標(biāo)題,并使用包。
c。服務(wù)的調(diào)用采用https加密鏈接的形式,以防止遇到和諧網(wǎng)站時中斷獲取圖標(biāo)的過程。
四、后記
這種事情真的不好解釋wordpress網(wǎng)站建設(shè),有什么問題請留言。請在提問前仔細(xì)研究。
五、更新2013.05.23
大部分內(nèi)容已經(jīng)修改,尤其是代碼?,F(xiàn)在使用 () 參數(shù)并且() 函數(shù)只被調(diào)用一次。使用()內(nèi)置分類功能,根據(jù)鏈接分類顯示若干塊(
)。
代碼現(xiàn)在干凈多了。之所以看起來很大,是因為它的所有參數(shù)都列在 () 的參數(shù)定義中??梢愿鶕?jù)需要進(jìn)行修改。幾乎每個參數(shù)后面都有描述。
2013.04.10
因為有些主題可能默認(rèn)不調(diào)用代碼,所以上面的代碼(在二、3中描述)做了修改,在
在前面添加調(diào)用輸出的代碼(藍(lán)色標(biāo)記):
?
這篇文章發(fā)表在 頁面上。固定鏈接:。轉(zhuǎn)載請保留此信息及相關(guān)鏈接。
類別 |標(biāo)簽 , , , PHP, , 主題, 定制, 網(wǎng)頁設(shè)計 |作者 H Zeng |收藏夾 固定鏈接
文章來自互聯(lián)網(wǎng),侵權(quán)請聯(lián)系刪除,文章闡述觀點(diǎn)來自文章出處,并不代表本站觀點(diǎn)。
www.bjcthy.com