wordpress获取封面_PHP:获取WordPress发布类别

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()函数只是其中之一。

翻译自: https://davidwalsh.name/php-wordpress-post-categories

wordpress获取封面

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值