• Resolved deepwhitesound

    (@deepwhitesound)


    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!

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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)
    ?>

    https://codex.www.ads-software.com/Template_Tags/single_cat_title
    https://codex.www.ads-software.com/Function_Reference/get_page_by_title
    https://codex.www.ads-software.com/Function_Reference/query_posts#Post_.26_Page_Parameters
    https://codex.www.ads-software.com/Function_Reference/wp_reset_query

    second 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));

    Thread Starter deepwhitesound

    (@deepwhitesound)

    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

    Thread Starter deepwhitesound

    (@deepwhitesound)

    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.

    Thread Starter deepwhitesound

    (@deepwhitesound)

    everything you have provided works perfectly ?? thank you so much

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘help with custom field data’ is closed to new replies.