@WP程式研究室

[WordPress技術,在前台的每篇文章前加入編輯與刪除功能

Astra : Use content-blog.php (template-parts/content-blog.php) , Add below wording


<?php
/**
 * Template part for displaying posts.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package Astra
 * @since 1.0.0
 */

?>
<?php astra_entry_before(); ?>
<article
<?php
		echo astra_attr(
			'article-blog',
			array(
				'id'    => 'post-' . get_the_id(),
				'class' => join( ' ', get_post_class() ),
			)
		);
		?>
>
	<?php astra_entry_top(); ?>
		<strong><U><?php edit_post_link(__('編輯文章')); ?> </U></strong>
	
	
	<?php $url = get_bloginfo('url'); if (current_user_can('edit_post', $post->ID)){ echo '<a class="delete-post" href="'; echo wp_nonce_url("$url/wp-admin/post.php?action=delete&post=$id", 'delete-post_' . $post->ID); echo '"><strong> | <U>删除文章</U></strong></a>'; } ?>
	
	<?php astra_entry_content_blog(); ?>
	
	<?php astra_entry_bottom(); ?>
</article><!-- #post-## -->
<?php astra_entry_after(); ?>
Astra: Use content-single.php (template-parts/content-single.php) , Add below wording





<?php
/**
 * Template part for displaying single posts.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package Astra
 * @since 1.0.0
 */

?>

<?php astra_entry_before(); ?>

<article
<?php
		echo astra_attr(
			'article-single',
			array(
				'id'    => 'post-' . get_the_id(),
				'class' => join( ' ', get_post_class() ),
			)
		);
		?>
>

	<?php astra_entry_top(); ?>
<strong><U><?php edit_post_link(__('編輯文章')); ?> </U></strong>	
	<?php $url = get_bloginfo('url'); if (current_user_can('edit_post', $post->ID)){ echo '<a class="delete-post" href="'; echo wp_nonce_url("$url/wp-admin/post.php?action=delete&post=$id", 'delete-post_' . $post->ID); echo '"><strong> | <U>删除文章</U></strong></a>'; } ?>

	<?php astra_entry_content_single(); ?>
	
	<?php astra_entry_bottom(); ?>

</article><!-- #post-## -->

<?php astra_entry_after(); ?>
Scroll to Top
%d 位部落客按了讚: