wordpress nivo滑块在post期间创建自定义永久链接选项?

wordpress nivo滑块在post期间创建自定义永久链接选项?,wordpress,slider,nivo-slider,Wordpress,Slider,Nivo Slider,我没有使用nivo slider wordpress插件,而是使用常规的nivo slider jquery并在wordpress中实现它,目前我的“阅读更多”按钮如下所示: <a href='".get_permalink()."'>Read More</a> 我想要实现的是类似于get\u permalinkpage?因此,基本上我希望能够使阅读更多链接到我选择的wordpress页面,而不是帖子的永久链接。但我不知道如何在posts页面上实现一个自定义选项,允

我没有使用nivo slider wordpress插件,而是使用常规的nivo slider jquery并在wordpress中实现它,目前我的“阅读更多”按钮如下所示:

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

我想要实现的是类似于
get\u permalinkpage
?因此,基本上我希望能够使阅读更多链接到我选择的wordpress页面,而不是帖子的永久链接。但我不知道如何在posts页面上实现一个自定义选项,允许用户说“从页面中选择链接nivo滑块幻灯片的页面:(然后在网站上显示页面)”,然后输出该选择


有什么帮助吗?这是我需要为我们的网站实现的最后一件事

好的,我这里有你的答案,因为这是我最近自己做的事情。这实际上是一个关于自定义元数据库的问题。这里有一些关于它的参考资料——我收到了一个推荐这个的朋友发来的链接

在《骨头主题》中,作者推荐了这个主题

如果你想快速开始,我会在这里发布一些代码。我会将下面的代码放在它自己的文件中,并从functions.php(ie)中包含它

 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 home幻灯片链接。要使用该url,您需要在模板循环中包括以下内容,同时建立Nivoslider图像列表

 <?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>';
 ?>

因此,如果文章为滑块链接设置了url,那么它将使用该url,如果没有,则默认为永久链接


希望这对你有所帮助

这是基于您的解决方案的我的解决方案

<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;
?>  


这个解决方案与McNab的有什么不同?