Home > wordpress > iNove 分类显示友链

iNove 分类显示友链

2009年7月31日 字体大小 发表评论 阅读评论

数据库中分类的存储结构:

可以看出,我们只需要在 terms 表中出去相应数据元组对应的 name 属性就 OK 了。 所以这里需要通过 term_id 和 terms_taxonomy 表联一下,并且将 taxonomy 的值限定为 'link_category'。SQL 如下:

1
2
3
4
5
SELECT T1.name AS name
FROM   $wpdb->terms T1,
       $wpdb->term_taxonomy T2
WHERE  T1.term_id = T2.term_id
AND    T2.taxonomy = 'link_category'

通过以上 SQL 我们可以将所有链接分类的名字找出来,然后做一个循环处理,把链接按照分类查找出来,并置于页面中。

将 links.php 中原代码:

1
2
3
4
5
			<div class="boxcaption"><h3><?php _e('Blogroll', 'inove'); ?></h3></div>
			<div class="box linkcat">
				<ul><?php wp_list_bookmarks('title_li=&categorize=0&orderby=rand'); ?></ul>
				<div class="fixed"></div>
			</div>

替换为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
$linkcats = $wpdb->get_results("SELECT T1.name AS name FROM $wpdb->terms T1, $wpdb->term_taxonomy T2 WHERE T1.term_id = T2.term_id AND T2.taxonomy = 'link_category'");
if($linkcats) : foreach($linkcats as $linkcat) : ?>
	<div class="boxcaption"><h3><?php echo $linkcat->name; ?></h3></div>
	<div class="box linkcat">
		<ul>
			<?php
				$bookmarks = get_bookmarks('orderby=rand&category_name=' . $linkcat->name);
				if ( !empty($bookmarks) ) {
					foreach ($bookmarks as $bookmark) {
						echo '<li><a href="' . $bookmark->link_url . '" title="' . $bookmark->link_description . '">' . $bookmark->link_name . '</a></li>';
					}
				}
			?>
		</ul>
		<div class="fixed"></div>
	</div>
<?php endforeach; endif; ?>

原显示方式:

新显示方式:

分类: wordpress 标签: , 浏览276 次
声明: 本站内容遵循 署名-非商业性使用-禁止演绎 2.5 共享协议. 原创文章转载 请注明转自 守望的麦子

相关文章 随机文章 本月热评 热门标签

    1. 2009年7月31日10:17 | #1

      默认是在原窗口打开……
      需要新窗口打开在 a href="' . $bookmark->link_url . '" 后添加target="_blank" 即可……

      [回复]

      CHINA CHINA Internet Explorer Internet Explorer 6.0 Windows Windows XP
    2. 2009年8月3日15:04 | #2

      分かりません。(- -!)

      [回复]

      CHINA CHINA Internet Explorer Internet Explorer 6.0 Windows Windows XP
    3. 2010年9月28日23:33 | #3

      做的不错,特来踩踩,学习了。

      [回复]

      CHINA CHINA Internet Explorer Internet Explorer 8.0 Windows Windows 7
    1. 本文目前尚无任何 trackbacks 和 pingbacks.