前台显示编辑链接-WordPress主题开发

一个让你更方便的方法,

edit_post_link:

显示发布的编辑帖子链接。

https://developer.wordpress.org/reference/functions/edit_post_link/

get_edit_post_link:

检索发布的编辑帖子链接。

https://developer.wordpress.org/reference/functions/get_edit_post_link/

添加于博文循环函数内

把它放在你输出the_content()附近的主题文件中(可能在single.php或page.php文件中),以创建一个链接,你可以点击它进入管理员进行编辑。此链接仅在查看者登录并且具有编辑该页面(管理员或作者)的适当权限时才可见。

<?php edit_post_link(__('Edit This')); ?>

 有编辑权限的人(超级管理员,管理员,编辑,作者),显示编辑按钮:(推荐,来源于官方2019主题)

wp-content\themes\twentynineteen\template-parts\content\content-page.php

第34行

<?php if ( get_edit_post_link() ) : ?>
		<footer class="entry-footer">
			<?php
			edit_post_link(
				sprintf(
					wp_kses(
						/* translators: %s: Name of current post. Only visible to screen readers */
						__( 'Edit <span class="screen-reader-text">%s</span>', 'twentynineteen' ),
						array(
							'span' => array(
								'class' => array(),
							),
						)
					),
					get_the_title()
				),
				'<span class="edit-link">',
				'</span>'
			);
			?>
		</footer><!-- .entry-footer -->
	<?php endif; ?>

 WordPress编辑文章链接标签:edit_post_link

来源于:

https://www.beizigen.com/1687.html

WordPress模板标签edit_post_link用于输出编辑文章的链接,必须用在The Loop主循环中。

edit_post_link( string $text = null, string $before = '', string $after = '', integer $id = 0, string $class = 'post-edit-link' )

函数参数

$text

字符串值,默认为空

链接的锚文本

$before

字符串值,默认为空

在链接前输出的文本

$after

字符串值,默认为空

在链接后输出的文本

$id

整数型,默认值:0

指定文章ID,输出该文章的编辑链接。

$class

字符串值,默认值:post-edit-link

链接的类名

edit_post_link()函数使用示例

', ''); ?>

扩展阅读

edit_post_link()函数位于:wp-includes/link-template.php

相关函数:

参考:

前台显示编辑链接-WordPress主题开发-Npcink
前台显示编辑链接-WordPress主题开发-Npcink

不同的用户,不同的权限-WordPress开发

About:

 if( current_user_can('administrator') ) {
echo '  •  编辑';}
Typecho

Krait Major - 原创Typecho主题

2020-2-11 23:50:00

软件

Visual Studio Code - 强大而免费的代码编辑工具

2019-3-15 17:08:06

⚠️
Npcink上的部份代码及教程来源于互联网,仅供网友学习交流,若您喜欢本文可附上原文链接随意转载。
无意侵害您的权益,请发送邮件至 1355471563#qq.com 或点击右侧 私信:Muze 反馈,我们将尽快处理。
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索