外贸营销推广

【WordPress】WordPress标签大全—Michael王朝

所属分类:Wordpress   1,354 次浏览


网站名称 <?php bloginfo(‘name’); ?>
网站url <?php bloginfo(‘url’); ?>
single标题调用 <?php echo trim(get_the_title()); ?>
favicon图标 <link rel=”shortcut icon” href=”<?php bloginfo(‘url’); ?>/favicon.ico”>
样式文件路径调用 <?php bloginfo(‘template_url’); ?>/style/style.css
wordpress头部信息调用 <?php wp_head(); ?>
顶部导航调用

(需要配合后台菜单设置)

  <?php if ( function_exists( ‘wp_nav_menu’ ) ){

wp_nav_menu( array( ‘theme_location’ => ‘top-links’, ‘container_id’ => ‘topLinks’, ‘fallback_cb’=>’toplinks’) );

}else{

toplinks();

}?>

调用头部文件 <?php get_header(); ?>
调用footer底部文件 <?php get_footer(); ?>
调用侧边栏(系统默认) <?php get_sidebar(); ?>
调用评论 <?php comments_template();?>
友情链接 add_action(‘admin_init’, ‘wpjam_blogroll_settings_api_init’);

function wpjam_blogroll_settings_api_init() {

add_settings_field(‘wpjam_blogroll_setting’, ‘友情链接’, ‘wpjam_blogroll_setting_callback_function’, ‘reading’);

register_setting(‘reading’,’wpjam_blogroll_setting’);

}

function wpjam_blogroll_setting_callback_function() {

echo ‘<textarea name=”wpjam_blogroll_setting” rows=”10″ cols=”50″ id=”wpjam_blogroll_setting” class=”large-text code”>’ . get_option(‘wpjam_blogroll_setting’) . ‘</textarea>’;

}

function wpjam_blogroll(){

$wpjam_blogroll_setting =  get_option(‘wpjam_blogroll_setting’);

if($wpjam_blogroll_setting){

$wpjam_blogrolls = explode(“\n”, $wpjam_blogroll_setting);

foreach ($wpjam_blogrolls as $wpjam_blogroll) {

$wpjam_blogroll = explode(“|”, $wpjam_blogroll );

echo ‘ | <a target=”_blank” href=”‘.trim($wpjam_blogroll[0]).'” title=”‘.esc_attr(trim($wpjam_blogroll[1])).'”>’.trim($wpjam_blogroll[1]).'</a>’;

}

}

}

然后就可以在 WordPress 后台 > 设置 > 阅读 界面,就有一个友情链接添加的输入框。按照 链接 |标题 的方式输入所有的友情链接

https://www.seowangchao.com | 王朝

模板调用标签:

<?php if (function_exists(wpjam_blogroll)) wpjam_blogroll();?>

调用缩略图(配合functions) 在functions中加入:

function emtx_auto_thumbnail($pID,$thumb=’thumbnail’) {

$blogimg = FALSE;

if (has_post_thumbnail()) {// 判断该文章是否已经设置了”特色图像”,如果有则直接显示该特色图像的缩略图

$blogimg = wp_get_attachment_image_src(get_post_thumbnail_id($pID),$thumb);

$blogimg = $blogimg[0];

} elseif ($postimages = get_children(“post_parent=$pID&post_type=attachment&post_mime_type=image&numberposts=0”)) {//如果文章没有设置特色图像,则查找文章内是否有上传图片

foreach($postimages as $postimage) {

$blogimg = wp_get_attachment_image_src($postimage->ID, $thumb);

$blogimg = $blogimg[0];

}

} elseif (preg_match(‘/<img [^>]*src=[“|\’]([^”|\’]+)/i’, get_the_content(), $match) != FALSE) {

$blogimg = $match[1];

}

if($blogimg) {

$blogimg = ‘<a href=”‘. get_permalink().'”><img src=”‘.$blogimg.'” alt=”‘.get_the_title().'” class=”alignleft wp-post-image” /></a>’;

}

return $blogimg;

 

}

 

模板文件中调用:

<?php if(emtx_auto_thumbnail($post->ID) ) { echo emtx_auto_thumbnail($post->ID);} ?>

另外一种缩略图 在function.php中插入代码

add_theme_support(‘post-thumbnails’);

 

在要显示的 地方加入代码

