• Resolved lhoylhoy

    (@lhoylhoy)


    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.

Viewing 13 replies - 1 through 13 (of 13 total)
  • look at get_post https://codex.www.ads-software.com/get_post

    You add that code into your sidebar file

    Thread Starter lhoylhoy

    (@lhoylhoy)

    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?

    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.

    Thread Starter lhoylhoy

    (@lhoylhoy)

    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!

    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
    https://www.ads-software.com/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>";
    ?>

    Thread Starter lhoylhoy

    (@lhoylhoy)

    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.

    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>";
    ?>
    Thread Starter lhoylhoy

    (@lhoylhoy)

    thanks man! i’ll mark it resolved!

    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?

    @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.

    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?

    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!

    Ian

    (@ianaleksander)

    this worked for me also. I used the “executable php widget” plugin so I could paste the code directly in there and drag and drop it to organize.

    came out great ??

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Display ‘About’ page content/title in sidebar’ is closed to new replies.