doujia1871 2013-09-02 18:06
浏览 16
已采纳

我可以动态地将一页的摘录放入另一页的正文中吗?

The theme I am using has a page called 'home' whos body is displayed on the home page. I have another page set up called 'about' which is a detailed about page and quite long. I want there to be text on the homepage that is a short synopsis of the about page. I have this synopsis in the excerpt of the 'about' page. Is there a way for me to use that excerpt in the body of the 'home' page?

By doing it this way I can tell the client that all the about information is in one page instead of telling him to go to different pages to edit things that are directly related.

edit: I want to do it without editing the themes code so through the admins page editor

  • 写回答

2条回答 默认 最新

  • dongyi6845 2013-09-02 18:40
    关注

    Rather than using "include", you could use the following to get the page excerpt of the about page and stick with native wordpress functionality:

    $about = get_page_by_title( 'ABOUT_TITLE' );
    $about_excerpt = $about->post_excerpt;
    

    Then you can echo it into your theme template using:

    <?php echo $about_excerpt; ?>
    

    If you wanted to do this within the Wordpress backend, you would create a custom shortcode and wrap the above into a function to be called by that shortcode. Then you could put that shortcode wherever you wanted on any post/page.

    EDIT:

    Here is an example of doing this via shortcode so that you can use this for the About page or any other page with an excerpt within Wordpress:

    add_shortcode( "Excerpt", 'nb_excerpt_shortcode' );
    function nb_excerpt_shortcode( $atts, $content = null ) {
    extract( shortcode_atts( array(
        'for' => ''
    ), $atts) );
    $page = get_page_by_title( $for );
    $excerpt = $page->post_excerpt;
    
    return $excerpt;
    }
    

    Then call it into action with [Excerpt for="About" /]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