2012-07-25 2 views
-1

내가 대신 나는 일반 NIVO 슬라이더 jQuery를 사용하고는 NIVO 슬라이더 워드 프레스 플러그인을 사용하고 워드 프레스에서 작동하도록 구현, 현재 내 "더 읽기"아니에요 버튼은 다음과 같다 :게시 도중 맞춤 퍼 뮤 링크 옵션을 만드는 wordpress nivo 슬라이더?

<a href='".get_permalink()."'>Read More</a> 

내가 원하는 무엇 구현하려면 get_permalinkpage과 같은 무엇입니까? 그래서 기본적으로 나는 게시물의 permalink 대신에 나의 선택의 wordpress 페이지에 더 많은 링크를 읽을 수 있도록하고 싶다. 그러나 사용자가 "nivo 슬라이더 슬라이드를 연결할 페이지에서 선택하여 (다음 웹 사이트의 페이지를 보여줍니다") 말할 수있는 게시물 페이지에 사용자 지정 옵션을 구현 한 다음 해당 선택 항목을 출력하는 방법을 모르겠습니다.

어떤 도움이 필요합니까? 이것이 우리 웹 사이트에 구현해야 할 마지막 사항입니다!

답변

1

맞아, 나는 최근에 내가 한 일인 것처럼 당신의 대답을 가지고 있습니다. 이것은 정말 맞춤 대사에 관한 질문입니다. 여기에 약간의 자료가 있습니다 - 나는 이것을 추천하는 친구에게서 그것에 대한 링크를 보냈습니다;

http://www.deluxeblogtips.com/meta-box/

그리고 뼈 테마에서 저자는 이것을 권장

; 당신이 빨리와 가야 할 경우

https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress

나는 여기에 몇 가지 코드를 게시 할 예정입니다. 나는 그것의 파일에 다음 코드를 넣고 functions.php에서 그것을 포함시킬 것이다.

require_once('includes/metabox-post.php'); 

테마 디렉토리에 includes 디렉토리를 만들고이 코드가 포함 된 파일을 만듭니다.

<?php 

/* CUSTOM METABOX -----------------------------------------------------*/ 

//We create an array called $meta_box and set the array key to the relevant post type 
$meta_box_post['post'] = array( 

//This is the id applied to the meta box 
'id' => 'post-format-meta', 

//This is the title that appears on the meta box container 
'title' => 'My Custom Metabox',  

//This defines the part of the page where the edit screen section should be shown 
'context' => 'normal',  

//This sets the priority within the context where the boxes should show 
'priority' => 'high', 

//Here we define all the fields we want in the meta box 
'fields' => array( 
    array(
     'name' => 'Home Slider Link', 
     'desc' => 'You can create a custom link for the home slider image (ie to link to the shop). If left blank, it will by default link through to this post.', 
     'id' => 'home-slide-link', 
     'type' => 'text', 
     'default' => '' 
    ) 

    ) 

); 

add_action('admin_menu', 'meta_add_box_post'); 


//Add meta boxes to post types 
function meta_add_box_post() { 
global $meta_box_post; 

foreach($meta_box_post as $post_type => $value) { 
    add_meta_box($value['id'], $value['title'], 'meta_format_box_post', $post_type, $value['context'], $value['priority']); 
    } 
} 

//Format meta boxes 
function meta_format_box_post() { 
    global $meta_box_post, $post; 

    // Use nonce for verification 
    echo '<input type="hidden" name="plib_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />'; 

    echo '<table class="form-table">'; 

    foreach ($meta_box_post[$post->post_type]['fields'] as $field) { 
     // get current post meta data 
     $meta = get_post_meta($post->ID, $field['id'], true); 

     echo '<tr>'. 
       '<th style="width:20%"><label for="'. $field['id'] .'">'. $field['name']. '</label></th>'. 
       '<td>'; 
    switch ($field['type']) { 
     case 'text': 
      echo '<input type="text" name="'. $field['id']. '" id="'. $field['id'] .'" value="'. ($meta ? $meta : $field['default']) . '" size="30" style="width:97%" />'. '<br />'. $field['desc']; 
      break; 
     case 'textarea': 
      echo '<textarea name="'. $field['id']. '" id="'. $field['id']. '" cols="60" rows="4" style="width:97%">'. ($meta ? $meta : $field['default']) . '</textarea>'. '<br />'. $field['desc']; 
      break; 
     case 'select': 
      echo '<select name="'. $field['id'] . '" id="'. $field['id'] . '">'; 
      foreach ($field['options'] as $option) { 
       echo '<option '. ($meta == $option ? ' selected="selected"' : '') . '>'. $option . '</option>'; 
      } 
      echo '</select>'; 
      break; 
     case 'radio': 
      foreach ($field['options'] as $option) { 
       echo '<input type="radio" name="' . $field['id'] . '" value="' . $option['value'] . '"' . ($meta == $option['value'] ? ' checked="checked"' : '') . ' />' . $option['name']; 
      } 
      break; 
     case 'checkbox': 
      echo '<input type="checkbox" name="' . $field['id'] . '" id="' . $field['id'] . '"' . ($meta ? ' checked="checked"' : '') . ' /<br />&nbsp;&nbsp;'. $field['desc']; 
      break; 
    } 
    echo  '<td>'.'</tr>'; 
    } 

    echo '</table>'; 

} 