<?php the_post_thumbnail(); ?>

调用栏目描述 <?php echo category_description(); ?>
调用栏目描述(去除P标签) <meta name=”description” content=”<?php if (is_home()) {echo (‘ithink是一个….(省略)’);} elseif (is_single()) { echo mb_strimwidth(strip_tags(apply_filters(‘the_content’,$post->post_content)),0,220);} elseif (is_category()){echo trim(strip_tags(category_description()));} ?>” />
调用文章指定字数描述 <?php echo mb_strimwidth(strip_tags(apply_filters(‘the_content’, $post->post_content)), 0, 147,”……”); ?>
面包屑调用(category)  <a href=<?php echo get_option(‘home’); ?>><?php bloginfo(‘name’); ?></a>><?php the_category(‘, ‘) ?>
面包屑调用(single

 <a href=<?php echo get_option(‘home’); ?>><?php bloginfo(‘name’); ?></a>><?php the_category(‘, ‘) ?>><?php the_title(); ?>
面包屑导航 function dimox_breadcrumbs() {

$delimiter = ‘»’;

$name = ‘Home’; //text for the ‘Home’ link

$currentBefore = ‘<span>’;

$currentAfter = ‘</span>’;

 

if ( !is_home() && !is_front_page() || is_paged() ) {

 

echo ‘<div id=”crumbs”>’;

 

global $post;

$home = get_bloginfo(‘url’);

echo “<a href=\”$home\”>Home</a> ” . $delimiter . ‘ ‘;

 

if ( is_category() ) {

global $wp_query;

$cat_obj = $wp_query->get_queried_object();

$thisCat = $cat_obj->term_id;

$thisCat = get_category($thisCat);

$parentCat = get_category($thisCat->parent);

if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ‘ ‘ . $delimiter . ‘ ‘));

echo $currentBefore;

single_cat_title();

echo $currentAfter;

 

} elseif ( is_day() ) {

echo ” . get_the_time(‘Y’) . ‘ ‘ . $delimiter . ‘ ‘;

echo ” . get_the_time(‘F’) . ‘ ‘ . $delimiter . ‘ ‘;

echo $currentBefore . get_the_time(‘d’) . $currentAfter;

 

} elseif ( is_month() ) {

echo ” . get_the_time(‘Y’) . ‘ ‘ . $delimiter . ‘ ‘;

echo $currentBefore . get_the_time(‘F’) . $currentAfter;

 

} elseif ( is_year() ) {

echo $currentBefore . get_the_time(‘Y’) . $currentAfter;

 

} elseif ( is_single() ) {

$cat = get_the_category(); $cat = $cat[0];

echo get_category_parents($cat, TRUE, ‘ ‘ . $delimiter . ‘ ‘);

echo $currentBefore;

the_title();

echo $currentAfter;

 

} elseif ( is_page() && !$post->post_parent ) {

echo $currentBefore;

the_title();

echo $currentAfter;

 

} elseif ( is_page() && $post->post_parent ) {

$parent_id  = $post->post_parent;

$breadcrumbs = array();

while ($parent_id) {

$page = get_page($parent_id);

$breadcrumbs[] = ” . get_the_title($page->ID) . ”;

$parent_id  = $page->post_parent;

}

$breadcrumbs = array_reverse($breadcrumbs);

foreach ($breadcrumbs as $crumb) echo $crumb . ‘ ‘ . $delimiter . ‘ ‘;

echo $currentBefore;

the_title();

echo $currentAfter;

 

} elseif ( is_search() ) {

echo $currentBefore . ‘Search results for ” . get_search_query() . ”’ . $currentAfter;

 

} elseif ( is_tag() ) {

echo $currentBefore . ‘Posts tagged ”;

single_tag_title();

echo ”’ . $currentAfter;

 

} elseif ( is_author() ) {

global $author;

$userdata = get_userdata($author);

echo $currentBefore . ‘Articles posted by ‘ . $userdata->display_name . $currentAfter;

 

} elseif ( is_404() ) {

echo $currentBefore . ‘Error 404’ . $currentAfter;

}

 

if ( get_query_var(‘paged’) ) {

if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ‘ (‘;

echo __(‘Page’) . ‘ ‘ . get_query_var(‘paged’);

if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ‘)’;

}

 

echo ‘</div>’;

 

}

}

页面调用:

