2013年9月4日 星期三

wordpress 下一篇 上一篇 寫法

<?php
                        $next_post = get_next_post(ture);
                        $prev_post = get_previous_post(ture);

                        if (!empty( $prev_post )){?>
                        <div class="next-article"><a href="<?php echo get_permalink( $prev_post->ID ); ?>"><span>Next</span><i class="icon-nex-article-arr"></i></a></div>

                        <?php }else{?>
                        <?php
                             //目前分類的名稱
                            $category = get_the_category();
                            $args = array(
                            'post_type' => 'post',
                            'showposts' => 1,
                            'cat' => $category[0]->term_id
                             );
                            $top_query = new WP_Query($args); ?>
                            <?php while($top_query->have_posts()) : $top_query->the_post(); ?>

                            <div class="next-article"><a href="<?php echo get_permalink(get_the_ID()); ?>"><span>Next</span><i class="icon-nex-article-arr"></i></a></div>

                            <?php endwhile; ?>
                            <?php wp_reset_postdata();?>                      
                        <?php }?>

2013年8月27日 星期二

2013年8月26日 星期一

目前的CATEGORY NAME(只勾選一個的話)

//目前分類的名稱
<?php
$category = get_the_category();
echo $category[0]->cat_name;
?>

//目前分類的母分類名稱

<?php
   $category=get_the_category();
   $parent_cat= $category[0]->category_parent;
   $thisCat= get_category($parent_cat,false);
             echo $thisCat->name;
?>

//以上測試過 適用於該產品分類只屬於一個並沒有同時屬於第二個分類,因為[0]是取第一個

2013年8月22日 星期四

list category



如果不愛<?php wp_list_categories( $args ); ?>

請服用以下

<?php $args=array(

'orderby' => 'name',

'order' => 'ASC',

'show_count' => true,

'title_li' => '',

'child_of' => 5,

);

$categories = get_categories($args);

foreach($categories as $category) {

$output = '<li>';
$output .= '<a href="' . get_category_link($category->term_id) . '">' . $category->name . '</a></li>';
echo $output;
}
?>

2013年6月27日 星期四

以往可以用加上 -webkit-text-size-adjust : none 解決,但新版 Chrome 已經將 -webkit-text-size-adjust 支援移除。所以必須改以 -webkit-transform : scale( ... ) 處理, scale 中的數字為要設定的字型大小除以 12px ,例如 9px 就是 9 / 12 = 0.75 。請注意 display : inline 無法 transform ,請視情況加上 display : inline-block ,且目前看來 transform 會破壞字的間距:

-webkit-transform : scale(0.75);


from http://blog.xuite.net/vexed/tech/59449347-Chrome+font-size+%E5%B0%8F%E6%96%BC+12px

2013年6月19日 星期三

解決fadeIn與fadeOut在mouseover與out的動作後會持續重複動畫

$(".navleng").mouseover(function() { //When trigger is clicked...
 
      $(this).find(".head_subnav").fadeIn(300).slideDown('fast'); //Drop down the subnav on click

      $(this).hover(function() {
      }, function(){
          $(this).find(".head_subnav").stop(true).fadeOut(300).slideUp('fast');
      });  
 
  });

在hover的相反裡加入.stop(true)即可,然後剛滑入時的fadeIn不要加。

2013年5月2日 星期四

mysql中如何篩選出非重複資料

請參考
http://xcy.17cha8.cn/read.php/441.htm



使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供有distinct这个关键字来过滤掉多余的重复记录只保留一条,但往往只用它来返回不重复记录的条数,而不是用它来返回不重记录的所有值。其原因是distinct只能返回它的目标字段,而无法返回其它字段
下面先来看看例子:
   table
   id name
   1 a
   2 b
   3 c
   4 c
   5 b
比如我想用一条语句查询得到name不重复的所有数据,那就必须使用distinct去掉多余的重复记录。
select distinct name from table
得到的结果是:
   name
   a
   b
   c
好像达到效果了,可是,我想要得到的是id值呢?改一下查询语句吧:
select distinct name, id from table
结果会是:
   id name
   1 a
   2 b
   3 c
   4 c
   5 b
试了半天,也不行,最后在mysql手册里找到一个用法,
用group_concat(distinct name)配合group by name实现了我所需要的功能 5.0才支持的.
突然灵机一闪,既然可以使用group_concat函数,那其它函数能行吗?
赶紧用count函数一试,成功, 现在将完整语句放出:
select *, count(distinct name) from table group by name
结果:
   id name count(distinct name)
   1 a 1
   2 b 1
   3 c 1
再顺便说一句,group by 必须放在 order by 和 limit之前,不然会报错。。。OK了

2013年1月14日 星期一

scrolltop chrome firefox某一項無作用


原本這樣用
$('body').stop().delay(800).stop().animate({
scrollTop:0
}, 800);
但常常firefox無作用
於是加入下面html就可
$('body,html').stop().delay(800).stop().animate({
scrollTop:0
}, 800);

2013年1月10日 星期四

wordpress取得目前POST文章的路徑名稱 或是文章 ID


<?php
$pagename = get_query_var('pagename');
if ( !$pagename && $id > 0 ) {
// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
$post = $wp_query->get_queried_object();
 $pagename = $post->post_name;//目前文章 名稱
}
 $postid = get_the_ID();//目前文章ID

?>