WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Include content of a static page on the main blog page? (9 posts)

  1. StrangeAttractor
    Member
    Posted 6 years ago #

    I guess this is a variation of the "sticky post" idea, but I'm having trouble turning up info in my searches.

    I'd like to have a static announcement at the top of my blog page, before the start of the loop. I'd like this to be something can be editable and changed through the wp-admin, so I want it to be the content of a page or a post.

    Also I'd like to be able to style this announcment via the stylesheet (so perhaps I'd put it in its own div).

    I'm thinking along the lines of inserting the content of a page (as opposed to a post) because the function is more like a page -- something that would be edited once in a while, but would mostly be static.

    Is there a way to stick the content of a page in before the loop starts? I've been looking at the template tags but not sure how I'd call up a page.

  2. moshu
    Member
    Posted 6 years ago #

    I used this plugin several times when I needed exactly what you described above:
    http://guff.szub.net/2005/01/27/get-a-post/

  3. StrangeAttractor
    Member
    Posted 6 years ago #

    Thanks, Moshu! That looks it would be ideal for what I want to do.

    I'll try it out and see how it works.

  4. mundgerecht
    Member
    Posted 6 years ago #

    <? $my_id = 3; $post_id_7 = get_post($my_id); print $title = $post_id_7->post_content; ?>

    i use this in teh template to include the post3 or page3 with $my_id = 3;

  5. StrangeAttractor
    Member
    Posted 6 years ago #

    Thanks mundgerecht.

    I am still testing out solutions. I will come back and post what worked for me.

  6. boober
    Member
    Posted 6 years ago #

    i use this http://guff.szub.net/2006/04/12/welcome-visitor/

    thats how i put the three category image links at the top of my home page. you can put text, images, whatever. its styled through its own style in my style sheet. the page where you edit the content looks just like a post page.

  7. StrangeAttractor
    Member
    Posted 6 years ago #

    Thanks boober -- that also looks like a great option. I notice it's made by the same author as the plugin recommended by Moshu.

    I appreciate all the responses from everyone to my question, and it's great to have several options.

  8. StrangeAttractor
    Member
    Posted 6 years ago #

    Thank you all for your help.

    I'm installing this for a client, so needed a solution that was both user-friendly and flexible (because I needed to be able to heavily style the intro area).

    The "Welcome visitor" plugin recommended by Boober was promising because of being integrated into the admin panel, but was not flexible enough for my purposes.

    The best solution turned out to be Moshu's recommendation of the "Get a Post" plugin -- user friendly because it can also get pages (and the client can edit the page like any other), but flexible because it allows me to control where it appears on templates, and I can wrap it up in divs, etc.

    Thanks again, everyone.

  9. StrangeAttractor
    Member
    Posted 6 years ago #

    I thought I would add a little extra about what I did, for anyone interested in doing the same thing.

    Goals:

    1) On a site where the blog is the home page, I wanted to have a intro "Welcome" section before the blog posts which could be surrounded with divs, etc. so that I could style it with CSS.

    2) Also, I wanted this intro to appear ONLY on the main page of the site, and if users clicked the "blog" link on the pages nav menu, they would not see the intro (because if they are on the site, they have already seen it). To restate this: even though the home page IS the blog page, I only wanted them to see the intro when first arriving at the site, but not when clicking on "blog" (or for that matter on "previous entries" at the bottom of the home page).

    This is what I did:

    1) installed get-a-post plugin (see Moshu's post above for link)

    2) put this code before the loop on my home.php template:

    <?php get_a_post(16); //this uses the get_a_post plugin to pull up a page with id=16, which contains my Welcome entry ?>
    
    <!-- this area pulls up the title and content of entry, and is surrounded with divs that allow me to style the entry with background images etc. via the stylesheet  -->
    
    <div id="welcome">
          <div>
    	  <h3><span><?php the_title(); ?></span></h3>
    	  <?php the_content(); ?>
          </div>
         <div class="welcome_footer"></div>
    </div>
    
    <!-- Normal WordPress loop goes under here  -->

    3) Problem: the intro shows up on every page of the blog. I only want it on the first page, and also, I don't want it to show when someone clicks the "blog" link on the pages menu (which goes to www.mysite.com/blog/).

    Solution: Make sure that only page the intro shows up on is the naked URL of the WordPress site (e.g. www.mysite.com or www.mysite.com/wordpress/ but NOT www.mysite.com/blog/ or www.mysite.com/wordpress/blog/ etc.).

    Found the code for this on a post on Kolossus Interactive, which uses $_SERVER[’REQUEST_URI’] to compare the location of the site to the url pulled up by get_bloginfo('url').

    4) So now the whole thing looks like this (I've removed some of the annotation from the code above for brevity):

    <?php
    $request_loc = 'http://www.mysite.com';
    $request_loc .= $_SERVER['REQUEST_URI']; //request_uri is a relative url
    $blog_loc = get_bloginfo('url');
    $blog_loc .= '/'; //wordpress' blog url variable has no trailing slash, so add it
    ?>
    
    <?php if ( $request_loc == $blog_loc ): ?>
    
       <?php get_a_post(16); ?>  
    
       <div id="welcome">
    
           <div>
    	   <h3><span><?php the_title(); ?></span></h3>
    	   <?php the_content(); ?>
    	</div> 
    
            <div class="welcome_footer"></div>
    
       </div>
    
    <?php endif; ?>
    
    <!-- Normal WordPress loop goes under here  -->

    It works - the intro will show up ONLY if the user is on the home page, but not on the blog's paged "previous entries" nor if the user clicks "blog" from the pages menu.

    There may be simpler ways of doing this, but this worked for me.

Topic Closed

This topic has been closed to new replies.

About this Topic