简体   繁体   中英

Calling a Category w/PHP

This is a PHP problem in WordPress while using a custom theme options panel. I asked it on the WordPress site, but nobody could give me the right answer.

to_cat_home calls a category the user has selected from a theme options panel, to_count_home calls a number of posts the user has selected.

The problem is the posts_per_page works but the cat= simply doesn't.

On the archives pages the number of pages generated is determined by the basic WordPress settings, rather than the user selected number.

<?php
$cat = get_option('to_cat_home');
$per_page = get_option('to_count_home');
query_posts("cat=${cat}&posts_per_page=${per_page}&paged=".$paged);
if (have_posts())
?>

In my functions:

array( "name" => "Homepage featured category",
    "desc" => "Choose a category from which featured posts are drawn",
    "id" => $shortname."_cat_home",
    "type" => "select",
    "options" => $wp_cats,
    "std" => "Choose a category"),

You should use

<?php
query_posts("cat={$cat}&posts_per_page={$per_page}&paged=".$paged);"
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM