在太阳下
不管你喜不喜欢,高不高兴,爱与不爱;太阳照旧照耀着你!温暖着你!

wordpress 文章列表显示

首先来说说为什么要设置为文章列表显示吧
传统的博客程序都是全文显示或是摘要显示,一打开首页的齐刷刷的内容需要加载,并且这些内容未必是我们想要看的,我自己的习惯是先浏览一下最新的文章目录,然后看看有没有自己感兴趣的,如果没有的话就再往后看看有没有自己感兴趣的,如果没有直接就关掉这个网页,浪费他人的时间无异于谋财害命….
以前用过asp的一个博客程序PJblog,里面就有一个列表功能很是喜欢,但是asp的主机空间越来越少,php主流起来,也就换了WrodPress,WP很强大,但自己却没什么能耐,一只没能实现这个愿望,也曾经求助过他人由于种种原因一只没找到现成的答案,幸运的是前几天在WP的论坛上发了篇贴求助,得到了满意的答复,太感谢这位元凶了;虽然说用WP已经用好几年时间了,但感觉自己完全就是一小白。
好了,唠叨了那么多,现在来说说怎么WrodPress怎么实现列表显示文章的
目的:实现文章列表显示
方法:通过修改主题实现
1.删除文章摘要
2.删除“发表回复”
3.删除“文章发表日期”
4.删除“文章所属分类”

方法
在博客程序后台【外观】菜单下面找到【编辑】然后在编辑主题页面的最右边找到【首页模板index.php】并打开

<?php
/**
* The main template file
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* For example, it puts together the home page when no home.php file exists.
*
* @link http://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
*/

get_header(); ?>

<div id=”primary” class=”site-content”>
<div id=”content” role=”main”>
<?php if ( have_posts() ) : ?>

<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( ‘content’, get_post_format() ); ?>
<?php endwhile; ?>

<?php else : ?>

<article id=”post-0″ class=”post no-results not-found”>

<?php if ( current_user_can( ‘edit_posts’ ) ) :
// Show a different message to a logged-in user who can add posts.
?>
<header class=”entry-header”>
<h1 class=”entry-title”><?php _e( ‘No posts to display’, ‘twentytwelve’ ); ?></h1>
</header>

<div class=”entry-content”>
<p><?php printf( __( ‘Ready to publish your first post? <a href=”%s”>Get started here</a>.’, ‘twentytwelve’ ), admin_url( ‘post-new.php’ ) ); ?></p>
</div><!– .entry-content –>

<?php else :
// Show the default message to everyone else.
?>
<header class=”entry-header”>
<h1 class=”entry-title”><?php _e( ‘Nothing Found’, ‘twentytwelve’ ); ?></h1>
</header>

<div class=”entry-content”>
<p><?php _e( ‘Apologies, but no results were found. Perhaps searching will help find a related post.’, ‘twentytwelve’ ); ?></p>
<?php get_search_form(); ?>
</div><!– .entry-content –>
<?php endif; // end current_user_can() check ?>

</article><!– #post-0 –>

<?php endif; // end have_posts() check ?>

</div><!– #content –>
</div><!– #primary –>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

<?php get_template_part( ‘content’, get_post_format() ); ?>
这段的意思就是说首页模板的样式是基于content.php

打开【content.php】

<?php
/**
* The default template for displaying content
*
* Used for both single and index/archive/search.
*
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
*/
?>

<article id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>
<?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
<div class=”featured-post”>
<?php _e( ‘Featured post’, ‘twentytwelve’ ); ?>
</div>
<?php endif; ?>
<header class=”entry-header”>
<?php the_post_thumbnail(); ?>
<?php if ( is_single() ) : ?>
<h1 class=”entry-title”><?php the_title(); ?></h1>
<?php else : ?>
<h1 class=”entry-title”>
<a href=”<?php the_permalink(); ?>” rel=”bookmark”><?php the_title(); ?></a>
</h1>
<?php endif; // is_single() ?>
<?php if ( comments_open() ) : ?>
<div class=”comments-link”>
<?php comments_popup_link( ‘<span class=”leave-reply”>’ . __( ‘Leave a reply’, ‘twentytwelve’ ) .
‘</span>’, __( ‘1 Reply’, ‘twentytwelve’ ), __( ‘% Replies’, ‘twentytwelve’ ) ); ?>
</div><!– .comments-link –>
<?php endif; // comments_open() ?>
</header><!– .entry-header –>

<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class=”entry-summary”>
<?php the_excerpt(); ?>
</div><!– .entry-summary –>
<?php else : ?>
<div class=”entry-content”>
<?php the_content( __( ‘Continue reading <span class=”meta-nav”>&rarr;</span>’, ‘twentytwelve’ ) ); ?>
<?php wp_link_pages( array( ‘before’ => ‘<div class=”page-links”>’ . __( ‘Pages:’, ‘twentytwelve’ ), ‘after’ => ‘</div>’ )
); ?>
</div><!– .entry-content –>
<?php endif; ?>

<footer class=”entry-meta”>
<?php twentytwelve_entry_meta(); ?>
<?php edit_post_link( __( ‘Edit’, ‘twentytwelve’ ), ‘<span class=”edit-link”>’, ‘</span>’ ); ?>
<?php if ( is_singular() && get_the_author_meta( ‘description’ ) && is_multi_author() ) : // If a user has filled out
their description and this is a multi-author blog, show a bio on their entries. ?>
<div class=”author-info”>
<div class=”author-avatar”>
<?php
/** This filter is documented in author.php */
$author_bio_avatar_size = apply_filters( ‘twentytwelve_author_bio_avatar_size’, 68 );
echo get_avatar( get_the_author_meta( ‘user_email’ ), $author_bio_avatar_size );
?>
</div><!– .author-avatar –>
<div class=”author-description”>
<h2><?php printf( __( ‘About %s’, ‘twentytwelve’ ), get_the_author() ); ?></h2>
<p><?php the_author_meta( ‘description’ ); ?></p>
<div class=”author-link”>
<a href=”<?php echo esc_url( get_author_posts_url( get_the_author_meta( ‘ID’ ) ) ); ?>”
rel=”author”>
<?php printf( __( ‘View all posts by %s <span class=”meta-nav”>&rarr;</span>’,
‘twentytwelve’ ), get_the_author() ); ?>
</a>
</div><!– .author-link –>
</div><!– .author-description –>
</div><!– .author-info –>
<?php endif; ?>
</footer><!– .entry-meta –>
</article><!– #post –>
找到这段代码删掉
<div>
<?php the_content( __( ‘Continue reading <span>&rarr;</span>’, ‘twentytwelve’ ) ); ?>
<?php wp_link_pages( array( ‘before’ => ‘<div>’ . __( ‘Pages:’, ‘twentytwelve’ ), ‘after’ => ‘</div>’ )
); ?>
</div><!– .entry-content –>

测试过,文章摘要是删掉了,但是还要修改
1.文章标题/字号
2.删除“发表回复”
3.删除“文章发表日期”
4.删除“文章所属分类”
说简单也简单说复杂也复杂,再说吧,这么久也都过去了

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址