简体   繁体   中英

Wordpress add multiple pages to static front page

How can I add a static front page that will contain other pages placed in sections?

Ex. my static front pages is called Home. In addition to this Home page, I have three other pages: Bio , Music and Contact . All these three pages will each have two custom fields assigned to them: add_to_front_page = (Yes/No) and priority = int .

If add_to_front_page equals Yes. The current page will be added to the static Home page somehow like this:

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>

I am thinking about creating a page template that will be used only on the static front page, and I need some guidance on how to make this "page section loop".

I am open to other suggestions to solve this issue, as long as the result remains the same!

You can get this pages this way:

$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 );

}

And you can place this in front-page.php , which is the template for the static front-page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM