【问题标题】:Wordpress add multiple pages to static front pageWordpress 将多个页面添加到静态首页
【发布时间】:2017-01-31 14:26:57
【问题描述】:

如何添加一个静态首页,其中包含放置在部分中的其他页面?

例如 我的静态首页称为首页。除了这个主页,我还有其他三个页面:BioMusicContact。 所有这三个页面都将分配两个自定义字段:add_to_front_page = (Yes/No)priority = int

如果 add_to_front_page 等于 Yes。当前页面将以某种方式添加到静态主页中,如下所示:

Static Front Page = Home
<div class="main">

 <section id="<page title>">
   Bio content <!-- priority 1 -->
 </section>

 <section id="<page title>">
   Music content <!-- priority 2 -->
 </section>

 <section id="<page title>">
   Contact content <!-- priority 3 -->
 </section>

</div>

我正在考虑创建一个仅用于静态首页的页面模板,我需要一些有关如何制作此“页面部分循环”的指导。

我愿意接受其他解决此问题的建议,只要结果保持不变!

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    您可以通过这种方式获取此页面:

    $args = array(
        'posts_per_page'   => -1,
        'meta_key'         => 'priority',
        'orderby'          => 'meta_value_num',
        'order'            => 'ASC',        
        'post_type'        => 'page',       
        'post_status'      => 'publish',
        'meta_query' => array(
            array(
                'key'     => 'add_to_front_page ',
                'value'   => 'Yes',
                'compare' => '=',
            ),
        ),
    
    );
    $pages = get_posts( $args );
    
    
    foreach ( $pages as $page ) {
        $title = $page->post_title;
        $content = wpautop( $page->post_content );
    
    }
    

    你可以把它放在front-page.php,这是静态首页的模板。

    【讨论】:

    • 这项工作.. 在priority 之后缺少, 谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-09
    • 2015-12-18
    • 1970-01-01
    • 2016-08-23
    • 1970-01-01
    • 2014-03-02
    • 2021-11-05
    相关资源
    最近更新 更多