物件裡的TAG
<?php
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo $tag->name . ' ';
}
}
?>
列出所有TAG
<?php
$tags = get_tags();
if ($tags) {
foreach ($tags as $tag) {
echo '<li class="name ">' . $tag->name.'</li> ';
}
}
?>
2014年5月29日 星期四
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 }?>
$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日 星期二
如果the_content(),沒有出現任何output
請服用
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>.
//the_content();
<?php endwhile; ?>
<?php endif; ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>.
//the_content();
<?php endwhile; ?>
<?php endif; ?>
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]是取第一個
<?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年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
?>
2012年8月17日 星期五
wordpress 後台更改選項或自製後台
//更改選單位置
function custom_menu_order($menu_order) {
if (!$menu_order) return true;
return array(
'index.php',
'edit.php',
'edit.php?post_type=services',
'edit.php?post_type=work',
'edit.php?post_type=page',
);
}
add_filter('custom_menu_order', 'custom_menu_order');
add_filter('menu_order', 'custom_menu_order');
//更改底下說明
function change_footer_content() {
echo '感謝您使用我們的系統. 如果您需要請聯繫我們, 很好設計(studio.goods@gmail.com).';
}
add_filter('admin_footer_text', 'change_footer_content');
//刪除不必要後台功能,但用了更改分類會中猴
/*function remove_menu_pages() {
remove_menu_page('link-manager.php');
remove_menu_page('edit-comments.php');
}
add_action( 'admin_init', 'remove_menu_pages' );*/
wordpress 更多欄位請愛用Custom Fields(plugin)讓你無敵
wordpress 需要更多欄位請愛用Custom Fields(plugin)讓你無敵
例如
你需要很多複選框checkbox
你需要欄位可以選顏色 他就有colorpick
還有一個很賊的repeat fields可以再一則文章裡
上重複性的資料~~~多麼棒啊~但這要25美金~~我還沒買
例如
你需要很多複選框checkbox
你需要欄位可以選顏色 他就有colorpick
還有一個很賊的repeat fields可以再一則文章裡
上重複性的資料~~~多麼棒啊~但這要25美金~~我還沒買
wordpress 如果有用post_type 請愛用archive.php
wordpress 如果有用post_type 請愛用archive.php
而若使用post_type ,網址就是
xxx.com.tw/post_type的名稱/
xxx.com.tw/post_type的名稱/page/2
就不會跟
xxx.com.tw/ category /page/2
搞混了
而若使用post_type ,網址就是
xxx.com.tw/post_type的名稱/
xxx.com.tw/post_type的名稱/page/2
就不會跟
xxx.com.tw/ category /page/2
搞混了
wordpress WP_Query不同post type選擇內容
<?php
$args = array(
'post_type' =>'work',
'category_name' => $myCat_slug[$i],
'order' => 'ASC'
);
$listQuery = new WP_Query( $args );
?>
<?php
query_posts('post_type=post');
?>
2012年7月19日 星期四
wordpress取得縮圖網址SRC(thumbnail)
<?php
$domsxe = simplexml_load_string(get_the_post_thumbnail());
$thumbnailsrc = $domsxe->attributes()->src;
?>
<?php if (has_post_thumbnail()){ ?>
<?php }?>
2012年6月12日 星期二
wordpress-plugin:滑過展開按鈕群Accordion Menu
這配合wordpress的選單級次選單的外掛也太好用了吧!!!
jQuery Vertical Accordion Menu
(滑過展開按鈕群)
jQuery Vertical Accordion Menu
(滑過展開按鈕群)
2012年6月11日 星期一
wordpress enter輸入和br配合法
1.安裝TinyMCE advance
2.使用<?php echo nl2br(get_the_content()); ?>
3.可以正常使用enter(大斷) 和shift enter(小斷)
2.使用<?php echo nl2br(get_the_content()); ?>
3.可以正常使用enter(大斷) 和shift enter(小斷)
2012年5月16日 星期三
wordpress連續兩個query_post
要先new一個WP_Query出來使用
以下範例
<?php
// 僅顯示標籤帶有cooking的文章
$videoQuery = new WP_Query( 'tag=video' );
?>
<?php
$args = array(
'category_name' => 'frash_news');
query_posts($args);
?>
<?php while ($videoQuery->have_posts()) : $videoQuery->the_post(); ?>
//這裡使用吧!!!!
<?php endwhile; ?>
2012年5月15日 星期二
wordpress上使用jquery.masonry
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery-1.7.1.min.js"></script>
<?php wp_head(); ?>
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery.masonry.min.js"></script>
注意
jquery主體要在最上面
中間要是wp_head()
下方才能載入jquery.masonry.min.js
$(function(){
$('#news_container').masonry({
// options
itemSelector : '.news_col',
columnWidth : 295
});
});
295是news_col這物件的寬+左右padding+左右margin
.news_col{
float:left;
background:#EFEFEF;
margin-bottom:15px;
margin-left:15px;
padding-left:10px;
padding-right:10px;
width:auto;
width:260px;
2012年5月9日 星期三
2012年4月30日 星期一
wordpress 下其他路徑使用內建functions
假設在theme/library/functions/下
想使用get_bloginfo( 'admin_email' );//等等之程式
請使用作者愚蠢的做法如下
require( $_SERVER['DOCUMENT_ROOT'].'/wp-load.php' ); //目前是用這愚蠢的招式
//然後就可以使用get_bloginfo();了
想使用get_bloginfo( 'admin_email' );//等等之程式
請使用作者愚蠢的做法如下
require( $_SERVER['DOCUMENT_ROOT'].'/wp-load.php' ); //目前是用這愚蠢的招式
//然後就可以使用get_bloginfo();了
2012年2月22日 星期三
自訂義英文標題欄位在編輯文章時出現
//找到佈景裡的function.php
//加上底下
//Custom EnglishTitle Widget
add_action('admin_menu', 'custom_EnTitle_hooks');
add_action('save_post', 'save_custom_EnTitle');
add_action('wp_head','insert_custom_EnTitle');
function custom_EnTitle_hooks() {
add_meta_box('custom_EnTitle', '自訂英文標題', 'custom_EnTitle_input', 'post', 'normal', 'high');
add_meta_box('custom_EnTitle', '自訂英文標題', 'custom_EnTitle_input', 'page', 'normal', 'high');
}
function custom_EnTitle_input() {
global $post;
echo '';
echo '';
}
function save_custom_EnTitle($post_id) {
if (!wp_verify_nonce($_POST['custom_EnTitle_noncename'], 'custom-EnTitle')) return $post_id;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
$custom_EnTitle = $_POST['custom_EnTitle'];
update_post_meta($post_id, '_custom_EnTitle', $custom_EnTitle);
}
function insert_custom_EnTitle() {
if (is_page() || is_single()) {
if (have_posts()) : while (have_posts()) : the_post();
endwhile; endif;
rewind_posts();
}
}
//在要使用的地方加上
//加上底下
//Custom EnglishTitle Widget
add_action('admin_menu', 'custom_EnTitle_hooks');
add_action('save_post', 'save_custom_EnTitle');
add_action('wp_head','insert_custom_EnTitle');
function custom_EnTitle_hooks() {
add_meta_box('custom_EnTitle', '自訂英文標題', 'custom_EnTitle_input', 'post', 'normal', 'high');
add_meta_box('custom_EnTitle', '自訂英文標題', 'custom_EnTitle_input', 'page', 'normal', 'high');
}
function custom_EnTitle_input() {
global $post;
echo '';
echo '';
}
function save_custom_EnTitle($post_id) {
if (!wp_verify_nonce($_POST['custom_EnTitle_noncename'], 'custom-EnTitle')) return $post_id;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
$custom_EnTitle = $_POST['custom_EnTitle'];
update_post_meta($post_id, '_custom_EnTitle', $custom_EnTitle);
}
function insert_custom_EnTitle() {
if (is_page() || is_single()) {
if (have_posts()) : while (have_posts()) : the_post();
endwhile; endif;
rewind_posts();
}
}
//在要使用的地方加上
2012年2月12日 星期日
size of 33554432
size of 33554432 bytes exhausted wp-admin/includes/media.php on line 502
改空間商的php.ini
memory_limit = 16M(系統預設值) 32M 72M
或是在wp-config.php裡新增一條
define('WP_MEMORY_LIMIT', '64M');
任何位置
改空間商的php.ini
memory_limit = 16M(系統預設值) 32M 72M
或是在wp-config.php裡新增一條
define('WP_MEMORY_LIMIT', '64M');
任何位置
訂閱:
文章 (Atom)