下面是一个页面模板,我试图在其中检索活动成员元数据(属于Restrict Content Pro)。显示用户的元数据工作正常;但我不能只显示活跃的成员,而不是每个人。我想知道下面的语法中是否有一个简单的错误可以纠正这一点。
我需要检查成员是否处于活动状态[正在使用if( rcp_is_active() )]
, 其中所有成员也是网站的订阅者[ $members = get_users( $args ); foreach ($members as $member)]
.
<?php
/**
* This file adds the User Directory template to the Parallax Pro Theme.
*
* @author StudioPress
* @package Parallax
* @subpackage Customizations
*/
/*
Template Name: Directory
*/
add_action( \'genesis_entry_content\', \'ogs_directory\', 5 );
function ogs_directory() {
$args = array(
\'blog_id\' => 1, // unless yours is a multisite install, you shouldn\'t need to change this
\'exclude\' => array(), // IDs of users that need to be excluded
\'orderby\' => \'display_name\' // Sort by \'ID\', \'login\', \'nicename\', \'email\', \'url\', \'registered\', \'display_name\', or \'post_count\'; defaults to \'login\'
);
$members = get_users( $args );
if( rcp_is_active() ) {
foreach ($members as $member)
echo \'<p>\';
echo \'<strong>Name: </strong>\' .esc_attr( $member->first_name ). \'\' ;
echo \'<strong> </strong>\' .esc_attr( $member->last_name ). \'<br/> \' ;
if ( $member->rcp_address ) {
echo \'<strong>Address: </strong>\' .esc_attr( $member->rcp_address ). \'<br/> \' ;
}
if ( $member->rcp_univ_1 ) {
echo \'<strong>University: </strong>\' .esc_attr( $member->rcp_univ_1 ). \'<br/> \' ;
}
echo \'</p>\';
} }
//* Run the Genesis loop
genesis();
SO网友:Nilambar Sharma
的花括号foreach
缺少。尝试以下操作:
/*
Template Name: Directory
*/
add_action( \'genesis_entry_content\', \'ogs_directory\', 5 );
function ogs_directory() {
$args = array(
\'blog_id\' => 1, // unless yours is a multisite install, you shouldn\'t need to change this
\'exclude\' => array(), // IDs of users that need to be excluded
\'orderby\' => \'display_name\' // Sort by \'ID\', \'login\', \'nicename\', \'email\', \'url\', \'registered\', \'display_name\', or \'post_count\'; defaults to \'login\'
);
$members = get_users( $args );
if( rcp_is_active() ) {
foreach ($members as $member) {
echo \'<p>\';
echo \'<strong>Name: </strong>\' .esc_attr( $member->first_name ). \'\' ;
echo \'<strong> </strong>\' .esc_attr( $member->last_name ). \'<br/> \' ;
if ( $member->rcp_address ) {
echo \'<strong>Address: </strong>\' .esc_attr( $member->rcp_address ). \'<br/> \' ;
}
if ( $member->rcp_univ_1 ) {
echo \'<strong>University: </strong>\' .esc_attr( $member->rcp_univ_1 ). \'<br/> \' ;
}
echo \'</p>\';
} // end foreach
} // end if
} // end function
//* Run the Genesis loop
genesis();
SO网友:angiemeeker
if( rcp_is_active()
不适合我想做的事。我需要rcp_get_members()
. 改变这一点,并在上面缺少的括号中添加内容,使我能够产生我想要的结果。非常感谢。
add_action( \'genesis_entry_content\', \'ogs_directory\', 5 );
function ogs_directory() {
$args = array(
\'blog_id\' => 1, // unless yours is a multisite install, you shouldn\'t need to change this
\'exclude\' => array(), // IDs of users that need to be excluded
\'orderby\' => \'display_name\' // Sort by \'ID\', \'login\', \'nicename\', \'email\', \'url\', \'registered\', \'display_name\', or \'post_count\'; defaults to \'login\'
);
$members = rcp_get_members();
foreach ($members as $member) {
echo \'<p>\';
echo \'<strong>Name: </strong>\' .esc_attr( $member->first_name ). \'\' ;
echo \'<strong> </strong>\' .esc_attr( $member->last_name ). \'<br/> \' ;
if ( $member->rcp_address ) {
echo \'<strong>Address: </strong>\' .esc_attr( $member->rcp_address ). \'<br/> \' ;
}
if ( $member->rcp_univ_1 ) {
echo \'<strong>University: </strong>\' .esc_attr( $member->rcp_univ_1 ). \'<br/> \' ;
}
echo \'</p>\';
} }
//* Run the Genesis loop
genesis();