help with custom field data
-
hello, hope someone here can help me.
i would like to do two things, and both require ‘getting’ information from a page / its custom field data, and inserting into another code.
first: in my category.php file, before calling up all posts from a specific category, i’d like to insert code that would call up the content from a page with the same name as the category name.
for example, for a category named ‘The Beatles’ i’d like to pull up the_content from a page also named ‘The Beatles’ and include it in the category
if i could get this to work, this second part won’t be as important, however i’d still like to know how to do it…
second, on a page i’d like to call up all posts from a specific category. the category id would be specified as a value from a custom field entry from that page.
i’ve used get_posts to pull up the posts, and get_post_meta to pull up the custom field data, however when i use them together like this, it gives me an error:
<?php $postslist = get_posts('numberposts=5&order=DESC&orderby=ID&category=<?php echo get_post_meta($post->ID, 'identity', true); ?>'); foreach ($postslist as $post) : setup_postdata($post); ?> <div class="recent"> <?php the_excerpt(); ?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </div> <?php endforeach; ?>kind of new to more ‘complex’ use of this code so any help is greatly appreciated!
-
first question:
<?php $current_cat_name = single_cat_title('',false); $page = get_page_by_title($current_cat_name); if($page) : //only do the following if a page with this title exists $pageid=$page->ID; query_posts('post_status=publish&page_id='.$pageid); if(have_posts()) : while(have_posts()) : the_post(); /*your page output code here*/ the_title(); the_content(); endwhile; endif; //end of the loop wp_reset_query(); endif; //end of if($page) ?>http://codex.wordpress.org/Template_Tags/single_cat_title
http://codex.wordpress.org/Function_Reference/get_page_by_title
http://codex.wordpress.org/Function_Reference/query_posts#Post_.26_Page_Parameters
http://codex.wordpress.org/Function_Reference/wp_reset_querysecond question:
you seem to have ignored the sequence of opening/closing php tags:
instead of this line:$postslist = get_posts('numberposts=5&order=DESC&orderby=ID&category=<?php echo get_post_meta($post->ID, 'identity', true); ?>');you could try to use:
$postslist = get_posts('numberposts=5&order=DESC&orderby=ID&category='. get_post_meta($post->ID, 'identity', true));you are beyond incredible. thank you so much! the second code, i knew i was doing something wrong but i am new to this code and didn’t know exactly what it was.
thanks again you just saved the day
actually, for the first code, how about calling up just a link to the page with the same title, rather than the content from that page?
i’d like to insert code that would call up the content from a page with the same name as the category name.
it is not absolutely clear to me what that means;
however, if you just want to have a link to that particular page there:<?php $current_cat_name = single_cat_title('',false); $page = get_page_by_title($current_cat_name); if($page) : //only do the following if a page with this title exists $pageid=$page->ID; ?> <a href="<?php echo get_permalink($pageid);?>"><?php echo $page->post_title; ?></a> <?php endif; ?>this outputs the linked title of the page with the same name as the category.
everything you have provided works perfectly 🙂 thank you so much
The topic ‘help with custom field data’ is closed to new replies.