用wordpress建立小说站文章站几个要点备注
在网上找的wordpress小说主题都是太垃圾了,要么不能用,要么有毒。想要一个中意的模板风格很难。干脆自己根据wordpress提供的热门风格中改一款,这样既精简也放心,而且还能完美自适应。
关于文章倒序的问题:对于wordpress来说,管理分类的分为三个文件,分别为 category.php 或 archive.php以及category-*.php文件(*表示对应的分类序号),一般建议给主题添加一个 category.php 文件,因为是它专门用来显示分类存档的,优先级别高于 archive.php 。如果主题没有 category.php ,你可以直接复制 archive.php 的代码,另存为 category.php 即可。另外category-*.php文件是指给每个对应的主题以对应的风格,完全自定义了。
这里我就是在对应主题的根目录中建立category.php文件,代码如下
<?php
get_header();
global $wp_query;
$cat_ID = get_query_var('cat');
$myposts = get_posts('numberposts=3000&order=ASC&category='.$cat_ID);
foreach($myposts as $cat)
{
?>
<center><a href="<?php echo get_permalink($cat->ID);?>"> <?php echo get_the_title($cat->ID); ?> </a></center>
<?php
}
get_footer();
?>对于小说站而言重新定义对应目录3000个章节,采用倒序方法进行排列。至于美观上,如果有需要,自己去写CSS。
阅读页面的代码通常要加上上一章下一章的内容,这个前面我的日志《wordpress增加同类目上一篇下一篇的功能》中也有讲到。这里放Ribbon Lite这个主题的代码
<?php
/**
* The template for displaying all single posts.
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
*
* @package Ribbon Lite
*/
$ribbon_lite_single_breadcrumb_section = get_theme_mod('ribbon_lite_single_breadcrumb_section', '1');
$ribbon_lite_single_tags_section = get_theme_mod('ribbon_lite_single_tags_section', '1');
$ribbon_lite_authorbox_section = get_theme_mod('ribbon_lite_authorbox_section', '1');
$ribbon_lite_relatedposts_section = get_theme_mod('ribbon_lite_relatedposts_section', '1');
get_header(); ?>
<div id="page" class="single">
<div class="content">
<!-- Start Article -->
<article class="article">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('post'); ?>>
<div class="single_post">
<div class="post-date-ribbon"><div class="corner"></div><?php the_time( get_option( 'date_format' ) ); ?></div>
<?php if($ribbon_lite_single_breadcrumb_section == '1') { ?>
<div class="breadcrumb" xmlns:v="http://rdf.data-vocabulary.org/#"><?php ribbon_lite_the_breadcrumb(); ?></div>
<?php } ?>
<header>
<!-- Start Title -->
<h1 class="title single-title"><?php the_title(); ?></h1>
<!-- End Title -->
<!-- Start Post Meta -->
<div class="post-info">
<span class="theauthor"><span><i class="ribbon-icon icon-users"></i></span><?php _e('By','ribbon-lite'); ?> <?php the_author_posts_link(); ?></span>
<span class="featured-cat"><span><i class="ribbon-icon icon-bookmark"></i></span><?php the_category(', '); ?></span>
<span class="thecomment"><span><i class="ribbon-icon icon-comment"></i></span> <a href="<?php comments_link(); ?>"><?php comments_number(__('0 Comments','ribbon-lite'),__('1 Comment','ribbon-lite'),__('% Comments','ribbon-lite')); ?></a></span>
</div>
<!-- End Post Meta -->
</header>
<!-- Start Content -->
<div id="content" class="post-single-content box mark-links">
<?php
$categories = get_the_category();
$categoryIDS = array();
foreach ($categories as $category) {
array_push($categoryIDS, $category->term_id);
}
$categoryIDS = implode(",", $categoryIDS);
?>
<?php if (get_previous_post($categoryIDS)) { previous_post_link('上壹篇: %link','%title',true);} else { echo "沒有了,已經是最後文章";} ?>
<br>
<?php if (get_next_post($categoryIDS)) { next_post_link('下壹篇: %link','%title',true);} else { echo "沒有了,已經是最新文章";} ?>
<?php the_content(); ?>
<?php wp_link_pages(array('before' => '<div class="pagination">', 'after' => '</div>', 'link_before' => '<span class="current"><span class="currenttext">', 'link_after' => '</span></span>', 'next_or_number' => 'next_and_number', 'nextpagelink' => __('Next', 'ribbon-lite' ), 'previouspagelink' => __('Previous', 'ribbon-lite' ), 'pagelink' => '%','echo' => 1 )); ?>
<?php if($ribbon_lite_single_tags_section == '1') { ?>
<?php
$categories = get_the_category();
$categoryIDS = array();
foreach ($categories as $category) {
array_push($categoryIDS, $category->term_id);
}
$categoryIDS = implode(",", $categoryIDS);
?>
<?php if (get_previous_post($categoryIDS)) { previous_post_link('上壹篇: %link','%title',true);} else { echo "沒有了,已經是最後文章";} ?>
<br>
<?php if (get_next_post($categoryIDS)) { next_post_link('下壹篇: %link','%title',true);} else { echo "沒有了,已經是最新文章";} ?>
<?php }?>
<?php comments_template( '', true ); ?>
</div>
</div>
<?php endwhile; ?>
</article>
<!-- End Article -->
<!-- Start Sidebar -->
<?php get_sidebar(); ?>
<!-- End Sidebar -->
</div>
</div>
<?php get_footer(); ?>最后,最为重要的就是采集功能,这里有一款采集的插件,非常简单好用。缺点是只能采集一项,多项采集要不停修改采集规则,而且对于采集而言,还没有比关关采集器更加好用的。
采集插件下载:wp-aut_20160325152217.zip
wordpress总共才10个表,负载真的是个坑。非常不推荐使用wordpress做小说站。
另外WordPress的代码是默认的把HMTL符号实体转码成代码,所以无论是杰奇的后台采集还是关关采集。都需要把代码转码成符号,对应的关关替换如下:
∀♂∀ ∂♂∂ ∃♂∃ ∅♂∅ ∇♂∇ ∈♂∈ ∉♂∉ ∋♂∋ ∏♂∏ ∑♂∑ −♂− ∗♂∗ √♂√ ∝♂∝ ∞♂∞ ∠♂∠ ∧♂∧ ∨♂∨ ∩♂∩ ∪♂∪ ∫♂∫ ∴♂∴ ∼♂∼ ≅♂≅ ≈♂≈ ≠♂≠ ≡♂≡ ≤♂≤ ≥♂≥ ⊂♂⊂ ⊃♂⊃ ⊄♂⊄ ⊆♂⊆ ⊇♂⊇ ⊕♂⊕ ⊗♂⊗ ⊥♂⊥ ⋅♂⋅ ƒ♂ƒ ˆ♂ˆ ˜♂˜ –♂– —♂— ‘♂' ’♂' ‚♂‚ “♂" ”♂" „♂„ †♂† ‡♂‡ •♂• …♂… ‰♂‰ ′♂′ ″♂″ ‹♂‹ ›♂› ‾♂‾ €♂€ ™♂™ ™♂™ ←♂← ↑♂↑ →♂→ ↓♂↓ ↔♂↔ ↵♂↵ ⌈♂⌈ ⌉♂⌉ ⌊♂⌊ ⌋♂⌋ ◊♂◊
更多内容可以百度一下:HTML 符号实体参考手册


评论
fc
回复最后用起来了吗?我也想鼓捣个,就怕花了力气又不好用
ike
回复Wordpress 太消耗资源了,搭建了同类型的,那玩意儿是真消耗资源,现在弄的小说站淘宝定制的感觉还可以,优化的比较好,大佬可以看看 https://cqjiujiu.com 自动采集收录的还是快。