dyadica.net

Fun and Games in the Dyadic Sea

Cross Paging for Wordpress

permalink image comments image
Sunday, 12 July '09 :

At times I have found the need (want even desire) to be able to create a Page from a Post.

Yes I know that this can be classed as duplication of content, but some times its nice to be able to archive things in this manner and anyway you only create the content once ;)

So without further ado I introduce to you Cross Paging:

WordPress has the ability to allow authors to assign custom fields to Posts and Pages. This arbitrary extra information is known as meta-data.

We can use this data to ID a desired Posts content for use within a Page, simply by setting a reference to the Posts ID. The page checks to see if an ID has been set,  if so, then draws the content via a custom query:

<?php if(is_page()){

// cross-post-page = The Custom field Name. The value = the posts ID

$key=”cross-post-page”;
$pageid = get_post_meta($post->ID, $key, true);

if ($pageid){

//The Custom Query
query_posts(‘p=’.$pageid);

// Display post content
if ( have_posts() ) : while ( have_posts() ) : the_post();
the_content(‘More..’);
endwhile; endif;

//Reset the Query
wp_reset_query();

}

} ?>

The same system can also be used across pages, you just have to change the query call to reflect use of  page_id=N instead of p=N

<?php if(is_page()){

// cross-page-page = The Custom field Name. The value = the posts ID

$key=”cross-page-page”;
$pageid = get_post_meta($post->ID, $key, true);

if ($pageid){

//The Custom Query
query_posts(‘page_id=’.$pageid);

// Display post content
if ( have_posts() ) : while ( have_posts() ) : the_post();
the_content(‘More..’);
endwhile; endif;

//Reset the Query
wp_reset_query();

}

} ?>

So there you have it, the ability to populate a Pages content using existing Post/Page content – Cross Paging.

Tags: , , , ,

page meta

get trackback image get trackback image
details
  • Posted: Sunday, 12 July '09
  • Edited: Monday, 13 July '09
  • Category: php, wordpress
  • Author: admin

say what do you think

RSS feed | Trackback URI

css | xhtml | dyadica.net © admin 2010 | powered: wordpress | fuel: ps-wii-elite | top | sign-up