// Save data from meta box 
function meta_save_data_post($post_id) { 
    global $meta_box_post, $post; 

    //Verify nonce 
    if (!wp_verify_nonce($_POST['plib_meta_box_nonce'], basename(__FILE__))) { 
     return $post_id; 
    } 

    //Check autosave 
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { 
     return $post_id; 
    } 

    //Check permissions 
    if ('page' == $_POST['post_type']) { 
     if (!current_user_can('edit_page', $post_id)) { 
      return $post_id; 
     } 
    } elseif (!current_user_can('edit_post', $post_id)) { 
     return $post_id; 
    } 

    foreach ($meta_box_post[$post->post_type]['fields'] as $field) { 
     $old = get_post_meta($post_id, $field['id'], true); 
     $new = $_POST[$field['id']]; 

     if ($new && $new != $old) { 
      update_post_meta($post_id, $field['id'], $new); 
     } elseif ('' == $new && $old) { 
      delete_post_meta($post_id, $field['id'], $old); 
     } 
    } 
} 

add_action('save_post', 'meta_save_data_post'); 


?> 

이렇게하면 대체 url에 입력 할 수있는 게시물에 새로운 맞춤 대사가 추가됩니다. 이 사용자 정의 옵션의 id는 홈 슬라이드 링크입니다. 해당 URL을 사용하려면 Nivoslider 이미지 목록을 작성하는 동안 템플릿 루프에 다음을 포함시킵니다. 포스트 슬라이더 링크에 대해 설정된 URL이있는 경우

<?php 
if (get_post_meta($post->ID, 'home-slide-link', true)) : 
    $slideLink = get_post_meta($post->ID, 'home-slide-link', true); 
else : 
    $slideLink = get_permalink(); 
endif; 

    echo '<a href="'. $slideLink .'"><img src="image link in here" /></a>'; 
?> 

그래서 그것은 영구 링크에 해당하지 않을 경우 기본값을 사용합니다.

희망이 조금 도움이 되었어요!

+0

매우 고맙습니다. –

+0

아름답게 일했습니다! –

1

다음은 내 솔루션을 기반으로합니다.

<div id="slider"> 
<?php 
    $captions = array(); 
    $tmp = $wp_query; 
    $wp_query = new WP_Query('cat='.$category.'&posts_per_page=$n_slices'); 
    if($wp_query->have_posts()) : 
     while($wp_query->have_posts()) : 
      $wp_query->the_post(); 
      $captions[] = '<p>'.get_the_title($post->ID).'</p><p>'.get_the_excerpt().'</p>'; 
      $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'nivothumb'); 
      $mykey_values = get_post_custom_values('home-slide-link'); 
?> 

<a href="<?php echo $mykey_values[0] ?>"> 
    <img src="<?php echo $image[0]; ?>" class="attachment-nivothumb wp-post-image" title="#caption<?php echo count($captions)-1; ?>" alt="<?php the_title_attribute(); ?>" /> 
</a> 
<?php 
     endwhile; 
    endif; 
    $wp_query = $tmp; 
?> 
</div><!-- close #slider --> 

<?php 
    foreach($captions as $key => $caption) : 
?> 
    <div id="caption<?php echo $key; ?>" class="nivo-html-caption"> 
     <?php echo $caption;?> 
    </div> 
<?php 
    endforeach; 
?> 
+0

McNab의 솔루션과 다른 점은 무엇입니까? –