安装WordPress来建立公司网站和个人博客网站
安装:
环境:CentOS7.3
下载 wordpress-4.9.4.tar.gz
安装mysql:
# yum install mariadb-server
# vi /etc/my.cnf
…
# mysql_install_db –user=mysql –datadir=/data/MariaDB_DATA/
# systemctl start mariadb
建立新用户和设置root密码:
# mysqladmin -u root password ‘xxxxx’
# mysql -uroot -p
MariaDB [(none)]> create database wordpress;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON wordpress.* TO wordpress@”localhost” IDENTIFIED BY “xxxxx”;
安装apache:
# yum install httpd
安装php:
# yum install php
# yum install php-mysql
增大文件上传大小限制:
# vi /etc/httpd/conf.d/php.conf
尾部增加:
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
启动apache:
# systemctl start httpd
测试:
放入/var/www/htm/test.php:
<?php
phpinfo();
?>
访问:http://xxx.xx.xx.xx/test.php
可以看到php的各类信息,包括mysql连接信息。
安装wordpress:
# tar -zxvf wordpress-4.9.4.tar.gz
# mv wordpress /var/www/html/blog
然后访问:http://xxx.xx.xxx.xx/blog/ ,按照提示操作。
模板:
使用“Responsiveness”主题模板themes,也可以选择其他自己喜欢的模板,如果是公司网站,最好选择不带右侧sidebar的模板。
修改:
增加撰写编辑文章时字体设置等功能,在管理页面的“外观”->“编辑”->选择: 模板函数 (functions.php),底部添加:
function add_editor_buttons($buttons) {
$buttons[] = ‘fontselect’;
$buttons[] = ‘fontsizeselect’;
$buttons[] = ‘backcolor’;
$buttons[] = ‘underline’;
$buttons[] = ‘hr’;
$buttons[] = ‘sub’;
$buttons[] = ‘sup’;
$buttons[] = ‘cut’;
$buttons[] = ‘copy’;
$buttons[] = ‘paste’;
$buttons[] = ‘cleanup’;
$buttons[] = ‘wp_page’;
$buttons[] = ‘newdocument’;
return $buttons;
}
add_filter(“mce_buttons_2”, “add_editor_buttons”);
去掉sidebar里面“功能”部分的Wordpress.org链接:
# vi wp-includes/widgets/class-wp-widget-meta.php
…
<ul>
<?php wp_register(); ?>
<!– Max Shu modify on 2018/3/10
<li><?php wp_loginout(); ?></li>
–>
<li><a href=”<?php echo esc_url( get_bloginfo( ‘rss2_url’ ) ); ?>”><?php _e(‘Entries <abbr title=”Really Simple Syndication”>RSS</abbr>’); ?></a></li>
<li><a href=”<?php echo esc_url( get_bloginfo( ‘comments_rss2_url’ ) ); ?>”><?php _e(‘Comments <abbr title=”Really Simple Syndication”>RSS</abbr>’); ?></a></li>
<?php
/**
* Filters the “Powered by WordPress” text in the Meta widget.
*
* @since 3.6.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @param string $title_text Default title text for the WordPress.org link.
* @param array $instance Array of settings for the current widget.
*/
/* Max Shu modify on 2018/3/10
echo apply_filters( ‘widget_meta_poweredby’, sprintf( ‘<li><a href=”%s” title=”%s”>%s</a></li>’,
esc_url( __( ‘https://wordpress.org/’; ) ),
esc_attr__( ‘Powered by WordPress, state-of-the-art semantic personal publishing platform.’ ),
_x( ‘WordPress.org‘, ‘meta widget link text’ )
), $instance );
*/
wp_meta();
?>
</ul>
…
修改评论部分标题:
# vi ./wp-content/themes/responsiveness/comments.php
<h3 class=”comments-title”>
<?php
$comment_number = get_comments_number();
$comment_locale = number_format_i18n( $comment_number );
/* Max Shu modify on 2018/3/10
if ( ‘1’ === $comment_number ) {
esc_html_e( ‘One comment’, ‘responsiveness’ );
} else {
// translators: %s: number of comments
printf( esc_html( _n( ‘%s Commment’, ‘%s Commments’, $comment_locale, ‘responsiveness’ ) ), $comment_locale ); // WPCS: XSS OK.
}
*/
printf( esc_html( _n( ‘%s条评论’, ‘%s Commments’, $comment_locale, ‘responsiveness’ ) ), $comment_locale );
?>
</h3>
Responsiveness: 样式表 (style.css) 选择要编辑的主题(有必要的话):
h2.comments-title {
text-align: center;
font-weight: 600;
color: #333
}
Responsiveness: 样式表 (style.css) 给每个段落的开头增加两个字的缩进:
.entry-content p {
text-indent:2em;
margin: 1.5rem 0
}
修改“Continue Reading”按钮为中文:
# vi ./wp-content/themes/responsiveness/inc/template-tags.php
function responsiveness_fancy_excerpt() {
global $post;
if( is_archive() ) {
echo ‘<div class=”continue-reading”>’;
echo ‘<a class=”more-link more-link-activated” href=”‘ . esc_url( get_permalink() ) . ‘” title=”‘ . esc_html__( ‘继续阅读 ‘, ‘responsiveness’ ) . get_the_title() . ‘” rel=”bookmark”>’ . esc_html__( ‘继续阅读’, ‘responsiveness’ ) . ‘</a>’;
echo ‘</div>’;
} elseif ( is_page_template( ‘page-templates/page-child-pages.php’ ) ) {
the_excerpt();
echo ‘<div class=”continue-reading”>’;
echo ‘<a class=”continue-reading-arrow” href=”‘ . esc_url( get_permalink() ) . ‘” title=”‘ . esc_html__( ‘继续阅读 ‘, ‘responsiveness’ ) . get_the_title() . ‘” rel=”bookmark”>→</a>’;
echo ‘</div>’;
} elseif ( has_excerpt() || is_page_template( ‘page-templates/frontpage-portfolio.php’ ) ) {
the_excerpt();
echo ‘<div class=”continue-reading”>’;
echo ‘<a class=”more-link more-link-activated” href=”‘ . esc_url( get_permalink() ) . ‘” title=”‘ . esc_html__( ‘继续阅读 ‘, ‘responsiveness’ ) . get_the_title() . ‘” rel=”bookmark”>’ . esc_html__( ‘继续阅读’, ‘responsiveness’ ) . ‘</a>’;
echo ‘</div>’;
} elseif ( strpos ( $post->post_content, ‘<!–more–>’ ) ) {
the_content();
echo ‘<div class=”continue-reading”>’;
echo ‘<a class=”more-link more-link-activated” href=”‘ . esc_url( get_permalink() ) . ‘” title=”‘ . esc_html__( ‘继续阅读 ‘, ‘responsiveness’ ) . get_the_title() . ‘” rel=”bookmark”>’ . esc_html__( ‘继续阅读’, ‘responsiveness’ ) . ‘</a>’;
echo ‘</div>’;
} elseif ( str_word_count ( $post->post_content ) < 200 ) {
the_content();
} else {
the_excerpt();
echo ‘<div class=”continue-reading”>’;
echo ‘<a class=”more-link more-link-activated” href=”‘ . esc_url( get_permalink() ) . ‘” title=”‘ . esc_html__( ‘继续阅读 ‘, ‘responsiveness’ ) . get_the_title() . ‘” rel=”bookmark”>’ . esc_html__( ‘继续阅读’, ‘responsiveness’ ) . ‘</a>’;
echo ‘</div>’;
}
}
修改“Previous Post:”“Next Post:”为中文:
# vi ./wp-content/themes/responsiveness/inc/template-tags.php
<nav class=”navigation post-navigation” role=”navigation”>
<p class=”screen-reader-text”><?php esc_html_e( ‘Post navigation’, ‘responsiveness’ ); ?></p>
<div class=”nav-links” data-equalizer>
<?php
previous_post_link( ‘<div class=”nav-previous” data-equalizer-watch><div class=”nav-indicator”>’ . esc_html_x( ‘前一篇:’, ‘Previous post’, ‘responsiveness’ ) . ‘<
/div><h4>%link</h4></div>’, ‘%title’ );
next_post_link( ‘<div class=”nav-next” data-equalizer-watch><div class=”nav-indicator”>’ . esc_html_x( ‘后一篇:’, ‘Next post’, ‘responsiveness’ ) . ‘</div
><h4>%link</h4></div>’, ‘%title’ );
?>
</div> <!– .nav-links –>
</nav> <!– .navigation –>
页面加入meta信息:
# vi ./wp-content/themes/responsiveness/header.php
<html <?php language_attributes(); ?>>
<head>
<meta http-equiv=”X-UA-Compatible” content=”IE=edge,chrome=1″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<meta name=”keywords” content=”人工智能,云计算,大数据,物联网,IT,通信,嵌入式” />
<meta name=”description” content=”天楚,锐齿,天楚锐齿,锐齿咨询,见龙在天,Adai,Max Shu;从事人工智能、云计算、大数据、物联网、IT、通信、嵌入式研发。” />
<meta name=”author” content=”Max Shu” />
<meta charset=”<?php bloginfo( ‘charset’ ); ?>”>
增加手工上传文件的目录,用来保存视频等特别大的文件:
# mkdir /var/www/html/blog/./upload_manual
# chown -R apache:apache ./upload_manual
通过管理后台上传媒体文件的保存位置:
./wp-content/uploads/
修改后台管理页面上传文档的大小限制:
# vi /etc/httpd/conf.d/php.conf
尾部增加,然后重启httpd:
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
插件:
Dyanomic QR Code Generator:
在“外观”“小工具”里面“Sidebar”的About This site(个人介绍)增加短代码:
扫描二维码分享该文章(反斜杠不需要):
[d\q\r_c\o\d\e]
修改以下代码以在sidebar方式下产生首页二维码(估计是bug):
# vi ./wp-content/plugins/dynamic-qr-code-generator/dynamic_qr_code_generator.php
public function shortcode_dqr_code($atts)
{
$args = shortcode_atts( array(
‘post_id’ => ‘0’,
‘url’ => ”,
‘size’ =>’200′,
‘color’ =>’#000000′,
‘bgcolor’=> ‘#ffffff’
), $atts );
if($args[‘url’]==”){
if($args[‘post_id’]==”0″){
//no url or post id provided in shortcode return current page permalink
$url= get_permalink();
if (empty($url)){ $url= ‘http://www.max-shu.com/blog/’;}
$js_id=”qrcode-current”;
}else{
$url= get_permalink($args[‘post_id’]);
$js_id=”qrcode-“.$args[‘post_id’];
}
WP-PostViews:
设置中会出现一个“PostViews”的条目。
在“小工具”可以添加到sidebar,在“所有文章”处可以看到所有文章浏览量。
在编辑主题模板的single.php,加入以下代码,每篇文章尾部显示浏览量:
<?php
while ( have_posts() ) : the_post();
get_template_part( ‘components/post/content’, get_post_format() );
if(function_exists(‘the_views’)) { the_views(); }
responsiveness_post_navigation();
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
?>