SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Wizard ryanhellyer's Avatar
    Join Date
    Oct 2006
    Location
    New Zealand
    Posts
    2,323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Custom Fields with WordPress Pages

    Hi,
    I'm having a devil of a time trying to figure out how to list some WordPress pages with associated Custom Fields. This is easy with posts, but I'm damned if I can figure out how to do it with WordPress pages.

    So ... there would be a page, which would list all of the WordPress pages and beside each list item would be a code generated via the Custom Field of that page.

    Any ideas on how to go about doing this?

  2. #2
    SitePoint Addict bwdow's Avatar
    Join Date
    Feb 2006
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you planning to add a dynamic code to all pages? I think you need a special script for this.

  3. #3
    SitePoint Wizard ryanhellyer's Avatar
    Join Date
    Oct 2006
    Location
    New Zealand
    Posts
    2,323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not to all pages, just to a specific page.

    The page will display all the sub pages of that particular page. But the hard bit (or at least the part I can't figure out) is how to add information from a custom field from each page.

  4. #4
    Is Still Alive silver trophybronze trophy RetroNetro's Avatar
    Join Date
    Jul 2003
    Location
    Texas
    Posts
    6,883
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

  5. #5
    SitePoint Wizard ryanhellyer's Avatar
    Join Date
    Oct 2006
    Location
    New Zealand
    Posts
    2,323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by BPartch View Post
    Er, yep, that looks like it may be able to do it. That also looks hideously difficult but I'll give it a bash.

    Thanks for the link BPartch, er, Johhny Gulag.

    What's with the name change?

  6. #6
    Is Still Alive silver trophybronze trophy RetroNetro's Avatar
    Join Date
    Jul 2003
    Location
    Texas
    Posts
    6,883
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I am going through an identity crisis.

    Glad that link was useful, I honestly did not understand what it was saying, well I sorta did but I am not the advanced user it referred to I guess.

  7. #7
    SitePoint Addict
    Join Date
    Mar 2006
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've never used this, but it looks like what you want
    http://blog.ftwr.co.uk/wordpress/query-child-of-page/

    adds an argument for query_posts

    Edit: Couldn't you just query all your pages with query_posts('post_type=page') and add some conditional stuff in the loop for the custom field?

  8. #8
    SitePoint Wizard ryanhellyer's Avatar
    Join Date
    Oct 2006
    Location
    New Zealand
    Posts
    2,323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by aaronjj View Post
    I've never used this, but it looks like what you want
    http://blog.ftwr.co.uk/wordpress/query-child-of-page/

    adds an argument for query_posts
    Thanks

    Quote Originally Posted by aaronjj View Post
    Edit: Couldn't you just query all your pages with query_posts('post_type=page') and add some conditional stuff in the loop for the custom field?
    Er, I didn't realise you could use query_posts on pages like that.
    If that works, then that is exactly what I need to do.

    Thanks
    I'll report back shortly with my findings

  9. #9
    SitePoint Wizard ryanhellyer's Avatar
    Join Date
    Oct 2006
    Location
    New Zealand
    Posts
    2,323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks aaronjj

    I used your advice to track down the following forum post which solved my problem ... http://wordpress.org/support/topic/155532?replies=3

  10. #10
    SitePoint Wizard ryanhellyer's Avatar
    Join Date
    Oct 2006
    Location
    New Zealand
    Posts
    2,323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought this code did exactly what I was looking for. However I've now realised that it doesn't sort the page order according to the "WordPress Page Order", it generates them dependent on the date published.

    Code:
    <?php
    $args = array(
    	'post_type' => 'page',
    	'numberposts' => 4,
    	'post_status' => 'publish',
    	'post_parent' => 7, // any parent
    	);
    $attachments = get_posts($args);
    //print_r("attachements:" . $attachements);
    if ($attachments) {
    	foreach ($attachments as $post) { ?>
    	<div class="feature-products-boximg" style="background:url('<?php $pictures = get_post_meta($post->ID, "image", true); echo $pictures; ?>');">
    		<a href="<?php the_permalink(); ?>">
    			<span><?php the_title(); ?></span>
    		</a>
    	</div>
    	<?php
    		$the_excerpt = get_post_meta( $post->ID, '1lineblurb', $single = true);
    		if ($the_excerpt != '') { echo($the_excerpt); }// if: filename not blank
    	}
    }
    ?>
    Do any of you know how to modify this so that it generates the pages according to the "WordPress Page Order"?

    Thanks

  11. #11
    SitePoint Addict
    Join Date
    Mar 2006
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Add 'orderby' => 'menu_order' to your args

  12. #12
    SitePoint Wizard ryanhellyer's Avatar
    Join Date
    Oct 2006
    Location
    New Zealand
    Posts
    2,323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by aaronjj View Post
    Add 'orderby' => 'menu_order' to your args
    Brilliant! Thank you very much I'll try that tonight and see how I get on.


    There doesn't seem to be a lot of information about this feature of WordPress available. If anyone has any good links to a tutorial or similar I'd love to see them.

  13. #13
    SitePoint Wizard ryanhellyer's Avatar
    Join Date
    Oct 2006
    Location
    New Zealand
    Posts
    2,323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That did the trick perfectly

    Thanks aaronjj. Your help is much appreciated


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •