WordPress.org

Ready to get started?Download WordPress

Forums

Display post on homepage sidebar (4 posts)

  1. mcdesign
    Member
    Posted 1 year ago #

    I want my client to be able to post text to the sidebar on the homepage only. Ideally, it would be great to have them be able to add a readmore tag and only show intro text on the homepage.

    I know i personally would be able to fake this with the text widget. But there's no editor in the widget, so the client would not be able to format the text or add links without learning html.

    I tried the category post widget, thinking the client could format a post in a category and display it with the widget, but the formatting is stripped out.

    Can anyone help?

  2. Henry
    Member
    Posted 1 year ago #

    One approach would be to display a snippet of text from a page using the get_page function. http://codex.wordpress.org/Function_Reference/get_page

    Example:

    <?php $page_id = 7;
    
    $page_data = get_page( $page_id ); 
    
    echo '<h2>'. $page_data->post_title .'</h2>';
    
    echo apply_filters('the_excerpt', $page_data->post_excerpt); ?>

    You could then link to the page using simple HTML.

    <a href="http://example.com/page-url" title="Read more">Read more</a>

  3. mcdesign
    Member
    Posted 1 year ago #

    Where would that snippet go? And how would it work on the homepage only?

  4. Henry
    Member
    Posted 1 year ago #

    Assuming that you have set your homepage to 'a list of posts' in WordPress Admin then put the snippet in your theme's home.php file. This is the template for your homepage.

    Note: Be sure to change the page_id in my example to the actual page you will be using.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.