我是php和wordpress的新手。我正在建立一个档案模板,必须与当前类别的所有职位砌体画廊。我必须用一段动态代码来替换“edito”,这段代码给出了实际的类别名称。你能帮我弄清楚怎么做吗?谢谢
<?php
$args = array(
\'category_name\' => \'edito\',
\'post_type\' => \'post\',
\'orderby\' => \'menu_order\',
\'order\' => \'DESC\',
);
$child_query = new WP_Query( $args );
$first = true;
$same_date = \'dd\';
while ( $child_query->have_posts() ) : $child_query->the_post();
$divclass = \'\';
$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($thumb_id, \'thumbnail-size\', true);
$thumb_url = $thumb_url_array[0];
$thumb_w = $thumb_url_array[1];
$thumb_h = $thumb_url_array[2];
$excerpt = get_the_excerpt();
$divstyle = \'background-image:url(\' . $thumb_url .\');height:\' . $thumb_h . \'px;\';
?>
SO网友:WPhil
您可以尝试以下操作:
if ( is_category() ) {
$cat = get_category( get_query_var( \'cat\' ) );
// $cat_id = $cat->cat_ID;
$cat_name = $cat->name;
// $cat_slug = $cat->slug;
$args = array(
\'category_name\' => $cat_name,
\'post_type\' => \'post\',
\'orderby\' => \'menu_order\',
\'order\' => \'DESC\',
);
...
您需要的功能是
get_category, 以及is\\U category,以检查查询是否针对现有类别存档页。