以下,都是我在开发网站过程中用过的函数。
获取上传文件的绝对路径和文件名。
get_attached_file()
1 2 |
$fullsize_path = get_attached_file( $attachment_id ); // Full path $filename_only = basename( get_attached_file( $attachment_id ) ); // Just the file name |
获取页面标题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php if(is_category()) { echo single_cat_title( "", false ); } else if(is_tag()) { echo single_tag_title( "", false ); } else if(is_tax()) { echo single_term_title( "", false ); } else if(is_post_type_archive()) { echo post_type_archive_title( '', false ); } else if ( is_day() ) { echo 'Daily Archives: '.get_the_date(); } else if ( is_month() ) { echo 'Monthly Archives: '.get_the_date( 'F Y' ); } else if ( is_year() ) { echo 'Yearly Archives: '.get_the_date( 'Y' ); } else if(is_search()) { echo esc_attr__('Search: ', 'ATIV'), get_search_query(); } else { echo get_the_title(); } ?> |
分类名
1 2 3 4 5 6 7 8 |
<?php if ( is_tax() ) : ?> <?php printf( __( '%s', 'wordpress' ), single_term_title('', false ) ); ?> <?php endif; ?> <?php single_cat_title("", true); ?> <?php single_term_title("", true); ?> <?php echo get_cat_name ( $cat_id ); ?> by id get_the_archive_title() |
分类链接
1 2 3 |
get_term_link($cat_id, 'taxonomy' ) by id get_category_link( $category_id ) get_tag_link($tag_id) |
输出post type的name
1 2 3 |
<?php $type_name = get_post_type_object('product'); echo $type_name->labels->name; ?> |
输出链接
1 2 |
post_permalink('#page_id') by page id get_permalink(); |