Zupełnie nie znam się na PHP, aczkolwiek chciałabym by moja strona (Wordpress) była jak najbardziej funkcjonalna. Tym samym mam w indexie kod:
<div class="alignleft"><?php next_posts_link(__( '« Starsze Porady', 'kubrick')) ?></div>
<div class="alignright"><?php previous_posts_link(__( 'Nowsze Porady »', 'kubrick')) ?></div>
Chciałabym, by te linki kierowały do zakładek na stronie głównej, odpowiednio:
www.mojastrona.pl/?paged=1#zakladka
www.mojastrona.pl/?paged=2#zakladka
Znalazłam odpowiadający mojemu problemowi kod:
/**
* Display next post link that is adjacent to the current post.
*
* @since 1.5.0
*
* @param string $format Optional. Link anchor format.
* @param string $link Optional. Link permalink format.
* @param bool $in_same_cat Optional. Whether link should be in same category.
* @param string $excluded_categories Optional. Excluded categories IDs.
*/
function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') {
adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
}
/**
* Display adjacent post link.
*
* Can be either next post link or previous.
*
* @since 2.5.0
*
* @param string $format Link anchor format.
* @param string $link Link permalink format.
* @param bool $in_same_cat Optional. Whether link should be in same category.
* @param string $excluded_categories Optional. Excluded categories IDs.
* @param bool $previous Optional, default is true. Whether display link to previous post.
*/
function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
if ( $previous && is_attachment() )
$post = & get_post($GLOBALS['post']->post_parent);
else
$post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
if ( !$post )
return;
$title = $post->post_title;
if ( empty($post->post_title) ) $title = $previous ? __('Previous Post') : __('Next Post');
$title = apply_filters('the_title', $title, $post);
$date = mysql2date(get_option('date_format'), $post->post_date);
$string = '<a href="'.get_permalink($post).'">';
$link = $string . $link . '</a>';
$adjacent = $previous ? 'previous' : 'next';
echo apply_filters
( "{$adjacent}_post_link", $format, $link ); }
/**
* Retrieve get links for page numbers.
*
* @since 1.5.0
*
* @param int $pagenum Optional. Page ID.
* @return string
*/
function get_pagenum_link($pagenum = 1) {
$pagenum = (int) $pagenum;
$request = remove_query_arg( 'paged' );
$home_root = ( isset($home_root['path']) ) ?
$home_root['path'] : ''; $home_root = preg_quote( trailingslashit
( $home_root ), '|' );
$request = preg_replace('|^'. $home_root . '|', '', $request);
if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
$base = trailingslashit( get_bloginfo( 'home' ) );
if ( $pagenum > 1 ) {
$result = add_query_arg( 'paged', $pagenum, $base . $request );
} else {
$result = $base . $request;
}
} else {
$qs_regex = '|\?.*?$|';
if ( !empty( $qs_match[0
] ) ) { $query_string = $qs_match[0];
} else {
$query_string = '';
}
$request = ltrim($request, '/');
$base = trailingslashit( get_bloginfo( 'url' ) );
if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
$base .= 'index.php/';
if ( $pagenum > 1 ) {
$request = ( ( !empty( $request ) ) ? trailingslashit
( $request ) : $request ) . user_trailingslashit
( 'page/' . $pagenum, 'paged' ); }
$result = $base . $request . $query_string;
}
$result = apply_filters('get_pagenum_link', $result);
return $result;
}
/**
* Retrieve next posts pages link.
*
* Backported from 2.1.3 to 2.0.10.
*
* @since 2.0.10
*
* @param int $max_page Optional. Max pages.
* @return string
*/
function get_next_posts_page_link($max_page = 0) {
if ( !is_single() ) {
if ( !$paged )
$paged = 1;
$nextpage = intval($paged) + 1; if ( !$max_page || $max_page >= $nextpage )
return get_pagenum_link($nextpage);
}
}
/**
* Display or return the next posts pages link.
*
* @since 0.71
*
* @param int $max_page Optional. Max pages.
* @param boolean $echo Optional. Echo or return;
*/
function next_posts( $max_page = 0, $echo = true ) {
$output = esc_url( get_next_posts_page_link( $max_page ) );
if ( $echo )
else
return $output;
}
/**
* Return the next posts pages link.
*
* @since 2.7.0
*
* @param string $label Content for link text.
* @param int $max_page Optional. Max pages.
* @return string|null
*/
function get_next_posts_link( $label = 'Next Page »', $max_page = 0 ) {
if ( !$max_page ) {
$max_page = $wp_query->max_num_pages;
}
if ( !$paged )
$paged = 1;
$nextpage = intval($paged) + 1;
if ( !is_single
() && ( empty($paged) || $nextpage <= $max_page) ) { $attr = apply_filters( 'next_posts_link_attributes', '' );
return '<a href="' . next_posts
( $max_page, false ) . "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>'; }
}
/**
* Display the next posts pages link.
*
* @since 0.71
* @uses get_next_posts_link()
*
* @param string $label Content for link text.
* @param int $max_page Optional. Max pages.
*/
function next_posts_link( $label = 'Next Page »', $max_page = 0 ) {
echo get_next_posts_link
( $label, $max_page ); }
/**
* Retrieve previous post pages link.
*
* Will only return string, if not on a single page or post.
*
* Backported to 2.0.10 from 2.1.3.
*
* @since 2.0.10
*
* @return string|null
*/
function get_previous_posts_page_link() {
if ( !is_single() ) {
$nextpage = intval($paged) - 1; if ( $nextpage < 1 )
$nextpage = 1;
return get_pagenum_link($nextpage);
}
}
/**
* Display or return the previous posts pages link.
*
* @since 0.71
*
* @param boolean $echo Optional. Echo or return;
*/
function previous_posts( $echo = true ) {
$output = esc_url( get_previous_posts_page_link() );
if ( $echo )
else
return $output;
}
/**
* Return the previous posts pages link.
*
* @since 2.7.0
*
* @param string $label Optional. Previous page link text.
* @return string|null
*/
function get_previous_posts_link( $label = '« Previous Page' ) {
if ( !is_single() && $paged > 1 ) {
$attr = apply_filters( 'previous_posts_link_attributes', '' );
return '<a href="' . previous_posts
( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&$1', $label ) .'</a>'; }
}
/**
* Display the previous posts page link.
*
* @since 0.71
* @uses get_previous_posts_link()
*
* @param string $label Optional. Previous page link text.
*/
function previous_posts_link( $label = '« Previous Page' ) {
echo get_previous_posts_link
( $label ); }
/**
* Return post pages link navigation for previous and next pages.
*
* @since 2.8
*
* @param string|array $args Optional args.
* @return string The posts link navigation.
*/
function get_posts_nav_link
( $args = array() ) {
$return = '';
if ( !is_singular() ) {
'sep' => ' — ',
'prelabel' => __('« Previous Page'),
'nxtlabel' => __('Next Page »'),
);
$args = wp_parse_args( $args, $defaults );
$max_num_pages = $wp_query->max_num_pages;
$paged = get_query_var('paged');
//only have sep if there's both prev and next results
if ($paged < 2 || $paged >= $max_num_pages) {
$args['sep'] = '';
}
if ( $max_num_pages > 1 ) {
$return = get_previous_posts_link($args['prelabel']);
$return .= preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $args['sep']); $return .= get_next_posts_link($args['nxtlabel']);
}
}
return $return;
}
/**
* Display post pages link navigation for previous and next pages.
*
* @since 0.71
*
* @param string $sep Optional. Separator for posts navigation links.
* @param string $prelabel Optional. Label for previous pages.
* @param string $nxtlabel Optional Label for next pages.
*/
function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) {
echo get_posts_nav_link
($args); }
Będę wdzięczna za pomoc.
Ten post edytował Spawnm 14.07.2010, 09:01:26
Powód edycji: [Spawnm]: