• What would be the best way to import pages/posts by id to my index and which would be better?

    Posts or Pages?

Viewing 8 replies - 1 through 8 (of 8 total)
  • I don’t understand. By “index” to you mean your blog’s front page, or do you mean a non-WordPress page?

    Please clarify what you are trying to do.

    Thread Starter Mobster

    (@mobster)

    I am trying to import small posts into various blocks on by “home” Word Press page.

    I would like to be able to edit a post or pages, import the posts/pages by id so the information displays in various blocks or <div>’s on my themes home page.

    Make sense?

    Yep, that makes sense. You’ll want to use Template_Tags/query_posts to grab the specific posts you want before your loop starts.

    Thread Starter Mobster

    (@mobster)

    Well… so far so good… I have experimented with this but the content repeats itself over and over… I’m kind of a SQL noob. How do I close the query after it retrieves the information.

    Thread Starter Mobster

    (@mobster)

    Thanks adamrbrown for the direction… custom query strings are freak’n awesome!

    I just have one little question.

    Is there a way to a “read more” and limit the amount of words to query using the_excerpt();

    Preferably without a plugin… thanks again

    Thread Starter Mobster

    (@mobster)

    Actually, I’m trying to do the very thing you have on your page.

    the_excerpt(); with limited text? how did you do that?

    Thanks

    Mobster, this here works great. I have a Revolution City theme by Brian Gardner (currently under construction). Here’s part of the css for the homepage from style.css

    #homepageleft {
    float: left;
    width: 290px;
    margin: 0px;
    padding: 0px;
    }

    .featured {
    background: #FFFFFF;
    float: left;
    width: 270px;
    margin: 0px 0px 20px 0px;
    padding: 10px 10px 10px 10px;
    border: 1px dotted #94B1DF;
    }

    .featured img {
    border: none;
    margin: 0px;
    }

    #homepageright {
    float: right;
    width: 290px;
    margin: 0px;
    padding: 0px;
    }

    I’m pulling pages, not posts. The first page or parent is pulled by id. The 2 subsequent child pages are pulled by page/child-page.

    <div id="homepageleft">
    
    			<!--This section is currently pulling category ID #1, and can be switched by changing the cat=1 to show whatever category ID you would like in this area.-->
    
    			<div class="featured">
    			<h5>Arizona Homes & Real Estate</h5>
    
    				<!--This is where the thumbnails are found for the homepage bottom section - note the custom field name for this image is "thumbnail". Recommended image size is 70x70, as the stylesheet is written for this size.-->
    
    				<?php query_posts('page_id=33');
                                    while (have_posts()) : the_post(); ?>
                                    <?php if( get_post_meta($post->ID, "thumbnail", true) ): ?>
    				    <a href="<?php the_permalink() ?>" rel="bookmark"><img style="float:left;margin:0px 10px 0px 0px;" src="<?php echo 
    
    get_post_meta($post->ID, "thumbnail", true); ?>" alt="alt text" /></a>
    				<?php else: ?>
    				   	<a href="<?php the_permalink() ?>" rel="bookmark"><img style="float:left;margin:0px 10px 0px 0px;"  src="<?php 
    
    bloginfo('template_url'); ?>/images/thumbnail.jpg" alt="Default thumbnail" /></a>
    				<?php endif; ?>
    				<b><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></b>
    				<?php the_content_limit(80, ""); ?>
    
    				<div style="border-bottom:1px dotted #94B1DF; margin-bottom:10px; padding:0px 0px 10px 0px; clear:both;"></div>
    
    				<?php endwhile; ?>
    
                                    <?php query_posts('pagename=arizona/arizona-homes');
                                    while (have_posts()) : the_post(); ?>
                                    <?php if( get_post_meta($post->ID, "thumbnail", true) ): ?>
    				    <a href="<?php the_permalink() ?>" rel="bookmark"><img 
    
    style="float:left;margin:0px 10px 0px 0px;" src="<?php echo get_post_meta($post->ID, "thumbnail", 
    
    true); ?>" alt="alt text" /></a>
    				<?php else: ?>
    				   	<a href="<?php the_permalink() ?>" rel="bookmark"><img 
    
    style="float:left;margin:0px 10px 0px 0px;"  src="<?php bloginfo('template_url'); 
    
    ?>/images/thumbnail.jpg" alt="Default thumbnail" /></a>
    				<?php endif; ?>
    				<b><a href="<?php the_permalink() ?>" rel="bookmark"><?php 
    
    the_title(); ?></a></b>
    				<?php the_content_limit(80, ""); ?>
    
    				<div style="border-bottom:1px dotted #94B1DF; margin-bottom:10px; 
    
    padding:0px 0px 10px 0px; clear:both;"></div>
    
    				<?php endwhile; ?>
    
                                    <?php query_posts('pagename=arizona/arizona-real-estate');
                                    while (have_posts()) : the_post(); ?>
                                    <?php if( get_post_meta($post->ID, "thumbnail", true) ): ?>
    				    <a href="<?php the_permalink() ?>" rel="bookmark"><img 
    
    style="float:left;margin:0px 10px 0px 0px;" src="<?php echo get_post_meta($post->ID, "thumbnail", 
    
    true); ?>" alt="alt text" /></a>
    				<?php else: ?>
    				   	<a href="<?php the_permalink() ?>" rel="bookmark"><img 
    
    style="float:left;margin:0px 10px 0px 0px;"  src="<?php bloginfo('template_url'); 
    
    ?>/images/thumbnail.jpg" alt="Default thumbnail" /></a>
    				<?php endif; ?>
    				<b><a href="<?php the_permalink() ?>" rel="bookmark"><?php 
    
    the_title(); ?></a></b>
    				<?php the_content_limit(80, ""); ?>
    
    				<div style="border-bottom:1px dotted #94B1DF; margin-bottom:10px; 
    
    padding:0px 0px 10px 0px; clear:both;"></div>
    
    				<?php endwhile; ?>
    
    				<!--This is where you can specify the archive link for each section.-->
    
    				<b><a href="ENTER CATEGORY URL HERE" rel="bookmark">More Featured Category Posts</a></b>
    
    			</div>

    This is set up to pull a 70px by 70px thumbnail image from the page. Put whatever image you want in the main page when you are writing it. Then under advanced options, custom fields put in the key name as thumbnail and then define the absolute url to the image in the Value box. You can see the example here on Brian’s demo page.

    This pulls categories and has the same exact look.

    <div id="homepageleft">
    
    			<!--This section is currently pulling category ID #1, and can be switched by changing the cat=1 to show whatever category ID you would like in this area.-->
    
    			<div class="featured">
    			<h3>Featured Category</h3>
    
    				<!--This is where the thumbnails are found for the homepage bottom section - note the custom field name for this image is "thumbnail". Recommended image size is 70x70, as the stylesheet is written for this size.-->
    
    				<?php $recent = new WP_Query("cat=1&showposts=3"); while($recent->have_posts()) : $recent->the_post();?>
    				<?php if( get_post_meta($post->ID, "thumbnail", true) ): ?>
    				    <a href="<?php the_permalink() ?>" rel="bookmark"><img style="float:left;margin:0px 10px 0px 0px;" src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" alt="alt text" /></a>
    				<?php else: ?>
    				   	<a href="<?php the_permalink() ?>" rel="bookmark"><img style="float:left;margin:0px 10px 0px 0px;"  src="<?php bloginfo('template_url'); ?>/images/thumbnail.jpg" alt="Default thumbnail" /></a>
    				<?php endif; ?>
    				<b><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></b>
    				<?php the_content_limit(80, ""); ?>
    
    				<div style="border-bottom:1px dotted #94B1DF; margin-bottom:10px; padding:0px 0px 10px 0px; clear:both;"></div>
    
    				<?php endwhile; ?>
    
    				<!--This is where you can specify the archive link for each section.-->
    
    				<b><a href="ENTER CATEGORY URL HERE" rel="bookmark">More Featured Category Posts</a></b>
    
    			</div>

    I have 2 different <h> tags in the example. The code in this box was the original code with the developers <h3> tags. On the example above I changed my theme to an <h5> tag for SEO purposes. That way I can use <h1> to <h3> in my text. My sidebar is an <h4> and my “search this site” on the header is an <h6> I hope that clarifies it. Good luck all!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Including Posts and Pages to Index’ is closed to new replies.