• Hello,

    I would like to display a specific post OR page within my sidebar so a user could update it every day such as (daily specials). I don’t like a client to have to edit the basic text widget because the styling can break very easily. I’d rather they edited a post/page using the WYSIWYG editor. I installed the “Featured Post Widget” but this is only displaying 3 lines from the post. Is there a way for me to load a “get post” or something like that in my sidebar.php file? I’ve tried a couple solutions I found in the forums and I can’t get any of them to work for me. Is there another solution that would work better? Thanks!

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter InHouse

    (@inhouse)

    I’m sorry but I’m not sure how this would work to display a specific post or page. I could see how this would get a list of posts in a category, but I’d like to only show 1 post all the time. What would I need to add to sidebar.php? This is the first time I’ve really messed with anything like this before. Thanks for replying so quick too!
    <?php get_posts( $args ); ?>

    Thread Starter InHouse

    (@inhouse)

    @esmi, thanks so much for replying, but I’m so confused by this. I’ve read both pages multiple times and I think I learned a little, but what I’ve attempted has not worked. I am placing this in my sidebar.php file and this makes my sidebar disappear.

    <?php get_posts( $query = new WP_Query( 'name=todays-specials' ); ?>

    You use the same queries and some form of the Loop to display posts whether it’s one post or 100 posts.

    Thread Starter InHouse

    (@inhouse)

    Any idea if I’m doing this right and why it’s not working? Seems as though I have the code right, but I’m not sure if that goes in sidebar.php to display in the sidebar or where it should go?

    Thread Starter InHouse

    (@inhouse)

    Also tried <?php get_posts( $query = new WP_Query( 'pagename=todays-specials' ); ?> in sidebar.php and the sidebar is still blank. No background color or anything. Please help! Address is here

    Either use get_posts or WP_Query – not both!

    Thread Starter InHouse

    (@inhouse)

    Ok, so it should be <?php $query = new WP_Query( 'page_id=38' ); ?> or $query = new WP_Query( 'page_id=38' );? I also tried the get_posts to no avail. Can you be more specific? I really appreciate the help. This is all I have in my sidebar:

    <div id="sidebar">
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar-Main') ) { ?>
    
    <?php get_posts( 'pagename=todays-specials' );?>
    
    <?php } ?>
    </div>
    <?php
    $args = array(
    	'page_id' => 38,
    	'posts_per_page' => 1
    );
    $my_pages = get_posts( $args );
    foreach($my_pages as $post) : setup_postdata($post); ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_content(); ?>
    <?php endforeach;
    wp_reset_query();?>
    Thread Starter InHouse

    (@inhouse)

    OMG, I was not even close to getting this to work… I can’t thank you enough. This is by far the most complicated thing I’ve attempted and I’m still a little unclear as to how it works but I will keep learning and now I have an awesome example to follow. Thanks a ton!

    No problem. Once you can understand get_posts, you’ll be able to move onto WP_Query which is even more powerful.

    Thread Starter InHouse

    (@inhouse)

    How would I change this to display a page instead of a post? Page ID=41 so I tried to change that and now nothing is displayed.

    Change 'page_id' => 38, to 'page_id' => 41,

    Thread Starter InHouse

    (@inhouse)

    Right, that’s what I did and nothing was displayed. It isn’t working correctly. I tried various page_id and none work. I thought it was as simple as changing IDs but does something else need to change too?

    If you just want another Page, nothing else needs to change.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Display post/page in sidebar’ is closed to new replies.