wordpress实用修改命令

阅读数:3067

显示当前Category Name可用:<?php printf( __(‘%s’,”), single_cat_title(”, false)); ?>

显示当前category description:<?php echo category_description(); ?>

不支持中文tag符号的URL:可使用这个classes文档

增加密码的文章文字修改:在function.php 增加:

function catch_that_image() {
global $post, $posts;
$first_img = ”;
ob_start();
ob_end_clean();
$output = preg_match_all(‘/<img.+src=[\'"]([^\'"]+)[\'"].*>/i’, $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //设置默认图片,在文中没有图片是显示
$first_img = “http://www.zvenue.cn/wp-content/themes/zve/images/z.jpg”;
}
return $first_img;
}
function my_password_form() {
global $post;
$label = ‘pwbox-’.( empty( $post->ID ) ? rand() : $post->ID );
$o = ‘<form action=”‘ . esc_url( site_url( ‘wp-login.php?action=postpass’, ‘login_post’ ) ) . ‘” method=”post”>
‘ . __( “本节为正式学员课件,请输入课件密码:” ) . ‘
<label for=”‘ . $label . ‘”>’ . __( “Password:” ) . ‘ </label><input name=”post_password” id=”‘ . $label . ‘” type=”password” size=”20″ /><input type=”submit” name=”Submit” value=”‘ . esc_attr__( “Submit” ) . ‘” />
</form>
‘;
return $o;
}
add_filter( ‘the_password_form’, ‘my_password_form’ );

 

动态meta title, keyword description

<?php
if (is_home() || is_page()) {
// 将以下引号中的内容改成你的主页description
$description = “”;

// 将以下引号中的内容改成你的主页keywords
$keywords = “”;
}
elseif (is_single()) {
$description1 = strip_tags(get_the_excerpt($post->ID));
$description2 = mb_strimwidth(strip_tags($post->post_content), 0, 200, “…”);

// 填写自定义字段description时显示自定义字段的内容,否则使用文章内容前200字作为描述
$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; ?>” />