wordpress获取封面
When I put together my WordPress theme, I wanted to put all of my post categories in the footer of the page and in two column format. Obviously there isn't a built-in WordPress function that will format the categories the way I wanted to so it was up to me to do all the work. Here's how I was a able to put my categories in two column format.
当我整理WordPress主题时,我想将我所有的帖子类别都放在页面的页脚中,并以两列的格式。 显然,没有内置的WordPress功能可以按照我想要的方式格式化类别,因此,由我自己来完成所有工作。 这就是我能够将类别分为两列的方式。
PHP代码 (The PHP Code)
<h5>Discussion Topics</h5>
<?php
/* BUILD THE CATEGORY LIST */
$categories = get_categories(array('type' => 'post','child_of' => 0,'orderby' => 'name','order' => 'ASC','hide_empty' => true));
$category_count = 0; $category_col = 1;
foreach($categories as $catty)
{
$category_count++;
${'category_list_'.$category_col}[] = array('name'=>$catty->cat_name,'url'=>$catty->category_nicename);
if(floor($category_count) == (count($categories) / 2)) { $category_col = 2; }
}
?>
<div id="col-1">
<?php foreach($category_list_1 as $item) { echo '<a href="/sugar/',$item['url'],'">',$item['name'],'</a>'; } ?>
</div>
<div id="col-2">
<?php foreach($category_list_2 as $item) { echo '<a href="/sugar/',$item['url'],'">',$item['name'],'</a>'; } ?>
</div>
Easy, right? WordPress is a magnificent tool with plenty of helpful functions -- the get_categories() function is only one of them.
容易吧? WordPress是一个功能强大的工具,具有许多有用的功能-get_categories()函数只是其中之一。
wordpress获取封面