|
So this is my first post. I will use it to explain how to access different posts from your wordpress site and display them without using a template file. It is something I’ve been working on but only just implemented it. Make sure you don’t install wordpress in the root directory. This makes it very easy to control things later on. You can just redirect to the wordpress index.php with the .htaccess file in your root directory.
First I started off with a regular old index.html file which is the homepage the public will access. I then changed the extension to .php so my wordpress index.php can REQUIRE it. In the index.php file in your wordpress installation you must add a path to your homepage index.php file:
require('../path/to/index.php');
Now every path (src=”relative/path/to/file.jpg”) in your original index.html file which is now renamed index.php (right?) must be changed to include the correct path because since the wordpress index.php required your homepage index.php your script is running in the wordpress folder. So we have:
path/to/wordpressinstall/index.php
path/to/homepage/index.php
Your paths must be changed to something like this:
../path/to/homepage/image.jpg
**note the two periods to look in parent folder
Now for the code if you only want the script to display all your posts from a category and display them in descending order by date. This script will show the post title then the post below it:
<?php $myposts = query_posts('cat=3');
foreach( $myposts as $post ) : setup_postdata($post);
?>
<table>
<tr>
<td align="center">
<h2><?php the_title(); ?></h2>
</td>
</tr>
<tr>
<td>
<?php the_content(); ?>
</td>
</tr>
</table>
<?php endforeach; ?>
Notice the ‘cat=3′ being sent to the query_posts function. I have all my posts organized by category to determine where they end up on the page. I have another category for site specific details. I found the category number by trial and error. You might be able to find it in the wordpress admin panel.
You can also access your posts directly by pointing to the number of the post:
<?php $postID = 55; $queried_post = get_post($postID); echo $queried_post->post_content; ?>
Just stick that inside of a table cell and you’re off. This makes it easy to edit your site without having to edit html or use an ftp client. You can now create a one post per body of text then place it anywhere on your page.
|