有没有办法删除帖子标题?或者至少不需要我输入帖子标题。我已经从tumblr迁移到wordpress,我不需要tumblr的标题,所以我想知道我是否可以对wordpress也这样做?
Remove post title
3 个回复
最合适的回答,由SO网友:Jen 整理而成
Wordpress不需要输入文章标题,至少不需要在后端输入。你可以把表格的那部分留空。
就你的主题而言,这将取决于主题作者以及他们是否考虑过没有输入标题的人。默认的twentyeleven主题处理得很好,使用发布日期链接到帖子页面,但并非所有作者都会这么周到。如果您使用的主题没有其他选择,可以尝试编辑循环。
根据主题的设置方式,可能只有一个循环,也可能有几个循环用于不同的目的。您正在查找与归档、类别、标记、搜索和主页相关的循环。通常会有一个“默认”循环,只获取所有这些值(“loop.php”)。查找带有标题标记和<? the_title(); ?>
在他们里面。大多数看起来像这样:
<h2 class="entry-title">
<a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a>
</h2>
从各方面考虑,你通常可以把这件事放在一边。当没有文本可供填写时<h2>
上面的标记只是折叠并消失。问题是,如果这是唯一的链接,您需要其他东西来链接到帖子页面。二十一世纪的主题正好提供了这一点。将此函数添加到函数文件:function twentyeleven_posted_on() {
printf( __( \'<span class="sep">Posted on</span>
<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date"
datetime="%3$s" pubdate>%4$s</time></a><span class="by-author">
<span class="sep"> by </span>
<span class="author vcard">
<a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a>
</span></span>\', \'twentyeleven\' ),
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
esc_attr( get_the_date( \'c\' ) ),
esc_html( get_the_date() ),
esc_url( get_author_posts_url( get_the_author_meta( \'ID\' ) ) ),
esc_attr( sprintf( __( \'View all posts by %s\', \'twentyeleven\' ), get_the_author() ) ),
get_the_author()
);
}
然后,您可以在标题显示位置附近的循环中调用它:<h2 class="entry-title">
<a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a>
</h2>
<?php twentyeleven_posted_on() ?>
希望这有帮助!SO网友:fuxia
你可以使用我的插件Fix Empty Titles. 当文章保存且标题仍然为空时,它会从文章正文的前20个字符创建一个文章标题。
当前代码:
<?php # -*- coding: utf-8 -*-
/*
Plugin Name: Fix Empty Titles
Description: Replaces missing titles with the first characters from post body.
Version: 1.1
Required: 3.2
Author: Thomas Scholz
Author URI: http://toscho.de
License: GPL
Based on an idea of Konstantin Kovshenin. See
http://kovshenin.com/2011/10/wordpress-posts-without-titles-in-rss-feeds-3621/
*/
add_action( \'save_post\', \'t5_fix_empty_title\', 11, 2 );
/**
* Fills an empty post title from the first words of the post.
*
* @param int $post_id Post ID
* @param object $post Post object
* @return void
*/
function t5_fix_empty_title( $post_id, $post )
{
if ( ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE )
or ! current_user_can( \'edit_post\', $post_id )
or ! empty ( $post->post_title )
or empty ( $post->post_content )
or wp_is_post_revision( $post )
)
{ // Noting to do.
return;
}
// Remove all tags and replace breaks whith white space.
$no_tags = wp_strip_all_tags( $post->post_content, TRUE );
// The post content contains just markup.
if ( \'\' === $no_tags )
{
return;
}
$length = apply_filters( \'t5_fix_empty_title_length\', 20 );
$words = preg_split( "/\\s+/", $no_tags, $length, PREG_SPLIT_NO_EMPTY );
array_pop( $words );
$title = implode( \' \', $words );
// Add a no break space and an ellipsis at the end.
$title = rtrim( $title, \'.,!?…*\' ) . \' …\';
wp_update_post( array ( \'ID\' => $post_id, \'post_title\' => $title ) );
}
我不会隐藏标题输入字段,因为那时您没有简单的方法来更改标题。SO网友:Vivekpathak
您可以在主题函数中使用此代码。php文件删除文章标题中的链接。
add_action(\'wp_head\' , \'remove_post_list_title_links\');
function remove_post_list_title_links() {
?>
<script id="remove-links-in-title" type="text/javascript">
jQuery(document).ready(function($) {
$(\'.entry-title\').each(function() {
var $title_link = $(\'a[rel="bookmark"]\' , $(this)),
$title_text = $title_link.text();
$title_link.remove();
$(this).prepend($title_text);
});
});
</script>
<?php
}
结束