0

I have a page that lists posts from a specific category.

Now I need to add another page which needs to list posts from another category.

I could just create a copy of the template that the working page is using and just change category ID.

But since everything else in the template is the same it would probably be better if both pages use the same page template and the category ID is obtained from the URL.

There is probably a way to achieve this but I'm not sure how.

4

1 回答 1

1

You can add a Custom Field in the page : cats = "1,2,3"

then in page template :

$custom_cats = get_post_custom_values('cats');
$args = array(
    'category'        => $custom_cats[0], //like: 1,2,3
    'orderby'         => 'post_date',
    'post_status'     => 'publish',
);
$query = get_posts( $args );

This is the same page template.

于 2013-03-30T12:05:07.973 回答