get page title, url and excerpt of a page

I have the following setup: the front-page is setup as ‘static’ and it uses a theme page template. On this template / front-page, I need to get the page title, URL and excerpt of the About page.

I found this code that does exactly what I need, but I’m wandering if there’s a different approach to this, one that would not use the page ID but the page slug or title.

Read More
<?php
    $page_id = 13;
    $page_data = get_page( $page_id );
    $the_excerpt = $page_data->post_excerpt;
    $title = $page_data->post_title;
?>
<a href="<?php echo get_permalink(13); ?>">
    <?php echo $page_data->post_title; ?>
</a>

Later edit: Based on the answer provided by peteroak, this is the complete working code:

<?php
    $page = get_page_by_title( 'About' );
    $the_excerpt = $page->post_excerpt;
    $page_data = get_page( $page );
    $title = $page_data->post_title;
?>
<header class="entry-header">
    <h1 class="entry-title">
        <a href="<?php echo esc_url( get_permalink( get_page_by_title( 'About' ) ) ); ?>">
            <?php echo $page_data->post_title; ?>
        </a>
    </h1>
</header>   
    <div class="entry-content"><?php echo $page->post_excerpt; ?>
        <a href="<?php echo esc_url( get_permalink( get_page_by_title( 'About' ) ) ); ?>">more +</a>
    </div>

Related posts

Leave a Reply

2 comments