<div><?php if (function_exists(‘dimox_breadcrumbs’)) dimox_breadcrumbs(); ?> </div>

调用某个指定ID分类 <a href=”<?php echo get_category_link(1)?>” title='<?php echo get_category(1)->name?>’><?php echo get_category(1)->name?></a>
调用某个指定pages <a href=”<?php echo get_page_link(1)?>” title='<?php echo get_page(1)->name?>’><?php echo get_page(1)->name?></a>
调用文章发布时间 <?php the_time(‘y-m-j’) ?>
调用描述 <?php echo mb_strimwidth(strip_tags(apply_filters(‘the_content’, $post->post_content)), 0, 250,”……”); ?>
调用正文下部的摘要内容 <?php the_excerpt();?>
调用当前栏目名称+链接 <?php the_category(); ?>
只调用当前栏目名称 <?php single_cat_title(); ?>
在single页面调用当前栏目名称(不带链接)  

<?php

foreach((get_the_category()) as $category)

{

echo $category->cat_name;

}

?>

————————————————————————

<?php

$category = get_the_category();

echo $category[0]->cat_name;

?>

————————————————————————

<?php $thiscat = get_category($cat); echo $thiscat ->name;?>

调用指定ID分类的文章列表 <ul>

<?php query_posts(‘cat=1&posts_per_page=5’); while(have_posts()): the_post(); ?>

<li><a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a></li>

<?php endwhile; wp_reset_query(); ?>

</ul>

调用指定id分类的描述 <?php echo category_description(6); ?> (调用id=6的分类的描述)
标签云 <?php wp_tag_cloud( $args ); ?>
single页面配合采集使用  <?php

if (have_posts()) :

while (have_posts()) : the_post(); ?>

<h1><?php the_title(); ?></h1>

<div class=”caiji-box”>

<?php if(!in_category(‘news’)){?>

<?php the_content(); ?>

<?php }else{ ?>

<?php

$datatitle=get_the_excerpt();

$datadesc =get_the_content();

$title=explode(‘::::::’,$datatitle);

$desc=explode(‘::::::’,$datadesc);

$title_num=count($title)-2;

for($i=0;$i<=$title_num;$i++){

echo ‘<div class=”caiji-box”>’;

echo ‘<div class=”caiji-img”><a href=”javascript:void(0)” onclick=”openZoosUrl()”><img src=”http://localhost/wp2/rand/’.rand(1,99).’.jpg” /></a></div>’;

echo ‘<div class=”caiji-text”>’;

echo “<h3>”.$title[$i].”</h3>”;

echo “<p>”.$desc[$i].”</p>”;

echo ‘</div>’;

echo ‘<div class=”clear”></div>’;

echo ‘</div>’;

}

?>

<?php }?>

<?php endwhile; else: ?>

<p>Sorry, but you are looking for something that isn’t here.</p>

<?php endif; ?>

调用文章标题和链接 <?php the_title(); ?>

<?php the_permalink() ?>

page页面内容调用 <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<?php the_content(__(‘(more…)’)); ?>

<?php endwhile; else: ?>

<p><?php _e(‘Sorry, no posts matched your criteria.’); ?></p>

<?php endif; ?>

文章列表页面的调用

(category.php)

<ul>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<li><h3><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></h3>

<?php echo mb_strimwidth(strip_tags(apply_filters(‘the_content’, $post->post_content)), 0, 250,”……”); ?>

<span><a href=”<?php the_permalink();?>” title=”<?php the_title(); ?>”>详情…</a></span>

</li>

<?php endwhile; ?>

<?php endif; ?>

</ul>

调用指定文章 <?php query_posts(‘p=1’); ?>//p=文章ID

<?php while (have_posts()) : the_post(); ?>

<?php the_content(); ?>

<?php the_permalink() ?>

<?php the_excerpt(); ?>

<?php the_title(); ?>

<?php the_category(); ?>

<?php the_ID(); ?>

<?php the_post_thumbnail(); ?>

<?php the_tags(); ?>

<?php the_author(); ?>

<?php the_author_link(); ?>

<?php the_time(); ?>

<?php endwhile;wp_reset_query();?>

调用置顶文章   <ul>

<?php

$sticky = get_option(‘sticky_posts’);

rsort( $sticky );//对数组逆向排序,即大ID在前

