wordpress插入代码_如何将WordPress页面内容插入另一个页面或发布

本文介绍了一种方法,通过安装并使用'Insert Pages'插件,允许用户在WordPress中将一个页面或自定义帖子类型的内容插入到另一个帖子、页面或自定义类型中,包括使用自定义模板来调整显示样式。
摘要由CSDN通过智能技术生成

wordpress插入代码

Recently one of our users asked if it was possible to add content from a WordPress page into another post or page. In this article, we will show you how to insert content from one WordPress page to another post, page, or any custom post types.

最近,我们的一位用户询问是否可以将WordPress页面中的内容添加到另一个帖子或页面中。 在本文中,我们将向您展示如何将内容从一个WordPress页面插入到另一个帖子,页面或任何自定义帖子类型。

First thing you need to do is install and activate the Insert Pages plugin. Upon activation simply go to Posts » Add New to see it in action.

您需要做的第一件事是安装并激活“ 插入页面”插件。 激活后,只需转到帖子»添加新内容即可查看其运行情况。

If you use visual editor, then you will notice a new button labeled ‘Insert Page’ in the menu.

如果您使用可视化编辑器 ,那么您会在菜单中注意到一个标记为“插入页面”的新按钮。

Insert page button in the visual editor

Clicking on it will bring up a popup where you can select the page, post, or custom post type you want to add.

单击它会弹出一个弹出窗口,您可以在其中选择要添加的页面,帖子或自定义帖子类型。

Insert page popup

You can choose how you would like to insert the post/page by clicking on the Options. By default you can add title, content, link, or choose a custom template. We will explain custom templates later in this article.

您可以通过单击选项来选择插入帖子/页面的方式。 默认情况下,您可以添加标题,内容,链接或选择自定义模板。 我们将在本文后面解释自定义模板。

After choosing the post/page click on the Insert Page button. The plugin will add the shortcode required to display your selected post/page.

选择帖子/页面后,单击“ 插入页面”按钮。 插件将添加显示所选帖子/页面所需的简码。

If you use the text editor to write your posts, then you can manually enter the shortcode. The shortcode parameters are quite simple.

如果使用文本编辑器编写帖子,则可以手动输入简码。 简码参数非常简单。

[insert page='page-slug|ID' display='title|link|content|all|custom-template.php']

[insert page='page-slug|ID' display='title|link|content|all|custom-template.php']

The page parameter for the shortcode accepts page-slug or ID. Please note that by page slug, it doesn’t mean that you can only enter pages. You can add any post or custom post type’s slug as well.

简码的page参数接受page-slug或ID。 请注意,按页面提示,这并不意味着您只能输入页面。 您也可以添加任何帖子或自定义帖子类型的子句。

You can also use post id. Here is a quick guide on how to find post id in WordPress.

您也可以使用帖子ID。 这是有关如何在WordPress中查找帖子ID的快速指南。


[insert page='author-syed-balkhi' display='content']
[insert page='128' display='content']
[insert page='128' display='all']
[insert page='128' display='custom-author.php']


[insert page='author-syed-balkhi' display='content']
[insert page='128' display='content']
[insert page='128' display='all']
[insert page='128' display='custom-author.php']

在帖子中添加自定义帖子类型 (Adding Custom Post Types into Posts)

Using WordPress you can add any type of content by creating post types for different content types. Checkout our guides on when do you need a custom post type and how to create a custom post type in WordPress.

使用WordPress,您可以通过为不同的内容类型创建帖子类型来添加任何类型的内容。 查阅我们的指南,了解何时需要自定义帖子类型以及如何在WordPress中创建自定义帖子类型

Insert Pages allows you to add your custom post types into posts and pages. For example, you can create a custom post type for image galleries and then use Insert Pages to add those galleries into your posts or pages.

插入页面允许您将自定义帖子类型添加到帖子和页面中。 例如,您可以为图像画廊创建自定义帖子类型,然后使用“插入页面”将这些画廊添加到您的帖子或页面中。

A custom gallery post type added into a WordPress post

Similarly, you can create custom post types for videos, portfolio, client testimonials, etc. to add into your pages or posts.

同样,您可以为视频,作品集,客户推荐等创建自定义帖子类型,以添加到您的页面或帖子中。

使用自定义模板显示插入的页面 (Using Custom Templates to Display Inserted Pages)

Insert Pages allows you to display title, link, content, or all fields for inserted pages. However some users may still need to tweak the display to meet their own needs. This can be achieved by using custom templates.

插入页面允许您显示标题,链接,内容或插入页面的所有字段。 但是,某些用户可能仍需要调整显示以满足他们自己的需求。 这可以通过使用自定义模板来实现。

All you need to do is create a blank php file and upload it to your theme directory. You can name the file anything you want. For example, custom-author.php.

您需要做的就是创建一个空白php文件并将其上传到您的主题目录。 您可以根据需要命名文件。 例如,custom-author.php。

This custom template works exactly like any other content template files in your theme. Here is sample template file that we created to display author pages.

此自定义模板的工作原理与主题中的任何其他内容模板文件完全相同。 这是我们创建的用于显示作者页面的示例模板文件。


<?php the_post(); ?>
<h3 class="author-name"><?php the_title(); ?></h3>
<?php if ( has_post_thumbnail() ) : ?>
<div class="author-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<?php endif; ?>
<div class="author-bio">
<?php the_content() ?>
</div>

You can use custom CSS classes in your template file and then style them in your theme’s stylesheet. We used this to style the display of author pages.

您可以在模板文件中使用自定义CSS类,然后在主题的样式表中对其进行样式设置。 我们使用它来设置作者页面的显示样式。



h3.author-name { 
font-size:16px;
}
.author-thumbnail { 
float:left;
padding:10px;
} 
.author-bio { 
font-style:italic; 
font-family: Lora, Georgia, Serif;
} 

This is how the end result looked on our dummy site:

这是最终结果在我们的虚拟站点上的样子:

Author bio page inserted into a WordPress post

We hope this article helped you add content from one WordPress page/post to another.

我们希望本文能帮助您将内容从一个WordPress页面/帖子添加到另一个页面。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Google+.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterGoogle+上找到我们。

翻译自: https://www.wpbeginner.com/plugins/how-to-insert-wordpress-page-content-to-another-page-or-post/

wordpress插入代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值