serializer and weblog
[ start | index | login ]
start > 2010-03-27 > 1

2010-03-27 #1

Created by case. Last edited by case, 2 years and 53 days ago. Viewed 1,055 times. #3
[diff] [history] [edit] [rdf]
labels
attachments

including WordPress posts into static website

To make a "news" part of a static website more maintainable (and editable by end-user), I decided to include WordPress posts into that site. Doing so, I stumbled over issues with the post paged navigation.

Despite that, WordPress documentation about >>The Loop in Action tells you everything you need to know to get your posts into your static website.

Just make sure to start your php file with

<?php include ('./blog/wp-blog-header.php'); ?>

The trouble with the post-navigation was caused by the fact, that I installed WordPress into a subdirectory, while the posts actually would be shown on a page at the top-level directory. Now using the function

<?php posts_nav_link() ?>
would result in broken links as they would try to locate the current page url within the subdirectory.

Instead of checking out the original functions's php code I used hints from multiple sources and built up my self-made navigation. I haven't used php before, so there might be easier and much more smart ways to do this.

Nevertheless here is it in case you stumble across the same issue:

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
	<?php the_content('Read the rest of this entry &raquo;'); ?>
<?php endwhile; ?>

<?php global $wp_query; /* set paged if not set (entry page) */ if ($paged == 0) { $paged = 1; } /*add newer link to entry page without $paged parameter */ if ($paged == 2) { echo "<a href=\""; echo $_SERVER['SCRIPT_NAME']; echo "\">&laquo; newer posts</a>"; } /*add newer link*/ if ($paged > 2) { echo "<a href=\""; echo $_SERVER['SCRIPT_NAME']; echo "?paged="; echo ($paged-1); echo "\">&laquo; newer posts</a>"; } /*add older link*/ if ($paged < $wp_query->max_num_pages) { /*add new-old separator if needed*/ if ($paged > 1) { echo " &#183; "; } echo "<a href=\""; echo $_SERVER['SCRIPT_NAME']; echo "?paged="; echo ($paged+1); echo "\">older posts &raquo;</a>"; } ?>

<?php else: ?> <p><?php _e('no entries found.'); ?></p> <?php endif; ?>

no comments | post comment
Motto
Communication is key

quick Quick Links
WhatIsThis about?
Java mobile Sudoku
Jave mobile Kakuro
more Java mobile apps...
PostTrack (a desktop app)
TimeLine
Impressum
Charley - suzie's dog

Logged in Users: (1)
… and 2 Guests.

Icon-Snip more changes...

Twitter updates

Twitter Updates

    more updates...

    Blogs
    >>Polskie Wyzwania
    >>++ vox.machina ++
    >>Zitate - Sprüche - Aphorismen
    >>Wil Wheaton
    >>Mathematische Kleinigkeiten
    >>William Gibson
    >>instant-thinking
    >>Over heard in NY

    RSS Feed RSS Feed
    post to del.icio.us

    Stats: 1223 snips by 16 users
    take-off 9 years and 125 days ago

    Powered by
    >>SnipSnap 1.0b2-uttoxeter
    with SnipScale 1.1.0



    This work is licensed under a
    >>Creative Commons License.

    SEARCH