$sticky = array_slice( $sticky, 0, 5);//输出置顶文章数,请修改5,0不要动,如果需要全部置顶文章输出,可以把这句注释掉

query_posts( array( ‘post__in’ => $sticky, ‘caller_get_posts’ => 2 ) );

if (have_posts()) :while (have_posts()) : the_post();

?>

<li><?php the_post_thumbnail(‘index’, array( ‘class’ => ‘style’,’title’ => get_the_title(),’alt’ => get_the_title())); ?></li>

<?php endwhile; endif; ?>

</ul>

<ul>

<?php

$sticky = get_option(‘sticky_posts’);

rsort( $sticky );

query_posts( array(‘post__in’ => $sticky, ‘caller_get_posts’ => 2,’cat’=>59 ) );

if (have_posts()) :while (have_posts()) : the_post();

?>

<li><?php the_post_thumbnail(‘index’, array( ‘class’ => ‘style’,’title’ => get_the_title(),’alt’ => get_the_title())); ?></li>

<?php endwhile; endif;

wp_reset_query(); ?>

</ul>

判断category模板 <?php

if ( is_category(array(3,4,5)) ){

include(TEMPLATEPATH .’/category-pro.php’);

}

else if( is_category(1) ){

include(TEMPLATEPATH . ‘/category-products.php’);

}else{

include(TEMPLATEPATH . ‘/category-new.php’);

}//产品列表

?>

判断single模板 <?php

if ( in_category(array(3,4,5)) ){

include(TEMPLATEPATH .’/single-pro.php’);

}

else if( in_category(array(2)) ){

include(TEMPLATEPATH . ‘/single-products.php’);

}else{

include(TEMPLATEPATH . ‘/single-new.php’);

}//产品列表

?>

singel和category调用关键词和描述 //页面显示关键词

function the_keywords(){

if(is_home()&&($home_keywords=get_option(‘home_keywords’))!=””){

echo ‘<meta name=”keywords” content=”‘.$home_keywords.'”/>’.”\n”;

}else if(is_single()){

$tags=get_the_tags();

if($tags){

$keywords=array();

foreach ($tags as $tag){

$keywords[]=$tag->name;

}

$single_keywords=implode(“,”,$keywords);

echo ‘<meta name=”keywords” content=”‘.$single_keywords.'”/>’.”\n”;

}

}

}

//页面显示描述

function the_description(){

if(is_home()&&($home_description=get_option(‘home_description’))!=”){

echo ‘<meta name=”description” content=”‘.$home_description.'”/>’.”\n”;

}else if(is_single()||is_page()){

if ($post->post_excerpt) {

$description =$post->post_excerpt;

} else {

global $post;

$content=$post->post_content;

$description = str_replace(“\n”,””,mb_strimwidth(strip_tags($content),0,180));

}

echo ‘<meta name=”description” content=”‘.$description.'”/>’.”\n”;

}

}

 

模板文件里调用:

<title><?php echo trim(get_the_title()); ?></title>

<title>

<?php

foreach((get_the_category()) as $category)

{

echo $category->cat_name;

}

?></title>

 

<?php the_keywords();?>

<?php the_description();?>

上一篇下一篇调用 博客形式正常调用:

<?php previous_post_link(‘上一篇: %link’) ?>

<?php next_post_link(‘下一篇: %link’) ?>

————————————————————————————————————

带上title属性的上一篇下一篇:

上一篇:<?php

$prev_post = get_previous_post();

if (!empty( $prev_post )): ?>

<a title=”<?php echo $prev_post->post_title; ?>” href=”<?php echo get_permalink( $prev_post->ID ); ?>”><?php echo $prev_post->post_title; ?></a>

<?php endif; ?>

下一篇:<?php

$next_post = get_next_post();

if (!empty( $next_post )): ?>

<a title=”<?php echo $next_post->post_title; ?>” href=”<?php echo get_permalink( $next_post->ID ); ?>”><?php echo $next_post->post_title; ?></a>

<?php endif; ?>

————————————————————————————————————

同一分类下实现上一篇下一篇:

<?php if (get_previous_post()) { previous_post_link(‘上一篇: %link’,’%title’,true);} else { echo “没有了,已经是最后文章”;} ?>

<?php if (get_next_post()) { next_post_link(‘上一篇: %link’,’%title’,true);} else { echo “没有了,已经是最新文章”;} ?>

