生命不息,奋斗不止/创造价值-传递价值-获得价值
所谓迷茫,就是才华配不上梦想 每一个让你难堪的现在,都有一个不够努力的曾经

WordPress添加相关文章功能(标题/缩略图样式)

本文将教会你如何为WordPress添加相关文章功能,并提供了标题列表样式和缩略图样式。相关文章的获取思路是:Tags标签相关>同分类下文章,也就是说,先获取标签相同的文章,如果还达不到数量,就调用该分类下的文章补足。获取方法貌似最初来自Willin Kan 大师,倡萌再次修改。

1.添加标题列表样式的相关文章

WordPress添加相关文章功能(标题/缩略图样式)

将下面的代码添加到 single.php 要显示相关文章的位置即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<h3>相关文章</h3>
<ul class="related_posts">
<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php
<span%20style="color: #000088;"="">$post_num <span%20style="color: #339933;"="">= <span%20style="color: #cc66cc;"="">8<span%20style="color: #339933;"="">;
<span%20style="color: #000088;"="">$exclude_id <span%20style="color: #339933;"="">= <span%20style="color: #000088;"="">$post<span%20style="color: #339933;"="">-><span%20style="color: #004000;"="">ID<span%20style="color: #339933;"="">;
<span%20style="color: #000088;"="">$posttags <span%20style="color: #339933;"="">= get_the_tags<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000088;"="">$i <span%20style="color: #339933;"="">= <span%20style="color: #cc66cc;"="">0<span%20style="color: #339933;"="">;
<span%20style="color: #b1b100;"="">if <span%20style="color: #009900;"="">( <span%20style="color: #000088;"="">$posttags <span%20style="color: #009900;"="">) <span%20style="color: #009900;"="">{
	<span%20style="color: #000088;"="">$tags <span%20style="color: #339933;"="">= <span%20style="color: #0000ff;"="">''<span%20style="color: #339933;"="">; <span%20style="color: #b1b100;"="">foreach <span%20style="color: #009900;"="">( <span%20style="color: #000088;"="">$posttags <span%20style="color: #b1b100;"="">as <span%20style="color: #000088;"="">$tag <span%20style="color: #009900;"="">) <span%20style="color: #000088;"="">$tags <span%20style="color: #339933;"="">.= <span%20style="color: #000088;"="">$tag<span%20style="color: #339933;"="">-><span%20style="color: #004000;"="">term_id <span%20style="color: #339933;"="">. <span%20style="color: #0000ff;"="">','<span%20style="color: #339933;"="">;
	<span%20style="color: #000088;"="">$args <span%20style="color: #339933;"="">= <span%20style="color: #990000;"="">array<span%20style="color: #009900;"="">(
		<span%20style="color: #0000ff;"="">'post_status' <span%20style="color: #339933;"="">=> <span%20style="color: #0000ff;"="">'publish'<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'tag__in' <span%20style="color: #339933;"="">=> <span%20style="color: #990000;"="">explode<span%20style="color: #009900;"="">(<span%20style="color: #0000ff;"="">','<span%20style="color: #339933;"="">, <span%20style="color: #000088;"="">$tags<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'post__not_in' <span%20style="color: #339933;"="">=> <span%20style="color: #990000;"="">explode<span%20style="color: #009900;"="">(<span%20style="color: #0000ff;"="">','<span%20style="color: #339933;"="">, <span%20style="color: #000088;"="">$exclude_id<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'caller_get_posts' <span%20style="color: #339933;"="">=> <span%20style="color: #cc66cc;"="">1<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'orderby' <span%20style="color: #339933;"="">=> <span%20style="color: #0000ff;"="">'comment_date'<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'posts_per_page' <span%20style="color: #339933;"="">=> <span%20style="color: #000088;"="">$post_num<span%20style="color: #339933;"="">,
	<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
	query_posts<span%20style="color: #009900;"="">(<span%20style="color: #000088;"="">$args<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
	<span%20style="color: #b1b100;"="">while<span%20style="color: #009900;"="">( have_posts<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">) <span%20style="color: #009900;"="">) <span%20style="color: #009900;"="">{ the_post<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>
		<li><a rel="bookmark" href="<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_permalink<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>" title="<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_title<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>" target="_blank"><span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_title<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?></a></li>
	<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php
		<span%20style="color: #000088;"="">$exclude_id <span%20style="color: #339933;"="">.= <span%20style="color: #0000ff;"="">',' <span%20style="color: #339933;"="">. <span%20style="color: #000088;"="">$post<span%20style="color: #339933;"="">-><span%20style="color: #004000;"="">ID<span%20style="color: #339933;"="">; <span%20style="color: #000088;"="">$i <span%20style="color: #339933;"="">++;
	<span%20style="color: #009900;"="">} wp_reset_query<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
<span%20style="color: #009900;"="">}
<span%20style="color: #b1b100;"="">if <span%20style="color: #009900;"="">( <span%20style="color: #000088;"="">$i <span%20style="color: #339933;"="">< <span%20style="color: #000088;"="">$post_num <span%20style="color: #009900;"="">) <span%20style="color: #009900;"="">{
	<span%20style="color: #000088;"="">$cats <span%20style="color: #339933;"="">= <span%20style="color: #0000ff;"="">''<span%20style="color: #339933;"="">; <span%20style="color: #b1b100;"="">foreach <span%20style="color: #009900;"="">( get_the_category<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">) <span%20style="color: #b1b100;"="">as <span%20style="color: #000088;"="">$cat <span%20style="color: #009900;"="">) <span%20style="color: #000088;"="">$cats <span%20style="color: #339933;"="">.= <span%20style="color: #000088;"="">$cat<span%20style="color: #339933;"="">-><span%20style="color: #004000;"="">cat_ID <span%20style="color: #339933;"="">. <span%20style="color: #0000ff;"="">','<span%20style="color: #339933;"="">;
	<span%20style="color: #000088;"="">$args <span%20style="color: #339933;"="">= <span%20style="color: #990000;"="">array<span%20style="color: #009900;"="">(
		<span%20style="color: #0000ff;"="">'category__in' <span%20style="color: #339933;"="">=> <span%20style="color: #990000;"="">explode<span%20style="color: #009900;"="">(<span%20style="color: #0000ff;"="">','<span%20style="color: #339933;"="">, <span%20style="color: #000088;"="">$cats<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'post__not_in' <span%20style="color: #339933;"="">=> <span%20style="color: #990000;"="">explode<span%20style="color: #009900;"="">(<span%20style="color: #0000ff;"="">','<span%20style="color: #339933;"="">, <span%20style="color: #000088;"="">$exclude_id<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'caller_get_posts' <span%20style="color: #339933;"="">=> <span%20style="color: #cc66cc;"="">1<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'orderby' <span%20style="color: #339933;"="">=> <span%20style="color: #0000ff;"="">'comment_date'<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'posts_per_page' <span%20style="color: #339933;"="">=> <span%20style="color: #000088;"="">$post_num <span%20style="color: #339933;"="">- <span%20style="color: #000088;"="">$i
	<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
	query_posts<span%20style="color: #009900;"="">(<span%20style="color: #000088;"="">$args<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
	<span%20style="color: #b1b100;"="">while<span%20style="color: #009900;"="">( have_posts<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">) <span%20style="color: #009900;"="">) <span%20style="color: #009900;"="">{ the_post<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>
		<li><a rel="bookmark" href="<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_permalink<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>"  title="<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_title<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>" target="_blank"><span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_title<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?></a></li>
	<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php <span%20style="color: #000088;"="">$i<span%20style="color: #339933;"="">++;
	<span%20style="color: #009900;"="">} wp_reset_query<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
<span%20style="color: #009900;"="">}
<span%20style="color: #b1b100;"="">if <span%20style="color: #009900;"="">( <span%20style="color: #000088;"="">$i  <span%20style="color: #339933;"="">== <span%20style="color: #cc66cc;"="">0 <span%20style="color: #009900;"="">)  <span%20style="color: #b1b100;"="">echo <span%20style="color: #0000ff;"="">'<li>没有相关文章!</li>'<span%20style="color: #339933;"="">;
<span%20style="color: #000000;="" font-weight:="" bold;"="">?>
</ul></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:>

PS:第四行$post_num = 8;表示显示8篇文章,请根据自己的需要修改。

显示样式需要自己写css,可以参考一下下面的:

1
2
<span%20style="color: #6666ff;"="">.related_posts<span%20style="color: #00aa00;"="">{<span%20style="color: #000000;="" font-weight:="" bold;"="">margin-top<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">5px<span%20style="color: #00aa00;"="">;<span%20style="color: #00aa00;"="">}
<span%20style="color: #6666ff;"="">.related_posts li<span%20style="color: #00aa00;"="">{<span%20style="color: #000000;="" font-weight:="" bold;"="">margin-left<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">20px<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">color<span%20style="color: #00aa00;"="">:<span%20style="color: #cc00cc;"="">#444<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">list-style<span%20style="color: #00aa00;"="">:<span%20style="color: #993333;"="">circle<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">font-size<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">14px<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">line-height<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">26px<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">padding<span%20style="color: #00aa00;"="">:<span%20style="color: #cc66cc;"="">0 <span%20style="color: #cc66cc;"="">0 <span%20style="color: #cc66cc;"="">0 <span%20style="color: #933;"="">5px<span%20style="color: #00aa00;"="">}</span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:>

2.添加含缩略图的相关文章

WordPress添加相关文章功能(标题/缩略图样式)

倡萌只是根据上面的代码改了一下,添加了缩略图。

1)在主题的 functions.php 的最后一个 ?> 前添加下面的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<span%20style="color: #666666;="" font-style:="" italic;"="">//添加特色缩略图支持
<span%20style="color: #b1b100;"="">if <span%20style="color: #009900;"="">( <span%20style="color: #990000;"="">function_exists<span%20style="color: #009900;"="">(<span%20style="color: #0000ff;"="">'add_theme_support'<span%20style="color: #009900;"="">) <span%20style="color: #009900;"="">)add_theme_support<span%20style="color: #009900;"="">(<span%20style="color: #0000ff;"="">'post-thumbnails'<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
 
<span%20style="color: #666666;="" font-style:="" italic;"="">//输出缩略图地址 From wpdaxue.com
<span%20style="color: #000000;="" font-weight:="" bold;"="">function post_thumbnail_src<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #009900;"="">{
    <span%20style="color: #000000;="" font-weight:="" bold;"="">global <span%20style="color: #000088;"="">$post<span%20style="color: #339933;"="">;
	<span%20style="color: #b1b100;"="">if<span%20style="color: #009900;"="">( <span%20style="color: #000088;"="">$values <span%20style="color: #339933;"="">= get_post_custom_values<span%20style="color: #009900;"="">(<span%20style="color: #0000ff;"="">"thumb"<span%20style="color: #009900;"="">) <span%20style="color: #009900;"="">) <span%20style="color: #009900;"="">{	<span%20style="color: #666666;="" font-style:="" italic;"="">//输出自定义域图片地址
		<span%20style="color: #000088;"="">$values <span%20style="color: #339933;"="">= get_post_custom_values<span%20style="color: #009900;"="">(<span%20style="color: #0000ff;"="">"thumb"<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
		<span%20style="color: #000088;"="">$post_thumbnail_src <span%20style="color: #339933;"="">= <span%20style="color: #000088;"="">$values <span%20style="color: #009900;"="">[<span%20style="color: #cc66cc;"="">0<span%20style="color: #009900;"="">]<span%20style="color: #339933;"="">;
	<span%20style="color: #009900;"="">} <span%20style="color: #b1b100;"="">elseif<span%20style="color: #009900;"="">( has_post_thumbnail<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">) <span%20style="color: #009900;"="">)<span%20style="color: #009900;"="">{    <span%20style="color: #666666;="" font-style:="" italic;"="">//如果有特色缩略图,则输出缩略图地址
        <span%20style="color: #000088;"="">$thumbnail_src <span%20style="color: #339933;"="">= wp_get_attachment_image_src<span%20style="color: #009900;"="">(get_post_thumbnail_id<span%20style="color: #009900;"="">(<span%20style="color: #000088;"="">$post<span%20style="color: #339933;"="">-><span%20style="color: #004000;"="">ID<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">,<span%20style="color: #0000ff;"="">'full'<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
		<span%20style="color: #000088;"="">$post_thumbnail_src <span%20style="color: #339933;"="">= <span%20style="color: #000088;"="">$thumbnail_src <span%20style="color: #009900;"="">[<span%20style="color: #cc66cc;"="">0<span%20style="color: #009900;"="">]<span%20style="color: #339933;"="">;
    <span%20style="color: #009900;"="">} <span%20style="color: #b1b100;"="">else <span%20style="color: #009900;"="">{
		<span%20style="color: #000088;"="">$post_thumbnail_src <span%20style="color: #339933;"="">= <span%20style="color: #0000ff;"="">''<span%20style="color: #339933;"="">;
		<span%20style="color: #990000;"="">ob_start<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
		<span%20style="color: #990000;"="">ob_end_clean<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
		<span%20style="color: #000088;"="">$output <span%20style="color: #339933;"="">= <span%20style="color: #990000;"="">preg_match_all<span%20style="color: #009900;"="">(<span%20style="color: #0000ff;"="">'/<img.+src=[\'"]([^\'"]+)[\'"].*>/i'<span%20style="color: #339933;"="">, <span%20style="color: #000088;"="">$post<span%20style="color: #339933;"="">-><span%20style="color: #004000;"="">post_content<span%20style="color: #339933;"="">, <span%20style="color: #000088;"="">$matches<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
		<span%20style="color: #000088;"="">$post_thumbnail_src <span%20style="color: #339933;"="">= <span%20style="color: #000088;"="">$matches <span%20style="color: #009900;"="">[<span%20style="color: #cc66cc;"="">1<span%20style="color: #009900;"="">] <span%20style="color: #009900;"="">[<span%20style="color: #cc66cc;"="">0<span%20style="color: #009900;"="">]<span%20style="color: #339933;"="">;   <span%20style="color: #666666;="" font-style:="" italic;"="">//获取该图片 src
		<span%20style="color: #b1b100;"="">if<span%20style="color: #009900;"="">(<span%20style="color: #990000;"="">empty<span%20style="color: #009900;"="">(<span%20style="color: #000088;"="">$post_thumbnail_src<span%20style="color: #009900;"="">)<span%20style="color: #009900;"="">)<span%20style="color: #009900;"="">{	<span%20style="color: #666666;="" font-style:="" italic;"="">//如果日志中没有图片,则显示随机图片
			<span%20style="color: #000088;"="">$random <span%20style="color: #339933;"="">= <span%20style="color: #990000;"="">mt_rand<span%20style="color: #009900;"="">(<span%20style="color: #cc66cc;"="">1<span%20style="color: #339933;"="">, <span%20style="color: #cc66cc;"="">10<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
			<span%20style="color: #b1b100;"="">echo get_bloginfo<span%20style="color: #009900;"="">(<span%20style="color: #0000ff;"="">'template_url'<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
			<span%20style="color: #b1b100;"="">echo <span%20style="color: #0000ff;"="">'/images/pic/'<span%20style="color: #339933;"="">.<span%20style="color: #000088;"="">$random<span%20style="color: #339933;"="">.<span%20style="color: #0000ff;"="">'.jpg'<span%20style="color: #339933;"="">;
			<span%20style="color: #666666;="" font-style:="" italic;"="">//如果日志中没有图片,则显示默认图片
			<span%20style="color: #666666;="" font-style:="" italic;"="">//echo '/images/default_thumb.jpg';
		<span%20style="color: #009900;"="">}
	<span%20style="color: #009900;"="">}<span%20style="color: #339933;"="">;
	<span%20style="color: #b1b100;"="">echo <span%20style="color: #000088;"="">$post_thumbnail_src<span%20style="color: #339933;"="">;
<span%20style="color: #009900;"="">}</span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:>

PS:上面的代码主要是获取图片链接,获取的顺序是:

自定义字段为 thumb 的图片>特色缩略图>文章第一张图片>随机图片/默认图片;

随机图片:请制作10张图片,放在现用主题文件夹下的 images/pic/ 目录,图片为jpg格式,并且使用数字 1-10命名,比如 1.jpg;如果你不想用随机图片,请将 倒数第5行 前面的“//”去掉,然后给 倒数第7、9行 前面添加“//”注销,并且在现用主题的 /images/ 目录下添加一张名字为 default_thumb.jpg 的默认图片,这样,就会显示默认图片。

2)将下面的代码添加到 single.php 要显示相关文章的位置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<h3>相关文章</h3>
<ul class="related_img">
<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php
<span%20style="color: #000088;"="">$post_num <span%20style="color: #339933;"="">= <span%20style="color: #cc66cc;"="">4<span%20style="color: #339933;"="">;
<span%20style="color: #000088;"="">$exclude_id <span%20style="color: #339933;"="">= <span%20style="color: #000088;"="">$post<span%20style="color: #339933;"="">-><span%20style="color: #004000;"="">ID<span%20style="color: #339933;"="">;
<span%20style="color: #000088;"="">$posttags <span%20style="color: #339933;"="">= get_the_tags<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000088;"="">$i <span%20style="color: #339933;"="">= <span%20style="color: #cc66cc;"="">0<span%20style="color: #339933;"="">;
<span%20style="color: #b1b100;"="">if <span%20style="color: #009900;"="">( <span%20style="color: #000088;"="">$posttags <span%20style="color: #009900;"="">) <span%20style="color: #009900;"="">{
	<span%20style="color: #000088;"="">$tags <span%20style="color: #339933;"="">= <span%20style="color: #0000ff;"="">''<span%20style="color: #339933;"="">; <span%20style="color: #b1b100;"="">foreach <span%20style="color: #009900;"="">( <span%20style="color: #000088;"="">$posttags <span%20style="color: #b1b100;"="">as <span%20style="color: #000088;"="">$tag <span%20style="color: #009900;"="">) <span%20style="color: #000088;"="">$tags <span%20style="color: #339933;"="">.= <span%20style="color: #000088;"="">$tag<span%20style="color: #339933;"="">-><span%20style="color: #004000;"="">term_id <span%20style="color: #339933;"="">. <span%20style="color: #0000ff;"="">','<span%20style="color: #339933;"="">;
	<span%20style="color: #000088;"="">$args <span%20style="color: #339933;"="">= <span%20style="color: #990000;"="">array<span%20style="color: #009900;"="">(
		<span%20style="color: #0000ff;"="">'post_status' <span%20style="color: #339933;"="">=> <span%20style="color: #0000ff;"="">'publish'<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'tag__in' <span%20style="color: #339933;"="">=> <span%20style="color: #990000;"="">explode<span%20style="color: #009900;"="">(<span%20style="color: #0000ff;"="">','<span%20style="color: #339933;"="">, <span%20style="color: #000088;"="">$tags<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'post__not_in' <span%20style="color: #339933;"="">=> <span%20style="color: #990000;"="">explode<span%20style="color: #009900;"="">(<span%20style="color: #0000ff;"="">','<span%20style="color: #339933;"="">, <span%20style="color: #000088;"="">$exclude_id<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'caller_get_posts' <span%20style="color: #339933;"="">=> <span%20style="color: #cc66cc;"="">1<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'orderby' <span%20style="color: #339933;"="">=> <span%20style="color: #0000ff;"="">'comment_date'<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'posts_per_page' <span%20style="color: #339933;"="">=> <span%20style="color: #000088;"="">$post_num
	<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
	query_posts<span%20style="color: #009900;"="">(<span%20style="color: #000088;"="">$args<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
	<span%20style="color: #b1b100;"="">while<span%20style="color: #009900;"="">( have_posts<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">) <span%20style="color: #009900;"="">) <span%20style="color: #009900;"="">{ the_post<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>
		<li class="related_box"  >
		<div class="r_pic">
		<a href="<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_permalink<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>" title="<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_title<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>" target="_blank">
		<img src="<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php <span%20style="color: #b1b100;"="">echo post_thumbnail_src<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>" alt="<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_title<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>" class="thumbnail" />
		</a>
		</div>
		<div class="r_title"><a href="<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_permalink<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>" title="<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_title<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>" target="_blank" rel="bookmark"><span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_title<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?></a></div>
		</li>
	<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php
		<span%20style="color: #000088;"="">$exclude_id <span%20style="color: #339933;"="">.= <span%20style="color: #0000ff;"="">',' <span%20style="color: #339933;"="">. <span%20style="color: #000088;"="">$post<span%20style="color: #339933;"="">-><span%20style="color: #004000;"="">ID<span%20style="color: #339933;"="">; <span%20style="color: #000088;"="">$i <span%20style="color: #339933;"="">++;
	<span%20style="color: #009900;"="">} wp_reset_query<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
<span%20style="color: #009900;"="">}
<span%20style="color: #b1b100;"="">if <span%20style="color: #009900;"="">( <span%20style="color: #000088;"="">$i <span%20style="color: #339933;"="">< <span%20style="color: #000088;"="">$post_num <span%20style="color: #009900;"="">) <span%20style="color: #009900;"="">{
	<span%20style="color: #000088;"="">$cats <span%20style="color: #339933;"="">= <span%20style="color: #0000ff;"="">''<span%20style="color: #339933;"="">; <span%20style="color: #b1b100;"="">foreach <span%20style="color: #009900;"="">( get_the_category<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">) <span%20style="color: #b1b100;"="">as <span%20style="color: #000088;"="">$cat <span%20style="color: #009900;"="">) <span%20style="color: #000088;"="">$cats <span%20style="color: #339933;"="">.= <span%20style="color: #000088;"="">$cat<span%20style="color: #339933;"="">-><span%20style="color: #004000;"="">cat_ID <span%20style="color: #339933;"="">. <span%20style="color: #0000ff;"="">','<span%20style="color: #339933;"="">;
	<span%20style="color: #000088;"="">$args <span%20style="color: #339933;"="">= <span%20style="color: #990000;"="">array<span%20style="color: #009900;"="">(
		<span%20style="color: #0000ff;"="">'category__in' <span%20style="color: #339933;"="">=> <span%20style="color: #990000;"="">explode<span%20style="color: #009900;"="">(<span%20style="color: #0000ff;"="">','<span%20style="color: #339933;"="">, <span%20style="color: #000088;"="">$cats<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'post__not_in' <span%20style="color: #339933;"="">=> <span%20style="color: #990000;"="">explode<span%20style="color: #009900;"="">(<span%20style="color: #0000ff;"="">','<span%20style="color: #339933;"="">, <span%20style="color: #000088;"="">$exclude_id<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'caller_get_posts' <span%20style="color: #339933;"="">=> <span%20style="color: #cc66cc;"="">1<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'orderby' <span%20style="color: #339933;"="">=> <span%20style="color: #0000ff;"="">'comment_date'<span%20style="color: #339933;"="">,
		<span%20style="color: #0000ff;"="">'posts_per_page' <span%20style="color: #339933;"="">=> <span%20style="color: #000088;"="">$post_num <span%20style="color: #339933;"="">- <span%20style="color: #000088;"="">$i
	<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
	query_posts<span%20style="color: #009900;"="">(<span%20style="color: #000088;"="">$args<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
	<span%20style="color: #b1b100;"="">while<span%20style="color: #009900;"="">( have_posts<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">) <span%20style="color: #009900;"="">) <span%20style="color: #009900;"="">{ the_post<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>
	<li class="related_box"  >
		<div class="r_pic">
		<a href="<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_permalink<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>" title="<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_title<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>" target="_blank">
		<img src="<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php <span%20style="color: #b1b100;"="">echo post_thumbnail_src<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>" alt="<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_title<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>" class="thumbnail" />
		</a>
		</div>
		<div class="r_title"><a href="<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_permalink<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>" title="<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_title<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?>" target="_blank" rel="bookmark"><span%20style="color: #000000;="" font-weight:="" bold;"=""><?php the_title<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">; <span%20style="color: #000000;="" font-weight:="" bold;"="">?></a></div>
	</li>
	<span%20style="color: #000000;="" font-weight:="" bold;"=""><?php <span%20style="color: #000088;"="">$i<span%20style="color: #339933;"="">++;
	<span%20style="color: #009900;"="">} wp_reset_query<span%20style="color: #009900;"="">(<span%20style="color: #009900;"="">)<span%20style="color: #339933;"="">;
<span%20style="color: #009900;"="">}
<span%20style="color: #b1b100;"="">if <span%20style="color: #009900;"="">( <span%20style="color: #000088;"="">$i  <span%20style="color: #339933;"="">== <span%20style="color: #cc66cc;"="">0 <span%20style="color: #009900;"="">)  <span%20style="color: #b1b100;"="">echo <span%20style="color: #0000ff;"="">'<div class="r_title">没有相关文章!</div>'<span%20style="color: #339933;"="">;
<span%20style="color: #000000;="" font-weight:="" bold;"="">?>
</ul></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:>

PS:第四行$post_num = 4; 表示调用4篇文章,请根据自己需要修改。

css样式自己写,也可参考一下:

1
2
3
4
5
6
7
<span%20style="color: #6666ff;"="">.related_posts<span%20style="color: #00aa00;"="">{<span%20style="color: #000000;="" font-weight:="" bold;"="">margin-top<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">5px<span%20style="color: #00aa00;"="">;<span%20style="color: #00aa00;"="">}
<span%20style="color: #6666ff;"="">.related_img<span%20style="color: #00aa00;"="">{<span%20style="color: #000000;="" font-weight:="" bold;"="">width<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">600px<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">height<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">210px<span%20style="color: #00aa00;"="">;<span%20style="color: #00aa00;"="">}
<span%20style="color: #6666ff;"="">.related_box<span%20style="color: #00aa00;"="">{<span%20style="color: #000000;="" font-weight:="" bold;"="">float<span%20style="color: #00aa00;"="">:<span%20style="color: #993333;"="">left<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">overflow<span%20style="color: #00aa00;"="">:<span%20style="color: #993333;"="">hidden<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">margin-top<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">5px<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">width<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">148px<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">border-right<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">1px <span%20style="color: #cc00cc;"="">#eee <span%20style="color: #993333;"="">solid<span%20style="color: #00aa00;"="">}
<span%20style="color: #6666ff;"="">.related_box<span%20style="color: #00aa00;"="">:<span%20style="color: #f5758f;"="">hover<span%20style="color: #00aa00;"="">{<span%20style="color: #000000;="" font-weight:="" bold;"="">background<span%20style="color: #00aa00;"="">:<span%20style="color: #cc00cc;"="">#f9f9f9<span%20style="color: #00aa00;"="">}
<span%20style="color: #6666ff;"="">.related_box <span%20style="color: #6666ff;"="">.r_title<span%20style="color: #00aa00;"="">{<span%20style="color: #000000;="" font-weight:="" bold;"="">width<span%20style="color: #00aa00;"="">:<span%20style="color: #993333;"="">auto<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">height<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">72px<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">font-weight<span%20style="color: #00aa00;"="">:<span%20style="color: #cc66cc;"="">400<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">font-size<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">14px<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">margin<span%20style="color: #00aa00;"="">:<span%20style="color: #cc66cc;"="">0 <span%20style="color: #933;"="">10px<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">overflow<span%20style="color: #00aa00;"="">:<span%20style="color: #993333;"="">hidden<span%20style="color: #00aa00;"="">;<span%20style="color: #00aa00;"="">}
<span%20style="color: #6666ff;"="">.related_box <span%20style="color: #6666ff;"="">.r_pic<span%20style="color: #00aa00;"="">{<span%20style="color: #000000;="" font-weight:="" bold;"="">margin<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">6px<span%20style="color: #00aa00;"="">}
<span%20style="color: #6666ff;"="">.related_box <span%20style="color: #6666ff;"="">.r_pic img<span%20style="color: #00aa00;"="">{<span%20style="color: #000000;="" font-weight:="" bold;"="">width<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">130px<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">height<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">100px<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">border<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">1px  <span%20style="color: #993333;"="">solid <span%20style="color: #cc00cc;"="">#e1e1e1<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">background<span%20style="color: #00aa00;"="">:<span%20style="color: #cc00cc;"="">#fff<span%20style="color: #00aa00;"="">;<span%20style="color: #000000;="" font-weight:="" bold;"="">padding<span%20style="color: #00aa00;"="">:<span%20style="color: #933;"="">2px<span%20style="color: #00aa00;"="">}</span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:></span%20style="color:>
赞(1)
未经允许不得转载:jack361博客 » WordPress添加相关文章功能(标题/缩略图样式)

如果你爱我或恨我,请↓

联系我