前几天,我从容斌的(链接已过期)友情链接页面看到,他在每个链接前都放了一张图片。这些图像是从网站图标以编程方式生成的,并且具有很多特征。后来查了一下,发现也有可以实现类似功能的程序。有人说程序不稳定,不完整,但我注意到我在使用这样的功能,觉得还不错,所以决定使用它。
看来容斌为了让网站看起来更整洁,把他的链接页面去掉了,所以不能让大家看到效果。我只记得他当时提到过这样的事情,但我忘记了他从哪里得到的。因为我用的是另一种方法,所以我就不多介绍了。有兴趣的可以看这里(链接已过期)。它似乎是 的发源地。
这里是使用提供的 -to-image 功能创建链接页面的完整过程和方法。
内容目录:
一、理念介绍
先说一下我的想法,做一个整体的介绍。
我大家看到的“站外资源”页面包括3个部分,前2个部分和内置的链接管理(可惜Codex上只有英文介绍,中国人好像不太喜欢参与在本次开源创作中,可能是使用“免费”软件的习惯),后半部分是直接通过编辑页面手动添加(就像写普通文章一样),全部改成直接调用()显示内置链接数据库。
这种设计的优点是您可以通过链接管理单元创建和管理您的附属链接,当您不想使用这样一个单独的页面但在动态侧边栏上放置一个小部件时可以轻松切换没有它需要太多的劳动;也可以编辑页面单独列出一些其他的内容,随时可能更改,或者放入链接管理比较复杂不方便。
二、准备一个单独的页面模板
既然您需要创建特色内容,您自然需要自己创建。幸运的是,这一步非常简单。 Codex 说默认主题中有一个 links.php 模板,但我的没有。不过没关系wordpress 自定义链接,我们可以从默认的 page.php 中创建一个。这里以当前的默认主题为例。
1、新建页面模板
在您的主题文件夹中复制 page.php 并将其重命名为 links.php。
2、修改新模板的头部信息。
使用文本编辑器打开 links.php(建议使用 ++),并使前几行类似于以下内容:
修改为:
暂时不要移动其他内容。保存!
注意不同主题的模板写法不同,不能通用;也就是说,如果你想改变主题,你可能需要以这种方式重新创建友好链接的页面模板。
三、添加代码生成链表
现在,让我们在这个模板中添加代码,从数据库中读取链接信息并显示出来。
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' );
?>
这样,我们可以在保留页面内容的同时,在页面内容前面插入和显示友好链接。如果不想保留原静态页面的内容,只需删除上面代码片段中标记为绿色的部分即可。
2、完成页面。
这个主题挺变态的,一个页面模板居然分为2个文件。将主循环单独放在loop-page.php文件中,然后在page.php中调用主循环(上面代码中绿色部分就是完成这个功能)。
这样正好,这样我们就可以看清楚页面文件的结构了。为简单起见,我们在这里修剪这部分。有两种情况:
如果您以后不需要像我一样手动添加一些杂乱的链接(即部分),您可以删除标记为绿色的部分;如果你想保留它,你需要做一些改变。例如,您可能不想在页面中保留页面标题wordpress 自定义链接,对吗?和评论,还想要吗?如果你想保留它,你可以跳过这一步,直接跳到下面的3。否则,请按照以下步骤操作:将上面标记为绿色的部分替换为与page.php在同一文件夹中的loop-page.php中的代码;删除部分代码:
还有wordpress做网站,
前半部分显示页面标题,后半部分显示评论等。
注意,如果使用其他主题,方法类似。可能一般的主题不会单独拿出主循环,所以就跟着2.B去操作吧。
3、嵌入代码
在橙色文字标记的位置插入如下代码,包含样式、代码、执行语句等。
// 输出负责显示链接对应网站 Favicon 的代码
// 这一部分是设置 wp_list_bookmarks 的参数
// 如果在 WordPress 中的链接管理里面设置了多个分类,每个分类
// 都将以一个 div 单独包围起来
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版本中引入的()函数从数据库中查询和显示链接。
b.如果在链接管理中建立了多个分类,如 和 ,每个分类都会使用分类名称作为的标题,并使用包。
c。服务的调用采用https加密链接的形式,以防止遇到和谐网站时中断获取图标的过程。
四、后记
这种事情真的不好解释wordpress网站建设,有什么问题请留言。请在提问前仔细研究。
五、更新2013.05.23
大部分内容已经修改,尤其是代码。现在使用 () 参数并且() 函数只被调用一次。使用()内置分类功能,根据链接分类显示若干块(
)。
代码现在干净多了。之所以看起来很大,是因为它的所有参数都列在 () 的参数定义中。可以根据需要进行修改。几乎每个参数后面都有描述。
2013.04.10
因为有些主题可能默认不调用代码,所以上面的代码(在二、3中描述)做了修改,在
在前面添加调用输出的代码(蓝色标记):
©
这篇文章发表在 页面上。固定链接:。转载请保留此信息及相关链接。
类别 |标签 , , , PHP, , 主题, 定制, 网页设计 |作者 H Zeng |收藏夹 固定链接
文章来自互联网,侵权请联系删除,文章阐述观点来自文章出处,并不代表本站观点。
www.8001717.cn