-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordpress自定义页面显示所有文章列表.html
200 lines (189 loc) · 14.9 KB
/
wordpress自定义页面显示所有文章列表.html
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="littlewhite" />
<meta name="copyright" content="littlewhite" />
<meta property="og:type" content="article" />
<meta name="twitter:card" content="summary">
<meta name="keywords" content="wordpress, Skill, " />
<meta property="og:title" content="wordpress自定义页面显示所有文章列表 "/>
<meta property="og:url" content="https://chukeer.github.io/wordpress自定义页面显示所有文章列表.html" />
<meta property="og:description" content="wordpress博客里有两种类型的网页,一种叫文章,一种叫页面(page),文章就是你发表的每篇博客所在的网页,页面就是你网站导航栏里的那些链接,比如“首页”,“关于我”这样的网页,这种网页的特点是集中展示某一类信息,比如首页展示每篇博客的摘要,“关于我”展示博主简介等等,自定义文章列表毫无疑问也是属于这一类的 page类型的网页都是根据模板生成的,wordpress默认没有这一类模板,因此需要自己写一个PHP脚本,首先我们找到模板所在的目录,假设你的wordpress所在目录为/var/www,那么模板脚本在/var/www/wp-content/themes/your_theme,其中your_theme是你所使用的主体包,在里面建立一个文件page-allpost.php,内容如下 <?php get_header(); ?> <style type="text/css"> #table-allpost{border-collapse:collapse;} #table-allpost td,#table-allpost th{border:1px solid #98bf21;padding ..." />
<meta property="og:site_name" content="楚客" />
<meta property="og:article:author" content="littlewhite" />
<meta property="og:article:published_time" content="2014-03-27T00:00:00+08:00" />
<meta property="" content="2014-03-27T00:00:00+08:00" />
<meta name="twitter:title" content="wordpress自定义页面显示所有文章列表 ">
<meta name="twitter:description" content="wordpress博客里有两种类型的网页,一种叫文章,一种叫页面(page),文章就是你发表的每篇博客所在的网页,页面就是你网站导航栏里的那些链接,比如“首页”,“关于我”这样的网页,这种网页的特点是集中展示某一类信息,比如首页展示每篇博客的摘要,“关于我”展示博主简介等等,自定义文章列表毫无疑问也是属于这一类的 page类型的网页都是根据模板生成的,wordpress默认没有这一类模板,因此需要自己写一个PHP脚本,首先我们找到模板所在的目录,假设你的wordpress所在目录为/var/www,那么模板脚本在/var/www/wp-content/themes/your_theme,其中your_theme是你所使用的主体包,在里面建立一个文件page-allpost.php,内容如下 <?php get_header(); ?> <style type="text/css"> #table-allpost{border-collapse:collapse;} #table-allpost td,#table-allpost th{border:1px solid #98bf21;padding ...">
<title>wordpress自定义页面显示所有文章列表 · 楚客
</title>
<!--
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.1/css/font-awesome.css" rel="stylesheet">
--!>
<link href="https://chukeer.github.io/theme/css/bootstrap-combined.min.css" rel="stylesheet">
<link href="https://chukeer.github.io/theme/css/font-awesome.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://chukeer.github.io/theme/css/pygments.css" media="screen">
<link rel="stylesheet" type="text/css" href="https://chukeer.github.io/theme/tipuesearch/tipuesearch.css" media="screen">
<link rel="stylesheet" type="text/css" href="https://chukeer.github.io/theme/css/elegant.css" media="screen">
<link rel="stylesheet" type="text/css" href="https://chukeer.github.io/theme/css/custom.css" media="screen">
</head>
<body>
<div id="content-sans-footer">
<div class="navbar navbar-static-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="https://chukeer.github.io/"><span class=site-name>楚客</span></a>
<div class="nav-collapse collapse">
<ul class="nav pull-right top-menu">
<li ><a href="https://chukeer.github.io">Home</a></li>
<li ><a href="https://chukeer.github.io/categories.html">Categories</a></li>
<li ><a href="https://chukeer.github.io/tags.html">Tags</a></li>
<li ><a href="https://chukeer.github.io/archives.html">Archives</a></li>
<li><form class="navbar-search" action="https://chukeer.github.io/search.html" onsubmit="return validateForm(this.elements['q'].value);"> <input type="text" class="search-query" placeholder="Search" name="q" id="tipue_search_input"></form></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span1"></div>
<div class="span10">
<article>
<div class="row-fluid">
<header class="page-header span10 offset2">
<h1><a href="https://chukeer.github.io/wordpress自定义页面显示所有文章列表.html"> wordpress自定义页面显示所有文章列表 </a></h1>
</header>
</div>
<div class="row-fluid">
<div class="span2 table-of-content">
<nav>
<h4>Contents</h4>
<div class="toc">
<ul></ul>
</div>
</nav>
</div>
<div class="span8 article-content">
<p>wordpress博客里有两种类型的网页,一种叫文章,一种叫页面(page),文章就是你发表的每篇博客所在的网页,页面就是你网站导航栏里的那些链接,比如“首页”,“关于我”这样的网页,这种网页的特点是集中展示某一类信息,比如首页展示每篇博客的摘要,“关于我”展示博主简介等等,自定义文章列表毫无疑问也是属于这一类的 </p>
<p>page类型的网页都是根据模板生成的,wordpress默认没有这一类模板,因此需要自己写一个PHP脚本,首先我们找到模板所在的目录,假设你的wordpress所在目录为/var/www,那么模板脚本在/var/www/wp-content/themes/your_theme,其中your_theme是你所使用的主体包,在里面建立一个文件page-allpost.php,内容如下</p>
<div class="highlight"><pre><span></span><span class="cp"><?php</span>
<span class="nx">get_header</span><span class="p">();</span>
<span class="cp">?></span>
<span class="nt"><style</span> <span class="na">type=</span><span class="s">"text/css"</span><span class="nt">></span>
#table-allpost{border-collapse:collapse;}
#table-allpost td,#table-allpost th{border:1px solid #98bf21;padding:3px 7px 2px 7px;text-align:center;}
#table-allpost th{font-size:1.1em;text-align:center;padding-top:5px;padding-bottom:4px;background-color:#A7C942;color:#ffffff;}
#table-allpost td{border:1px dotted #98bf21;}
#table-allpost .td-left{text-align:left;}
<span class="nt"></style></span>
<span class="nt"><head><meta</span> <span class="na">http-equiv=</span><span class="s">"Content-Type"</span> <span class="na">content=</span><span class="s">"text/html; charset=utf-8"</span> <span class="nt">/></head></span>
<span class="nt"><div</span> <span class="na">style=</span><span class="s">"padding-bottom:10px"</span><span class="nt">><strong></span>全部文章<span class="nt"></strong></div></span>
<span class="nt"><div</span> <span class="na">id=</span><span class="s">"page-allpost"</span><span class="nt">></span>
<span class="nt"><table</span> <span class="na">id=</span><span class="s">"table-allpost"</span><span class="nt">></span>
<span class="nt"><tr></span>
<span class="nt"><th><strong></span>编号<span class="nt"></strong></th></span>
<span class="nt"><th><strong></span>发布时间<span class="nt"></strong></th></span>
<span class="nt"><th><strong></span>标题<span class="nt"></strong></th></span>
<span class="nt"></tr></span>
<span class="cp"><?php</span>
<span class="nv">$Count_Posts</span> <span class="o">=</span> <span class="nx">wp_count_posts</span><span class="p">();</span> <span class="nv">$Num_Posts</span> <span class="o">=</span> <span class="nv">$Count_Posts</span><span class="o">-></span><span class="na">publish</span><span class="p">;</span> <span class="nx">query_posts</span><span class="p">(</span><span class="s1">'posts_per_page=-1&caller_get_posts=1'</span> <span class="p">);</span>
<span class="k">while</span> <span class="p">(</span> <span class="nx">have_posts</span><span class="p">()</span> <span class="p">)</span> <span class="o">:</span> <span class="nx">the_post</span><span class="p">();</span>
<span class="nv">$Num</span> <span class="o">=</span> <span class="nb">sprintf</span><span class="p">(</span><span class="s2">"%03d"</span><span class="p">,</span> <span class="nv">$Num_Posts</span><span class="p">);</span>
<span class="k">echo</span> <span class="s1">'<tr>'</span><span class="p">;</span>
<span class="k">echo</span> <span class="s1">'<th>'</span><span class="o">.</span><span class="nv">$Num</span><span class="o">.</span><span class="s1">'</th>'</span><span class="p">;</span>
<span class="k">echo</span> <span class="s1">'<td>'</span><span class="p">;</span><span class="nx">the_time</span><span class="p">(</span><span class="nx">get_option</span><span class="p">(</span> <span class="s1">'date_format'</span> <span class="p">));</span>
<span class="k">echo</span> <span class="s1">'</td><td class="td-left";><a href="'</span><span class="p">;</span> <span class="nx">the_permalink</span><span class="p">();</span>
<span class="k">echo</span> <span class="s1">'" title="'</span><span class="o">.</span><span class="nx">esc_attr</span><span class="p">(</span> <span class="nx">get_the_title</span><span class="p">()</span> <span class="p">)</span><span class="o">.</span><span class="s1">'">'</span><span class="p">;</span> <span class="nx">the_title</span><span class="p">();</span>
<span class="k">echo</span> <span class="s1">'</a></td></tr>'</span><span class="p">;</span>
<span class="nv">$Num_Posts</span><span class="o">--</span><span class="p">;</span>
<span class="k">endwhile</span><span class="p">;</span> <span class="nx">wp_reset_query</span><span class="p">();</span>
<span class="cp">?></span>
<span class="nt"></table></span>
<span class="nt"></div></span>
<span class="cp"><?php</span>
<span class="nx">get_sidebar</span><span class="p">();</span>
<span class="cp">?></span>
<span class="cp"><?php</span>
<span class="nx">get_footer</span><span class="p">();</span>
<span class="cp">?></span>
</pre></div>
<p>保存好之后,再去wordpress后台新建一个页面,注意不是发表文章,而是在仪表盘的“页面”一栏里选择新建页面,标题写“全部文章”,内容为空,别名(固定链接)设置为“<font color="red">allpost</font>”,注意这里的别名必须和之前的脚本名page-allpost.php对应。点击保存,然后刷新你的站点首页,看看导航栏里是不是有了“全部文章”选项,点击进去看看是不是如下效果 </p>
<p><img alt="image" src="http://littlewhite.us/pic/allpost_screenshot.png"/></p>
<hr/>
<aside>
<nav>
<ul class="articles-timeline">
<li class="previous-article">« <a href="https://chukeer.github.io/python网页解析利器——BeautifulSoup.html" title="Previous: python网页解析利器——BeautifulSoup">python网页解析利器——BeautifulSoup</a></li>
<li class="next-article"><a href="https://chukeer.github.io/C++ const知多少.html" title="Next: C++ const知多少">C++ const知多少</a> »</li>
</ul>
</nav>
</aside>
</div>
<section>
<div class="span2" style="float:right;font-size:0.9em;">
<table class="table">
<!-- <time pubdate="pubdate" datetime="2014-03-27T00:00:00+08:00"> 3 27, 2014</time> -->
<tr>
<td>Published</td>
<td><time pubdate="pubdate" datetime="2014-03-27T00:00:00+08:00">2014- 3-27</time></td>
</tr>
<tr>
<td>Category</td>
<td><a class="category-link" href="https://chukeer.github.io/categories.html#skill-ref">Skill</a></td>
</tr>
<tr>
<td>Tags</td>
<td>
<ul class="list-of-tags tags-in-article">
<li><a href="https://chukeer.github.io/tags.html#wordpress-ref">wordpress
<span>1</span>
</a></li>
</ul>
</td>
</tr>
</table>
</div>
</section>
</div>
</article>
</div>
<div class="span1"></div>
</div>
</div>
<div id="push"></div>
</div>
<footer>
<div id="footer">
<ul class="footer-content">
<li class="elegant-power">Powered by <a href="http://getpelican.com/" title="Pelican Home Page">Pelican</a>. Theme: <a href="http://oncrashreboot.com/pelican-elegant" title="Theme Elegant Home Page">Elegant</a> by <a href="http://oncrashreboot.com" title="Talha Mansoor Home Page">Talha Mansoor</a></li>
</ul>
</div>
</footer> <!--
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
-->
<script src="https://chukeer.github.io/theme/js/jquery.min.js"></script>
<script src="https://chukeer.github.io/theme/js/bootstrap.min.js"></script>
<script>
function validateForm(query)
{
return (query.length > 0);
}
</script>
<script>
$("div.article-content table").addClass("table table-hover");
</script>
</body>
<!-- Theme: Elegant built for Pelican
License : http://oncrashreboot.com/pelican-elegant -->
</html>