当前分类下其他文章 <?php

global $post;

$categories = get_the_category(); //函数获取分类ID好

foreach ($categories as $category){

?>

<ul>

<?php

$posts = get_posts(‘numberposts=5&orderby=rand&category=’. $category->term_id);

//通过get_posts函数,根据分类ID来获取这个ID下的文章内容。

foreach($posts as $post){

?>

<li><a href=”<?php the_permalink(); ?>”>

<?php if(emtx_auto_thumbnail($post->ID) ) { echo emtx_auto_thumbnail($post->ID);} ?>

</a>

<p><a href=”<?php the_permalink(); ?>”>

<?php the_title(); ?>

</a></p>

</li>

<?php } ?>

</ul>

<?php } ?>

自定义字段  <?php $values = get_post_custom_values(“自定义”); echo $values[0]; ?>

 

<?php echo get_post_meta($post->ID, ‘自定义’, true); ?>

tag页面标题调用 <?php single_tag_title(“”, true); ?>
不同page不同模板 <?php

if ( in_page( 5 ) ){

include(TEMPLATEPATH .’/page-about.php’);

} //case

elseif( in_page( 1 ) ){

include(TEMPLATEPATH . ‘/page-news.php’);

}//news

else{

include(TEMPLATEPATH . ‘/page-news.php’);

}

?>

调用随机文章 function random_posts($posts_num=5,$before=’

‘,$after=’

‘){

global $wpdb;

$count= $wpdb->get_results(“SELECT MIN(ID) as min,MAX(ID) as max from $wpdb->posts”);

$startid=$count[0]->min;

$endid=$count[0]->max;

$querycount=0;

for ($i=0;$i<$posts_num;$i++){

//安全设置,保证不出现死循环

if($querycount-$posts_num>$posts_num) break;

$id=rand($startid,$endid);

$sql=”SELECT ID, post_title,guid from $wpdb->posts where ID=$id and post_status = ‘publish’ and post_title != ” AND post_password =” AND post_type = ‘post'”;

$randposts=$wpdb->get_results($sql);

if(! $randposts){$i–;continue;}

$output = ”;

foreach ($randposts as $randpost) {

$post_title = stripslashes($randpost->post_title);

$permalink = get_permalink($randpost->ID);

$output .= $before.” . $post_title . ”;

$output .= $after;

}

echo $output;

$querycount++;

}

}

 

调用代码:<?php random_posts();?>

 

例如要调10条记录,用ul和ol显示

<ul>

<?php random_posts(10,”<ol>”,”</ol>”);?>

</ul>

<?php

if (is_home()) {

//将以下引号中的内容改成你的首页description

$description = “博客描述”;

// 将以下引号中的内容改成你的首页keywords

$keywords = “关键词”;}

elseif (is_single() || is_page()) {

$description1 = get_post_meta($post->ID, “description”, true);

$description2 = mb_strimwidth(strip_tags(apply_filters

(‘the_content’, $post->post_content)), 0, 200, “…”);

// 填写自定义字段description时显示自定义字段的内容,否则使用文章内容前100字作为描述

$description = $description1 ? $description1 : $description2;

// 填写自定义字段keywords时显示自定义字段的内容,否则使用文章tags作为关键词

$keywords = get_post_meta($post->ID, “keywords”, true);

if($keywords == ”) {

$tags = wp_get_post_tags($post->ID);

foreach ($tags as $tag ) {

$keywords = $keywords . $tag->name . “, “;}

$keywords = rtrim($keywords, ‘, ‘);}

}

elseif (is_category()) {

$description = category_description();

$keywords = single_cat_title(”, false);}

elseif (is_tag()){

$description = tag_description();

$keywords = single_tag_title(”, false);

}

$description = trim(strip_tags($description));

$keywords = trim(strip_tags($keywords));

?>

<meta name=”description” content=”<?php echo $description; ?>” />

<meta name=”keywords” content=”<?php echo $keywords; ?>” />

调用文章描述 <?php the_excerpt();?>
调用当前标签 <?php echo trim(get_the_title()); ?>
标签页调用当前位置: <?php if (function_exists(‘dimox_breadcrumbs’)) dimox_breadcrumbs(); ?>
标签云(可用在相关搜索) <?php the_tags(“”);?>

Tags: | |