700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > digg没落_如何使用自定义字段在WordPress中添加Digg按钮

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

时间:2023-10-10 08:36:05

相关推荐

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

digg没落

You will see that many sites add a digg button within their post content. Some new users simply opensingle.phpand 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 yoursingle.phpand 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 buttonif($digg !== '') { ?><script src="/tools/diggthis.js" type="text/javascript"></script><?php } // end if statement// if there's not a digg buttonelse { echo ''; } ?>

You may wrap it around with any styling that you want. Save thesingle.phpand 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帖子,只需添加一个自定义字段,如下面的屏幕截图所示:

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 )

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

digg没落

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。