2017-12-01 3 views
0

내 포트폴리오의 포트폴리오를 표시하기 위해 사용자 정의 게시 유형을 만들었습니다. 사용자가 프로젝트를 클릭하면 프로젝트 세부 정보를 표시하려고합니다.사용자 정의 게시 유형 최근 게시물 만 표시

단일 프로젝트 세부 정보 페이지에서 사용자가 프로젝트 전후에 게시 된 프로젝트를 탐색 할 수 있기를 원하지만 올바르게 작업 할 수없는 페이지 매김을 얻을 수 없습니다.

내 루프는 내가가는 링크가 무엇이든 가장 최근의 게시물 만 표시하므로 그 이유를 알 수 없습니다. 이것이 제 페이지 매김 문제의 문제라고 생각합니다. 어떤 도움을 주셔서 감사합니다.

내가 비디오를 포함 한 것을 경험 메신저 : https://gyazo.com/4f148154e05bc205fd78bdde89de50c3

당신은 내가 "테스트 프로젝트 1"에이고는 "테스트 2"내용을 표시하는 것 볼 수 있듯이. 또한, 테스트 프로젝트 1 (가장 오래된 포스트 인) 매김 대신 시험 2 (새로운 포스트)

단일 project.php

<?php 
    $mypost = array('post_type' => 'project', 'posts_per_page' => 1,); 
    $loop = new WP_Query($mypost); 
    ?> 
    <?php while ($loop->have_posts()) : $loop->the_post();?> 

    <div class="col-lg-8" id="post-<?php the_ID(); ?>" <?php post_class(); ?>> 
    <?php the_content(); ?> 
    </div> 

    <div class="col-lg-4"> 
    <h3><?php the_title(); ?></h3> 
    <p><?php the_excerpt(); ?></p> 
    <h5>Date</h5> 
    <p><?php the_date(); ?></p> 
    <h5>Link</h5> 
    <p> 
     <?php $site= get_post_custom_values('project_link_detail'); 
      if($site[0] != ""){ 
     ?> 
     <a href="http://<?php echo esc_html(get_post_meta(get_the_ID(), 'project_link_detail', true)); ?>" target="_blank">Visit the Site</a> 
     <?php }else{ ?> 
      <em>Link Unavailable</em> 
     <?php } ?> 
    </div> 
    <hr> 
    <div class="col-lg-12"> 
    <div class="row"> 
     <div class="col-lg-6"> 
     <?php previous_post_link('%link') ?> 
     </div> 
     <div class="col-lg-6 text-right"> 
     <?php next_post_link(' %link') ?> 
     </div> 
    </div> 
    </div> 
    <?php endwhile; ?> 

portfolio.php

동일한 페이지 나 연출에
function my_portfolio() { 

    // Set the labels, this variable is used in the $args array 
    $labels = array(
    'name'    => __('Projects'), 
    'singular_name'  => __('Project'), 
    'add_new'   => __('Add New Project'), 
    'add_new_item'  => __('Add New Project'), 
    'edit_item'   => __('Edit Project'), 
    'new_item'   => __('New Project'), 
    'all_items'   => __('All Projects'), 
    'view_item'   => __('View Project'), 
    'search_items'  => __('Search Project'), 
    'featured_image'  => 'Preview', 
    'set_featured_image' => 'Add Preview' 
); 

    // The arguments for our post type, to be entered as parameter 2 of register_post_type() 
    $args = array(
    'labels'   => $labels, 
    'description'  => 'Holds portfolio specific data', 
    'public'   => true, 
    'menu_position'  => 25, 
    'supports'   => array('title', 'editor', 'thumbnail', 'excerpt', 'comments', 'custom-fields'), 
    'has_archive'  => true, 
    'show_in_admin_bar' => true, 
    'show_in_nav_menus' => true, 
    'has_archive' => 'page template', 
    'rewrite'   => true, 
    'query_var'   => 'project' 
); 

    // Call the actual WordPress function 
    // Parameter 1 is a name for the post type 
    // Parameter 2 is the $args array 
    register_post_type('project', $args); 
} 

답변

0

사용자 정의 게시 유형을 만들 때 보관 파일과 단일 파일에는 archive-portfolio 및 single-portfolio와 같은 사용자 정의 게시 이름이 포함되어야합니다. 이렇게하면 Wordpress는 각 파일에 대해 자동으로 쿼리를 매핑하므로 단일 포트폴리오에서 새 쿼리를 작성할 필요가 없습니다. 글로벌 $ post 변수에 액세스하면 게시물의 모든 정보를 얻을 수 있습니다 너는보고있다.

사용자 지정 쿼리를 제거하려고하면 여기에서 필요한 모든 항목이 포함 된 클린 테마를 다운로드 할 수도 있습니다. http://underscores.me/, 단일 파일 작동 방식을 볼 수 있습니다.

+0

와우! Underscores.me는 대단히 감사합니다. 결국 문제를 파악하고 사용자 지정 쿼리를 제거하고 archive- {posttype} .php 및 single- {post-type} .php를 사용하여 자동 매핑 된 쿼리를 사용했습니다. 다시 한 번 감사드립니다! – Nick

+0

예, 그 멋진 도구, 당신이 이것을 해결하는 방법을 찾은 것을 기쁘게 생각합니다. – ecastellano

관련 문제