WordPress.org

Ready to get started?Download WordPress

Forums

Calling a custom category (2 posts)

  1. crispmedia
    Member
    Posted 1 year ago #

    I am creating a custom template called "city index". The file needs to include an index for a specific category (among other things). Right now, I've figured out how to hard-code the category into the template file:

    <?php
    query_posts('cat=61');
    if(have_posts()) :?>

    Where 61 is the category I would like to use.

    I would like to replace 61 with a custom field, specified for the page.

    So something that lets me use something like:
    <?php echo get_post_meta($post->ID, ‘category', true); ?>

    where I specify "61" in a custom field associated with the page.

    I'm a complete PHP newbie, so what do I need to do to insert the above where "61" is? Will that work? Is there a better method? Any feedback offered is appreciated.

  2. Mohd Rafie
    Member
    Posted 1 year ago #

    Hi there,

    When you call the get_post_meta it should be inside the loop ie the query_posts

    The codex doco has an example for calling a custom field value

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.