Forums

use custom fields to call a category slug (4 posts)

  1. bollywooddreamz
    Member
    Posted 3 years ago #

    hi

    i am trying to make a template that can be used many times. as such i want to use custom fields to define a category slug and use it within the query_posts . but its not working. can anyone help me out with this

    the code i am using is

    '<?php $cat=get_post_custom_values($key = "name"); ?>

    <?php query_posts("category_name=$cat&showposts=4"); ?>'

    please suggest what i am doing wrong

    thanks in advance

  2. Austin Matzko
    Member
    Posted 3 years ago #

    I don't understand exactly what you're trying to do, but this code probably isn't what you want to do:

    $cat=get_post_custom_values($key = "name");

    You might want

    $cat=get_post_custom_values("name");

  3. bollywooddreamz
    Member
    Posted 3 years ago #

    hi

    let me try to explain in detail.

    want to make a reusable template which drags posts from different categories with the same tag name on to one page.

    example i want a different categories of a movie such a movie review, video, movie preview and etc having the tag name i.e of a particular movie on to one page.

    so i cant hard code the category name in to the template. i want to use custom field to define the category and tag.

    hope i was clear this time.

    any assistance would be great.

  4. Austin Matzko
    Member
    Posted 3 years ago #

    want to make a reusable template which drags posts from different categories with the same tag name on to one page.

    If you want to create a template that shows posts from particular category, just create a template file named like category-12.php where "12" is the category id number of the category whose posts you want to show.

    Alternatively, if you have a regular page template, you can query posts by category and get the same results with the following:

    query_posts(array('cat' => 12));

    Or search by category name:

    query_posts(array('category_name' => 'MyCategory'));

Topic Closed

This topic has been closed to new replies.

About this Topic