Last active
December 20, 2015 01:49
-
-
Save WenLiangTseng/6051611 to your computer and use it in GitHub Desktop.
讓Wordpress顯示出所有目錄的最新5篇文章
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#page-not-found dl { | |
width: 200px; | |
float: left; | |
padding: 0 18px 0 0; | |
height: 250px; | |
} | |
#page-not-found dt { | |
font-weight: bold; | |
font-size: 1.1em; | |
padding: 10px 0; | |
} | |
#page-not-found dt a { | |
color: #b0bf32; | |
} | |
#page-not-found dd.view-all { | |
border-top: 1px solid #c9c9c9; | |
font-size: 0.9em; | |
margin: 5px 0; | |
padding: 2px 0 0; | |
text-align: right; | |
} | |
#page-not-found dd.view-all a { | |
color: #999; | |
} | |
.page-end { | |
clear: both; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//WordPress PHP Code | |
<div id="page-not-found" class="post-page"> | |
<?php | |
$cat_args = array( | |
'orderby' => 'name', | |
'order' => 'ASC', | |
'child_of' => 0 | |
); | |
$categories = get_categories($cat_args); | |
foreach($categories as $category) { | |
echo '<dl>'; | |
echo '<dt> <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></dt>'; | |
$post_args = array( | |
'numberposts' => 5, | |
'category' => $category->term_id | |
); | |
$posts = get_posts($post_args); | |
foreach($posts as $post) { | |
?> | |
<dd><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></dd> | |
<?php | |
} | |
echo '<dd class="view-all"> <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>View all posts in ' . $category->name.'</a></dd>'; | |
echo '</dl>'; | |
} | |
?> | |
<div class="page-end"><!-- --></div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment