Forums

[resolved] Display 'About' page content/title in sidebar (13 posts)

  1. lhoylhoy
    Member
    Posted 7 months ago #

    hello, I just want to display my 'About' page content/title in sidebar so I just have to edit it at the dashboard not in the html. thanks.

  2. stvwlf
    Member
    Posted 7 months ago #

    look at get_post http://codex.wordpress.org/get_post

    You add that code into your sidebar file

  3. lhoylhoy
    Member
    Posted 7 months ago #

    hi stvwlf, where can i find my page id? i'm using dif. permalink display does that mean i have to my dashboard and change it so i can see the id? is there any other way to see your page id?

  4. stvwlf
    Member
    Posted 6 months ago #

    Hi - To find the page ID, go to the page edit screen that lists all the pages. Point at the name of the page you want. While pointing, look in the lower left corner of browser window at the status line - there you will see a URL - the page ID is at the end of that URL.

    Not very intuitive, I know.

  5. lhoylhoy
    Member
    Posted 6 months ago #

    but i happened to change my permalinks display what i'm seeing is mysite/about until i went to my dashboard and reformat to show mysite/p=n. What i wanna know is, if there's any other way to know your page-id without having to change the format of your permalink.

    and another thing how do i implement that function you just gave me earlier. Please give me exact working example, I already know my page id. thanks!

  6. stvwlf
    Member
    Posted 6 months ago #

    You do not need to change your permalinks to see the page ID at the bottom of the browser on the status bar. The last part of the URL says "post ID".

    You can also install a plugin
    http://wordpress.org/extend/plugins/reveal-ids-for-wp-admin-25/ that adds a column for ID on post and page edit page

    put in sidebar where you want About page output

    <?php
    $about_id = 2; // substitute page_id of about for "2"
    $about_page = get_post($about_id);
    echo "<p>$about_page->post_content</p>";
    ?>
  7. lhoylhoy
    Member
    Posted 6 months ago #

    it worked!!! thanks!

    But how can i make it dynamic? I'm just porting a theme for a client and I understand that the page_id # is variable right? Please don't get tired of me, thanks again.

  8. stvwlf
    Member
    Posted 6 months ago #

    This will display the post content of a page with a slug of 'about'

    <?php
    $about_page = get_page_by_title('about');
    echo "<p>$about_page->post_content</p>";
    ?>
  9. lhoylhoy
    Member
    Posted 6 months ago #

    thanks man! i'll mark it resolved!

  10. ohbrooke
    Member
    Posted 6 months ago #

    I am trying to do this too, but I want just the first 5 lines to show, or use the "more" link to create the break. Any idea how to do that?

  11. stvwlf
    Member
    Posted 6 months ago #

    @ohbrooke

    You need to set up a loop in the sidebar so you can use the "more" link. This code worked:

    <?php
    global $more;
    $about = new WP_Query();
    $about->query('pagename=about');
    while ($about->have_posts()) : $about->the_post();
       $more = false;   // set $more to false to only get the first part of the post ?>
       <p><?php the_content('Read the rest...'); ?></p>
    <?php endwhile;
    $more = true;   // restore default $more behavior
    ?>

    if you are including a post, not a page, change pagename= to name= In either case the name is the slug, not the post/page title.

  12. jonperry
    Member
    Posted 6 months ago #

    This is great stuff! It's just what I needed.

    I'm having one problem though, my sidebar is not putting <p> tags on the page when it's displayed in the sidebar. Is there a loop to fix that?

  13. ohbrooke
    Member
    Posted 5 months ago #

    BINGO! Thanks stvwlf!

    In my case, the page name was "winners" so I changed
    $about->query('pagename=about');

    to

    $about->query('pagename=winners');

    it's working great - thank you!

Reply

You must log in to post.

About this Topic

Tags

No tags yet.