Forums

Trouble ddding a page or most recent post in sidebar (7 posts)

  1. Doug
    Member
    Posted 2 years ago #

    I working on a blog theme for myself and I want to feature the About page in my sidebar. This would just be the opening part, with a read more link at the end. Also, I want to have it check so that if it's on the about page, it instead displays the most recent post.

    So, first I have my content section which goes through The Loop. I've added this code to my sidebar to select the about page.

    <?
    query_posts('page_id=160');//select the about page, ID 160 (don't ask).
    the_post();//start the_post so i can get the info
    ?>
    
    <h2 class="entry-title c5r"><a href="<? the_permalink(); ?>" title="Permanent Link to <? the_title_attribute(); ?>" rel="bookmark"><? the_title();?></a></h2>
    
    <? the_content('Find Out More <span class="meta-nav">></span>'); ?>

    It seems to work except for one crucial thing; the more-link won't work. It's in there, but it won't display, it just prints the whole post, which i don't want.

    And for part 2, I wanted to have it check if it's on the about page, and if so, grab the most recent post info and do that, which I have no idea how to do.

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    The more tag doesn't work on Pages without a template hack. Also I'd suggest using get_posts - not query_posts - and creating a pseudo-more link in the code if necessary.

    Part 2: See Conditional_Tags and again, consider using get_posts.

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

  3. Doug
    Member
    Posted 2 years ago #

    okay, I've used the get_post instead, and just did a substr on post_content to cut it off at the more link and then write it.

    However, I'm having trouble getting part 2 to work. I'm having it check is_single('about') (i checked and that is the slug) but it won't return true. I tried putting that check in the page template and... oh i'll just show you:

    <? the_post();
    if(is_single('about')){
    $is_page="about";
    }?>

    that's on the page.php file, then on the sidebar I have:

    <? if($is_page=="about"){
    echo "Latest Post";
    }else{
    echo "About";
    }?>

    I think I was at least able to get the most recent post part to work in the meantime, but not this page check.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    is_single() only works for a single post page. You're working with Pages, yes?

  5. Doug
    Member
    Posted 2 years ago #

    Yes, I couldn't seem to find any other function that did the same thing for pages.

  6. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Try is_page().

  7. Doug
    Member
    Posted 2 years ago #

    Oh... I missed that one. Well, actually I did notice that, but at a glance I thought it was referring to navigational pages (page 3 of 7 type of thing) not post pages.

    Thanks so much for your help.

Topic Closed

This topic has been closed to new replies.

About this Topic