Forums

Retrieve specific page to show at top of sidebar (6 posts)

  1. bobmeador
    Member
    Posted 5 years ago #

    I want to add a "callout" type item at the top of the sidebar (sort of an "About this site" blurb, that'll appear in a styled box). I'm wondering what the best way to do this is.

    I'm thinking I should create a page, then use something that's a cross between query_posts():

    query_posts('pagename=about');

    and get_posts():

    $result = get_posts('pagename=about');

    (though of course that won't work - right?)

    Anyway, I want to retrieve a single page into a result array, then I can display the relevant parts in the sidebar. This way the blog owner can edit the content without having to dive into the template files.

    I'd prefer not to use a plugin - is there some way to do this with standard template tags?

    - Bob

  2. Chris_K
    Member
    Posted 5 years ago #

    Have a look at http://codex.wordpress.org/Template_Tags/bloginfo

    In particular, this example:

    Show Blog Description

    Displays Tagline for your blog as set in the Administration panel under General Options.

    <p><?php bloginfo('description'); ?> </p>

    Would that work?

  3. bobmeador
    Member
    Posted 5 years ago #

    I think the description field might be too "short" - I'm thinking of either a paragraph or a bunch of short lines separated by returns (depending on what the client requests), and probably with a link at the bottom to an actual page with more in-depth "about" info.

    I suppose I could use either a page or a post as the content, as long as I can prevent that page or post from showing up in other lists, categories, archives etc. I just thought that kind of exclusion would be easier with a page (exclude it from "Pages") than a post (which would have to be excluded from multiple places.

    I just wish I knew how to explicitly query and retrieve a page into a PHP array. Guess I could hand-write the query (horrors!)

    mysql_query("SELECT * FROM wp_posts WHERE post_status='Static' AND post_title='about'");

    But that seems so "un-WP-like" :)

  4. Chris_K
    Member
    Posted 5 years ago #

  5. ninjaboy
    Member
    Posted 5 years ago #

    Get a Post is great by the way, I really like it. It would certainly do what you want, and then some! Don't be fooled by the name - Get a Post plugin is able to fetch PAGES as well as posts (pages are pasically posts anyway when it comes to WP and ID's, but lets not get into that!).

    Once I had got this working I wanted a big more flexibility with WP to display different posts and pages - check the link below out on the codex to get started:

    http://codex.wordpress.org/Function_Reference/WP_Query

    I then used something like this:

    
    <?php
    $lastposts = get_posts('numberposts=1&category=1');
    foreach($lastposts as $post) :
    setup_postdata($post);
    ?>
    <a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>" title="Read the full feature '<?php the_title(); ?>'"><?php the_title(); ?></a></h1>
    <?php the_content(''); ?>
    <?php endforeach; ?>
    

    This just gets 1 post (the latest) from category 1 - not what you wanted, but a starting point for code!

  6. bobmeador
    Member
    Posted 5 years ago #

    get_a_post() worked great! Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic