digg没落_如何使用自定义字段在WordPress中添加Digg按钮

digg没落

You will see that many sites add a digg button within their post content. Some new users simply open single.php and add the digg script which will cause a digg button to show on all blog posts. But what if you want to display digg button on only specific posts? You can add it manually on each post when writing a post, but that is not the most efficient way. In this article we will show you, how you can add a digg button on specific posts by simply using Custom fields.

您会看到许多网站在其帖子内容中添加了一个digg按钮。 一些新用户只需打开single.php并添加digg脚本,这将导致digg按钮显示在所有博客文章上。 但是,如果您只想在特定帖子上显示digg按钮,该怎么办? 您可以在撰写帖子时在每个帖子上手动添加它,但这不是最有效的方法。 在本文中,我们将向您展示如何通过使用“自定义”字段在特定帖子上添加digg按钮。

First open your single.php and find a code that looks like this:

首先打开您的single.php并找到如下代码:


<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

Replace it with:

替换为:


<?php if (have_posts()) : while (have_posts()) : the_post();
// check for digg button for single page
$digg = get_post_meta($post->ID, 'Digg', $single = true);
?>

Now you need to add the following code within the loop anywhere you like:

现在,您需要在循环中的任意位置添加以下代码:


<?php // if there's a single page digg button
if($digg !== '') { ?>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
<?php } // end if statement
// if there's not a digg button
else { echo ''; } ?>

You may wrap it around with any styling that you want. Save the single.php and upload it to your theme folder.

您可以将其包装为所需的任何样式。 保存single.php并将其上传到主题文件夹。

Now when writing a post if you want to add a digg post simply add a custom field like shown in the screen shot below:

现在,在编写帖子时,如果要添加Digg帖子,只需添加一个自定义字段,如下面的屏幕截图所示:

Add a Digg Button in Your WordPress using Custom Field

Whenever you specify this custom field, WordPress will display a digg button on your post like this one:

每当您指定此自定义字段时,WordPress都会在您的帖子上显示如下所示的digg按钮:

Check out this example (Live)

看看这个例子( Live )

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-add-a-digg-button-in-your-wordpress-using-custom-fields/

digg没落

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值