如何在 Wordpress 中显示页面摘录 [英] How to display page excerpt in Wordpress

查看:25
本文介绍了如何在 Wordpress 中显示页面摘录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Wordpress 的新手,我创建了一个页面,其中包含一长串项目.

I am new in using Wordpress, I created a page that contains a long list of items.

* Item 1
* Item 2
* Item 3
* Item 4 ... and so on

我打算在单独的页面上嵌入带有一长串项目的页面.我该怎么做?我在网上学习了教程,并想到将这段代码 add_post_type_support( 'page', 'excerpt' ); 放在 functions.php 上.放置代码后,创建/编辑页面时将提供一个新选项.但在那之后,我怎样才能显示我的页面摘录?

I am planning to embed this page with long list of items on a separate page. How am I going to do it? I followed tutorials online and got the idea of putting this piece of code add_post_type_support( 'page', 'excerpt' ); on functions.php. After putting the code, an new option will be available when you create/edit pages. But after that, how can I display the my page excerpt?

推荐答案

先把这段代码放到你的主题function.php文件中.

First to put this code on your theme function.php file.

add_action( 'init', 'my_add_excerpts_to_pages' );
function my_add_excerpts_to_pages() {
     add_post_type_support( 'page', 'excerpt' );
}

启用页面摘录后,请参阅下面的定义图像:

After that enable excerpt for page see below define image:

使用此代码获取页面摘录:

Using this code to get page excerpt:

<?php echo get_the_excerpt(); ?>

<?php 
    query_posts("page_id=36");
    while ( have_posts() ) : the_post()
?>
    <h1><a href="<?php echo the_permalink(); ?>"><?php echo get_the_title(); ?></a></h1>
    <?php the_excerpt(); ?>

<?php
    endwhile; 
    wp_reset_query();
?>      

这篇关于如何在 Wordpress 中显示页面摘录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