Действительно ли возможно выбрать определенные категории, которые будут только отображены к, вошел в систему участники?
Я пытался найти плагин или решение PHP, которое делает это, но не могло найти ничего, что было все еще релевантно.
Да :).
Следующее произведет все запросы для сообщений на фронтенде включая 'вторичные циклы' (например, отправит списки на стороне), но это не произведет пользовательские типы сообщения. Таким образом, это не может быть точно, что Вы после, но принцип является тем же:
add_action('pre_get_posts','wpse72569_maybe_filter_out_category');
function wpse72569_maybe_filter_out_category( $query ){
//Don't touch the admin
if( is_admin() )
return;
//Leave logged in users alone
if( is_user_logged_in() )
return;
//Only effect 'post' queries
$post_types = $query->get('post_type');
if( !empty($post_types) && 'post' != $post_types )
return;
//Get current tax query
$tax_query = $query->get('tax_query');
//Return only posts which are not in category with ID 1
$tax_query[] = array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => array( 1 ),
'operator' => 'NOT IN'
);
//If this is 'OR', then our tax query above might be ignored.
$tax_query['relation'] = 'AND';
$query->set('tax_query',$tax_query);
}
Вы могли попробовать это, если то, что вы смотрели использует его структура типа цикла:
<?php
if ( is_user_logged_in() ) {
//Only displays if the user is logged in.
query_posts('cat=1'); // Replace the category number with the correct category number you want to display
while (have_posts()) : the_post();
the_content();
endwhile;
} else {
// Everyone else that is not logged in
query_posts('cat=2'); // Replace the category number with the correct category number you want to display
while (have_posts()) : the_post();
the_content();
endwhile;
}
?>
Если Вы надеетесь просто отображать ссылки на страницы категории как меню, можно сделать это:
Используйте военно-морскую функцию меню WP. Зарегистрируйте меню в своем functions.php в Вашей папке темы. Можно сделать это путем добавления этого к файлу:
<?php
register_nav_menus( array(
'primary' => __( 'Primary Navigation', 'your_theme_name' ), // Your main navigation. Replace "your_theme_name" with the theme you are using.
'logged_in_user' => __( 'Logged In User', 'your_theme_name' ), // Remember replace "your_theme_name" with the theme you are using.
) );
?>
Добавьте категории к меню через администрирование.
Назовите его в своей теме. Это подобно тому, что мы сделали выше, но просто перечислим его как меню и не список сообщений.
<?php
if ( is_user_logged_in() ) {
//Only displays if the user is logged in.
wp_nav_menu( array( 'container' => false, 'menu_id' => 'nav', 'theme_location' => 'logged_in_user' ) );
} else {
// Everyone else that is not logged in
// You can display anything you want to none logged in users or just leave it blank to display nothing.
}
?>
query_post()
. Не используйте фильтр :)
– Stephen Harris
14.11.2012, 19:19