WordPress入门 - 2025年个人日记备份

WordPress登录后台重定向次数过多的解决办法

如果你新安装的一个wordpress站点配置https后,再登录wordpress后台,却无法访问后台了。页面提示:将您重定向的次数过多,怎么办呢?

只需要在网站根目录的php文件wp-config.php开头加入以下代码,即可完美解决此问题了:

解决方法

在你的网站根目录下,找到 wp-config.php 文件,并加入以下代码,即可解决“将您重定向的次数过多”问题:

$_SERVER['HTTPS'] = 'on';

define('FORCE_SSL_LOGIN', true);

define('FORCE_SSL_ADMIN', true);

关键说明:以上代码添加时,必须添加在 if ( !defined('ABSPATH') ) 代码之前才能生效!如下图所示位置:

否则,在登录WordPress网站后台时,可能会出现“抱歉,您不能访问此页面”的错误提示,导致还是无法登录网站后台。

不显示全文  content.php

content.php

<div id="aaa">        

<?php

if ( ! post_password_required() && ! is_attachment() ) :

the_post_thumbnail();

endif;

?>

<!-- .缩略图 -->

<?php

  if(!is_single()) {

      the_excerpt();

  } else {

      the_content(__('(more…)'));

  }

?>        

<!-- .显示全文 -->

</div> 

手机 viewport meta 标签

针对移动网页优化过的页面的 viewport meta 标签大致如下:

<meta name="viewport" content="width=device-width, initial-scale=1">

<div id="aaa">        <!-- .显示全文 -->

<?php the_content( __( '???? <span class="meta-nav">...</span>', 'twentytwelve' ) ); ?>

</div> 

分页插件WP-PageNavi 使用

此插件并不是启用后就可以看到效果了,必须把以下代码放到模板上;例如:分类目录模板;

 <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>

切记:不要把代码放到循环内!

侧边栏悬浮固定

运用到下面的代码(当然是在边栏sidebar.php文件内添加):

  1. <div id="float" class="div2">
  2. 你要悬浮的内容      
  3. </div>    
  4. <script type="text/javascript" src="http://www.***.com/a.js"></script>  

div内可以自由添加要悬浮的div内容,而下面运用的js文件的内容为:

  1. // 固定层
  2. function buffer(a,b,c){var d;return function(){if(d)return;d=setTimeout(function(){a.call(this),d=undefined},b)}}(function(){function e(){var d=document.body.scrollTop||document.documentElement.scrollTop;d>b?(a.className="div1 div2",c&&(a.style.top=d-b+"px")):a.className="div1"}var a=document.getElementById("float");if(a==undefined)return!1;var b=0,c,d=a;while(d)b+=d.offsetTop,d=d.offsetParent;c=window.ActiveXObject&&!window.XMLHttpRequest;if(!c||!0)window.onscroll=buffer(e,150,this)})();

大家可以新建个a.js文件来调用,或者直接将上面的js代码放到你们wordpress已调用的js内!最后,给style.css里添加样式为:

  1. .div2{top:10px;z-index:999;position:fixed;_position:absolute}

WordPress显示文章最后更新时间教程

一、代码分享

WordPress的文章页面是single.php这个文件渲染的,所以我们要修改这个文件的代码。

找到文件中显示文章更新时间的代码块,下文以DUX主题为例,分别获取post_timeupdate_time即可,用到了get_the_timeget_the_modified_time这两个函数:

<?php 

// 首先获取时间信息 

$post_time = get_the_time('Y-m-d'); 

$update_time = get_the_modified_time('Y-m-d'); 

// 定义一个函数来判断日期B是否在日期A之后 

