中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

WordPress父分類調(diào)用子分類名稱和文章列表

2018-11-02    來源:學做網(wǎng)站論壇

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用

在之前的網(wǎng)站制作文章中講到了wordpress如何調(diào)用當前分類下面的子分類的方法,但這種方法只能調(diào)用出子分類的名稱,無法去調(diào)用出子分類下面的文章列表。(相關(guān)閱讀:wordpress調(diào)用分類下的二級分類名)

在做網(wǎng)站時,為了實現(xiàn)某種需要,我們要同時調(diào)用出分類的名稱和文章列表,以達到如下圖的效果。
wordpress同時調(diào)用子分類的名稱和文章列表

為達到這樣的功能,我們需要判斷一下當前分類包含的二級子分類,然后調(diào)用出所有的二級分類ID,再通過ID去調(diào)用子分類的名稱和子分類下面的文章列表。代碼如下:

<?php
global $cat;
$cats = get_categories(array(
'child_of' => $cat,
'parent' => $cat,
'hide_empty' => 0
));
$c = get_category($cat);
if(empty($cats)){
?>
<div class="item">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post">
<h2><a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p><?php the_excerpt(); ?></p>
<p><a href="<?php the_permalink(); ?>">more >></a></p>
<div class="meta"><?php the_time('Y-m-d'); ?> | 標簽: <?php the_tags('', ' , ', ''); ?></div>
</div>
<?php endwhile; ?>
<?php else: ?>
<div class="post"><p>暫無文章</p></div>
<?php endif; ?>
</div>
<div class="navigation">
<span class="alignleft"><?php next_posts_link('&laquo; Older posts') ?></span>
<span class="alignright"><?php previous_posts_link('Newer posts &raquo;') ?></span>
</div>
<?php
}else{
foreach($cats as $the_cat){
$posts = get_posts(array(
'category' => $the_cat->cat_ID,
'numberposts' => 10,
));
if(!empty($posts)){
echo '
<div class="item cat_item">
<div class="item_title"><h2><a title="'
.$the_cat->name.'" href="'.get_category_link($the_cat).'">'.$the_cat->name.'</a></h2></div>
<ul class="box_list">'
;
foreach($posts as $post){
echo '<li><span class="alignright">'.mysql2date('Y-m-d', $post->post_date).'</span>
<a title="'
.$post->post_title.'" href="'.get_permalink($post->ID).'">'.$post->post_title.'</a></li>';
}
echo '</ul>
</div>'
;
}
}
}
?>

通過對以上的代碼進行改編輯,結(jié)合WordPress分類目錄添加縮略圖上傳功能,可以制作出以下的網(wǎng)頁效果。

wordpress同時調(diào)用子分類的名稱和文章列表擴展

代碼如下:(代碼里的分類ID和圖片的地址自行修改)


<?php
global $cat;
$cats = get_categories(array(
'child_of' => $cat,
'parent' => $cat,
'hide_empty' => 0
));
$c = get_category($cat);
if(empty($cats)){
?>
<?php
}else{
foreach($cats as $the_cat){
$posts = get_posts(array(
'category' => $the_cat->cat_ID,
'numberposts' => 6,
));
if(!empty($posts)){
echo '
<tr bgcolor="#006699" align="center">
<td colspan="2" height="30" align="left"><font size="2" color="#ffffff">&gt;&gt;&gt; '
.$the_cat->name.'</font></td>
</tr>
<tr bgcolor="#edf1f5">
<td width="40%" height="25" align="center"><a title="'
.$the_cat->name.'" href="'.get_category_link($the_cat).'" target="_blank"><img alt="'.$the_cat->name.'" src="https://www.xuewangzhan.com/wp-content/themes/jcw/images/'.$the_cat->cat_ID.'.jpg" width="250"></a></td>
<td width="60%">
<table cellspacing="0" cellpadding="0" border="0">
<tbody>'
;
foreach($posts as $post){
echo '

<tr height="22">
<td width="80%"><a href="'
.get_permalink($post->ID).'" target="_blank">'.$post->post_title.'</a></td>
<td width="20%">'
.mysql2date('Y-m-d', $post->post_date).'</td>
</tr> '
;
}
echo '
<tr height="1">
<td colspan="2" width="100%"><hr style="border:1px #cccccc dotted" size="1" noshade="noshade"></td>
</tr>
<tr>
<td colspan="2" width="100%"><a title="'
.$the_cat->name.'" href="'.get_category_link($the_cat).'" target="_blank"><img src="https://www.xuewangzhan.com/wp-content/themes/jcw/images/a0.gif" width="200" height="46" border="0"></a></td>
</tr>
</tbody></table>
</td></tr>
<tr bgcolor="#ffffff">
<td height="5" align="center"></td>
<td></td></tr>'
;
}
}
}
?>

標簽: Mysql 代碼 網(wǎng)站制作

版權(quán)申明:本站文章部分自網(wǎng)絡,如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:wordpress如何自動給圖片加ALT信息、標簽云等函數(shù)應用匯總

下一篇:wordpress下拉菜單,二級菜單制作