• Resolved idimitriadis

    (@idimitriadis)


    Hello,

    I have set an empty page (just the title) as a static home page.
    I would now like to have the home page display a random ‘page'(not post) within a specified range of page IDs (lets say from 1 to 10).

    If I understood correctly, I could add some code in index.php for that:

    https://pastebin.com/jsMexdK6

    I have some hard time figuring out what code I could use to pull that ‘functionality’? (no plugin found, and most content concerns posts, and does not cover a specified range of page or post IDs)

    Any pointer is welcome! ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • Create a front-page.php template, and use get_posts:

    <?php
    $args = array( 'post_type' => 'page', 'numberposts' => 1, 'orderby' => 'rand' );
    $rand_posts = get_posts( $args );
    foreach( $rand_posts as $post ) : ?>
    	<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            <?php the_content(); ?>
    <?php endforeach; ?>
    Thread Starter idimitriadis

    (@idimitriadis)

    Thank you for your quick reply Triple P ??

    I created a front-page.php that I uploaded in my theme’s folder (took a page template that seemed suited and added the code above).

    It does indeed now pull randomly one of the pages I have created!

    However, it shows only the title of the page as a link, it is not fully displayed, one has to click on the title to get to view that page’s content.

    Also, I’d like to include only a certain range of pages (page IDs from 1 to 10), I’ll have to search a little more for that.

    Any further help in these direction appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘how to display a random page in a static front page’ is closed to new replies.