function dateAfterDate($date1, $date2) { 

    $date1_s = strtotime($date1); 

    $date2_s = strtotime($date2); 

    return $date2_s > $date1_s; 

// 检查是否需要显示更新时间 

if (dateAfterDate($post_time, $update_time)) { 

    // 如果更新时间晚于发布时间,则只显示更新时间 

    ?> 

    <span class="item">Keith更新于:<?php echo $update_time; ?></span> 

    <?php 

} else { 

echo '<span class="item">Keith发布于:' . get_the_date() . '</span>';

?> 

<?php
$post_time = get_the_time('Y-m-d');
$update_time = get_the_modified_time('Y-m-d');
function dateBDate($date1, $date2) {
    $date1_s = strtotime($date1);
    $date2_s = strtotime($date2);
    if ($date2_s - $date1_s > 0) {
        return true;
    } else {
        return false;
    }
}
if (!dateBDate($post_time, $update_time)) {
    ?>

<?php
} else {
    ?>
   <span class="item">更新于 <?php echo $update_time ?></span>
    <?php
}
?>

**************************************************

//文章更新提示

function show_last_updated( $content ) {

$u_time = get_the_time('U');

$u_modified_time = get_the_modified_time('U');

if ($u_modified_time >= $u_time + 86400) {

$updated_date = get_the_modified_time('Y年m月d日');

$updated_time = get_the_modified_time('G:i:s');

$custom_content .= '<p class="last-updated-date">此篇文章最近更新于:'. $updated_date . ' at '. $updated_time .'</p>';

}

$custom_content .= $content;

return $custom_content;

}

add_filter( 'the_content', 'show_last_updated' );

额外CSS


  

.last-updated-date {

    color: #675f5f;

    padding: 0.1em 0.5em;

    background: #ededed;

    letter-spacing: 1px;

    border-radius: 10px 10px;

    font-family: Raleway, Arial, sans-serif;

    text-align: center;

    font-size: 14px;

}

1XEoo6yCS17IAq4wDswWvBA
0375c0d40889
b1202fd4248f
DfvSCt4Q2ND4CRj_0_MFIAA
---
1ao7tXLJ6FpOPh5XXLS8C3g
d0151113699a
DdNX72sQ2ND4CRiY1fMFIAA

404跳轉

<script language="javascript"> location.replace("https://xxx.xyz") </script>

回复评论字数限制

// 回复评论字数限制

function Bing_minimal_comment_length( $commentdata ){

$minlength = 5;//评论最少字数

preg_match_all( '/./u', trim( $commentdata['comment_content'] ), $maxlength );

$maxlength = count( $maxlength[0] );

if( $maxlength < $minlength ) wp_die( '评论最少需要 ' . $minlength . ' 字!“哈哈哈哈哈”等复数垃圾回复会被禁止访问' ); return $commentdata; } add_filter( 'preprocess_comment', 'Bing_minimal_comment_length', 8 );

55555_202504 软
66666_202504 T9 
99999_202504 dy-z-v2  
88888_202504 t
CDSs8dkD
3uZEntub

禁用搜索功能

//禁用WordPress前台搜索功能

function disable_search( $query, $error = true ) {

if (is_search() && !is_admin()) {

$query->is_search = false;

$query->query_vars['s'] = false;

$query->query['s'] = false;

if ( $error == true )

// 执行搜索后显示的错误页面

// $query->is_home = true; //跳转到首页

$query->is_404 = true;//跳转到404页

}

}

add_action( 'parse_query', 'disable_search' );

add_filter( 'get_search_form', create_function( '$a', "return null;" ) );

边栏区块代码备份

<!-- wp:search /-->

<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>近期文章</h2><!-- /wp:heading --><!-- wp:latest-posts /--></div><!-- /wp:group -->

<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>近期评论</h2><!-- /wp:heading --><!-- wp:latest-comments {"displayAvatar":false,"displayDate":false,"displayExcerpt":false} /--></div><!-- /wp:group -->

<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>归档</h2><!-- /wp:heading --><!-- wp:archives /--></div><!-- /wp:group -->

<!-- wp:group --><div class="wp-block-group"><!-- wp:heading --><h2>分类</h2><!-- /wp:heading --><!-- wp:categories /--></div><!-- /wp:group -->

上一篇  下一篇

<div id="nav-below" class="navigation">

<div class="nav-previous"><?php next_post_link( '%link', '<span class="meta-nav">' . _x('<i class="icon-arrow-left"></i>' , 'Next post link', 'frontopen' ) . '</span> %title ' ); ?></div>

<div class="nav-next"><?php previous_post_link( '%link', '%title ' . _x(' <i class="icon-arrow-right"></i>' , 'Previous post link', 'frontopen' ) . '' ); ?></div>

</div><!-- #nav-below -->

<nav class="nav-single">

<span class="nav-previous-post"><?php if (get_previous_post()) { previous_post_link('【上一篇】%link','%title',true);} else { echo "【上一篇】没有最早文章了";} ?></span><p></p>

<span class="nav-next-post"><?php if (get_next_post()) { next_post_link('【下一篇】%link','%title',true);} else { echo "【下一篇】没有最新文章了";} ?></span>

</nav>

随机文章

我们希望每次打开网站时,在某个位置生成随机的文章列表,可以通过以下代码实现:

<div class="rnd_list"">
<ul style="list-style:none;">
<?php
$args = array( 'numberposts' => 6, 'orderby' => 'rand', 'post_status' => 'publish' );
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) : ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
</div>

不定时更新备份

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值