记录日常点点滴滴,欢迎来到我的小站。

0%

使用Wordpress的朋友可能遇到这样的问题,在非single.php页面中我们有时候想要调用当前文章的标题、内容等信息,而Wordpress在生成文章页的时候在各个页面中唯一不变的只有当前的文章ID,那么如何根据这个ID获取到当前文章的标题、内容等信息呢?可以通过下面的代码实现:

1
2
3
4
5
<?php
$id=//这里是文章的ID
$title = get_post($id)->post_title;
echo $title;//输出文章的 标题
?>
阅读全文 »

strip_tags

  去掉 HTML 及 PHP 的标记。
  语法: string strip_tags(string str);
  传回值: 字串
  函式种类: 资料处理
  内容说明
  本函式可去掉字串中包含的任何 HTML 及 PHP 的标记字串。若是字串的 HTML 及 PHP 标签原来就有错,例如少了大于的符号,则也会传回错误。而本函式和 fgetss() 有着相同的功能。
  htmlspecialchars
  将特殊字元转成 HTML 格式。
  语法: string htmlspecialchars(string string);
  传回值: 字串
  函式种类: 资料处理
  本函式将特殊字元转成 HTML 的字串格式 ( &….; )。最常用到的场合可能就是处理客户留言的留言版了。

  & (和) 转成 &
  “ (双引号) 转成 "
  < (小于) 转成 <
  > (大于) 转成 >
  此函式只转换上面的特殊字元,并不会全部转换成 HTML 所定的 ASCII 转换。

使用范例

1
2
3
4
<?php  
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new;
?>

下载地址:
http://pageflipgallery.com/start-download/

http://wordpress.org/plugins/page-flip-image-gallery/

安装与使用方法:(自己翻译的)
1.下载并解压压缩包到/page-flip-image-gallery/ 文件夹.
2.使用FTP工具将“/page-flip-image-gallery/” 文件夹上传到WordPress插件目录中: /wp-content/plugins/.
3.进入WordPress后台,启用“FlippingBook gallery”插件
4.启用后就可以左侧看到“FlippingBook”的设置栏目,在此你可以添加图片集

要想在文本中加入你要显示的图片集可以使用如下代码:
[book id='1' /]
当然安装启用此插件后还会在添加文章的命令按钮栏上自动加入这个按钮。
数字“1”为你要显示的图片集所在ID号

Wordpress导致数据库服务器压力的一个原因是,日志更新的时候,日志履历的调整机能会残留很多的数据。

根据实际自己的服务器进行调查,发现数据库中这类数据相当于正常数据的10被左右。

对于一般用来说,wordpress的这项机能,其实用处不大。所以我们可以通过修改wp-config.php来停止他。

记录机能的完全停止

1
define(‘WP_POST_REVISIONS’, false);

记录机能限制次数

1
define(‘WP_POST_REVISIONS’, 5);

5可以根据自己的需要进行修改。

如果你正在使用Wordpress来做CMS,那么你可能会想要你的网站内容显示多种语言。最近,我看到一个使用 Wordpress 的博客,他的博客内容有三种语言版本展示。所以我决定去研究一下把 Wordpress 变成多语言支持的网站的方法以及插件。

维护一个多语言内容的网站是一件很不容易的事情。展现多语言内容给你的访客的最好的方式就是让访客可以在任何时候自行选择语言并进行切换。所以使用到的插件必须需要关心到这个问题也就是把多语言的网站内容连接起来。

除了创建链接到不同的语言内容,被翻译的内容的 URL 地址也是极其重要的。这里有两种展示 URL 的方式:

你可以提供相同的永久链接给被翻译的内容页面,然后在 URL 结尾部分添加一个标记 (例如: www.domain.com/multi-language-article/?lang=en, www.domain.com/multi-language-article/?lang=es, www.domain.com/multi-language-article/?lang=zh).
被翻译的内容页面将拥有完全不同的 URL 地址。 The
因此,在你创建一个多语言网站之前,如何选择你的 URL 地址方案是另外一个要考虑的主要问题。从 SEO 的角度来看的话,拥有一个绝对不同的唯一地址将获得更大的优势。稍候,我将给你们介绍5个不同的插件来管理你的 Wordpress 多语言网站。这些插件都各有利弊,因此选择一个最好最适合你需求的插件是至关重要的。

阅读全文 »

我们可以利用 wp_is_mobile 函数来进行区分现在浏览的末端是PC还是平板还是手机

1
2
3
4
5
<?php if (wp_is_mobile()): ?>
/*手机及平板表示时*/
<?php else: ?>
/*PC表示时*/
<?php endif; ?>

只在平板和手机时表示

1
2
<?php if (wp_is_mobile()): ?>
<?php endif; ?>

只在PC时表示

1
2
<?php if (!wp_is_mobile()): ?>
<?php endif; ?>

你可以利用Addthis, 本身提供的自定义代码,插入到您的网页,如果你使用的是
wordpress,也可以直接下载对应的插件。 操作非常方便。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!-- facebook -->
<iframe src="//www.facebook.com/plugins/like.php?href=<?php the_permalink() ?>&amp;width=450&amp;height=21&amp;colorscheme=light&amp;layout=button_count&amp;action=like&amp;show_faces=false&amp;send=false&amp;appId=1405102389709799" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true"></iframe>

<!-- twitter -->
<a href="https://twitter.com/share" class="twitter-share-button" data-url="<?php the_permalink() ?>" data-via="" data-lang="en">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

<!-- Google -->

<!-- Place this tag where you want the share button to render. -->
<div class="g-plus" data-action="share" data-annotation="bubble"></div>

<!-- Place this tag after the last share tag. -->
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>

<!-- Pinterest -->

<a href="//pinterest.com/pin/create/button/?url=<?php the_permalink() ?>&media=&description=<?php the_title(); ?>" data-pin-do="buttonPin" data-pin-config="beside"><img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" /></a>
<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>

<!-- StumbleUpon -->
<!-- Place this tag where you want the su badge to render -->
<su:badge layout="1" location="<?php the_permalink() ?>"></su:badge>

<!-- Place this snippet wherever appropriate -->
<script type="text/javascript">
(function() {
var li = document.createElement('script'); li.type = 'text/javascript'; li.async = true;
li.src = ('https:' == document.location.protocol ? 'https:' : 'http:') + '//platform.stumbleupon.com/1/widgets.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(li, s);
})();
</script>

<!-- tumblr -->
<script src="http://platform.tumblr.com/v1/share.js"></script>
<a href="http://www.tumblr.com/share" title="Share on Tumblr" style="display:inline-block; text-indent:-9999px; overflow:hidden; width:61px; height:20px; background:url('http://platform.tumblr.com/v1/share_2.png') top left no-repeat transparent;">Share on Tumblr</a>

<!-- In -->
<script src="//platform.linkedin.com/in.js" type="text/javascript">
lang: en_US
</script>
<script type="IN/Share" data-url="<?php the_permalink() ?>" data-counter="right"></script>