2013-10-02 4 views
1

두 개의 게시물 카테고리가 있습니다. 블로그 페이지에 하나만 나타나기를 바랍니다. 이 페이지는 홈 페이지가 아닙니다. 코덱스에서이 코드를 사용해 보았습니다 :Wordpress의 블로그 페이지에서 한 카테고리를 어떻게 제외합니까?

<?php 
if (is_page('page_slug')) { 
    query_posts('cat=-(category id)'); 
} 
?> 

사용하지 마십시오. 또한 페이지의 새 템플릿을 만든 다음, index.php에

<?php 
if (is_page_template('new_blog')) { 
    query_posts('cat=-(category id)'); 
} 
?> 

을 사용했지만 여전히 아무것도 만들지 않았습니다. 어쩌면 내가 잘못된 장소에 코드를 넣을거야? 아무도 내가 이것을 달성 할 수있는 방법에 대한 조언을 해줄 수 있습니까?

편집 : index.php를 홈페이지 일부 기능에 functions.php에이 코드를 추가이기 때문에이 코드가 실행되지 않습니다의 index.php에

<?php 

include_once get_template_directory() . '/functions/blackbird-functions.php'; 
$functions_path = get_template_directory() . '/functions/'; 
/* These files build out the options interface. Likely won't need to edit these. */ 
require_once ($functions_path . 'admin-functions.php'); // Custom functions and plugins 
require_once ($functions_path . 'admin-interface.php'); // Admin Interfaces (options,framework, seo) 
/* These files build out the theme specific options and associated functions. */ 
require_once ($functions_path . 'theme-options.php'); // Options panel settings and custom settings 
require_once ($functions_path . 'shortcodes.php'); 
?> 
<?php 

/* ----------------------------------------------------------------------------------- */ 
/* Styles Enqueue */ 
/* ----------------------------------------------------------------------------------- */ 

function blackbird_add_stylesheet() { 
    wp_enqueue_style('shortcodes', get_template_directory_uri() . "/css/shortcode.css", '', '', 'all'); 
} 

add_action('init', 'blackbird_add_stylesheet'); 
/* ----------------------------------------------------------------------------------- */ 
/* jQuery Enqueue */ 
/* ----------------------------------------------------------------------------------- */ 

function blackbird_wp_enqueue_scripts() { 
    if (!is_admin()) { 
     wp_enqueue_script('jquery'); 
     wp_enqueue_script('blackbird-ddsmoothmenu', get_template_directory_uri() . '/js/ddsmoothmenu.js', array('jquery')); 
     wp_enqueue_script('blckbird-flex-slider', get_template_directory_uri() . '/js/jquery.flexslider-min.js', array('jquery')); 
     wp_enqueue_script('blackbird-testimonial', get_template_directory_uri() . '/js/slides.min.jquery.js', array('jquery')); 
     wp_enqueue_script('blackbird-prettyphoto', get_template_directory_uri() . '/js/jquery.prettyPhoto.js', array('jquery')); 
     wp_enqueue_script('blackbird-validate', get_template_directory_uri() . '/js/jquery.validate.min.js', array('jquery')); 
     wp_enqueue_script('blackbird-custom', get_template_directory_uri() . '/js/custom.js', array('jquery')); 
    } elseif (is_admin()) { 

    } 
} 

add_action('wp_enqueue_scripts', 'blackbird_wp_enqueue_scripts'); 
/* ----------------------------------------------------------------------------------- */ 
/* Custom Jqueries Enqueue */ 
/* ----------------------------------------------------------------------------------- */ 

function blackbird_custom_jquery() { 
    wp_enqueue_script('mobile-menu', get_template_directory_uri() . "/js/mobile-menu.js", array('jquery')); 
} 

add_action('wp_footer', 'blackbird_custom_jquery'); 
//Front Page Rename 
$get_status = blackbird_get_option('re_nm'); 
$get_file_ac = get_template_directory() . '/front-page.php'; 
$get_file_dl = get_template_directory() . '/front-page-hold.php'; 
//True Part 
if ($get_status === 'off' && file_exists($get_file_ac)) { 
    rename("$get_file_ac", "$get_file_dl"); 
} 
//False Part 
if ($get_status === 'on' && file_exists($get_file_dl)) { 
    rename("$get_file_dl", "$get_file_ac"); 
} 

// 
function blackbird_get_option($name) { 
    $options = get_option('blackbird_options'); 
    if (isset($options[$name])) 
     return $options[$name]; 
} 

// 
function blackbird_update_option($name, $value) { 
    $options = get_option('blackbird_options'); 
    $options[$name] = $value; 
    return update_option('blackbird_options', $options); 
} 

// 
function blackbird_delete_option($name) { 
    $options = get_option('blackbird_options'); 
    unset($options[$name]); 
    return update_option('blackbird_options', $options); 
} 

//Enqueue comment thread js 
function blackbird_enqueue_scripts() { 
    if (is_singular() and get_site_option('thread_comments')) { 
     wp_print_scripts('comment-reply'); 
    } 
} 

add_action('wp_enqueue_scripts', 'blackbird_enqueue_scripts'); 
?> 

<?php 
add_action('init','posts_of_one_cat'); 
function posts_of_one_cat() { 
if (is_page('26') ) { 
    query_posts('cat=-12'); // 3 is id of your category you want to exclude 
    // do anything here 
} 
} 
?> 

답변

0

get_posts()가 바람직하다 옵션으로.

<?php $args = array(
    'category' => '-(category id)', 
?> 

<?php 
    $postslist = get_posts($args); 

    foreach ($postslist as $post) : 
    setup_postdata($post); 
?> 
+0

functions.php에 그 템플릿을 삽입합니까? 또는 내가 사용하고있는 블로그 페이지 템플릿? 죄송합니다. 저는이 모든 것을 처음 접했지만 웹 사이트 담당을 맡아서 매우 빨리 배우려고합니다. – jemtan990

+0

문제가 없습니다! 우리 모두는 어떤 시점에서 시작해야했습니다 (나는 아직도 배우고 있습니다). 이것은 사용중인 템플릿에 들어갑니다. 'foreach' 루프 내에서'echo $ post-> ID','$ slug = $ post-> slug'와 같이'$ post' 데이터를 얻거나 출력 할 수 있습니다. 전체 게시물을 뱉어 내고 액세스 할 수있는 방법과 액세스하는 방법을 보려면'foreach' 루프에'var_dump ($ post)'를 넣고 거기서 가십시오. 해피 코딩, godspeed. – zillaofthegods

+0

나는 마침내 그것을 이해했다! 당신의 도움을 주셔서 감사합니다. 나는 이것이 내가 Wordpress에서 주위를 어지럽히는 것에 대해 훨씬 더 강한 느낌을 주었다고 느낀다. – jemtan990

0

: 여기

가 functions.php 파일입니다

뭔가 같은 ...

<?php 
add_action('init','posts_of_one_cat'); 
function posts_of_one_cat() { 
if (is_page('your blog page id here') ) { 
    query_posts('cat=-3'); // 3 is id of your category you want to exclude 
    // do anything here 
} 
} 
?> 
+0

나는 그것을했고, 전체 사이트가 다운되었다. 그것은 "예기치 않은 jemtan990

+0

구문 오류 일 수 있습니다.' codepixlabs

+0

아하, 어리석은 오류는 미안 해요. 코드를 삽입했는데 여전히 효과가 나타나지 않습니다. 이것은 나를 미치게하고있다! – jemtan990

관련 문제