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(__( '&laquo; Starsze Porady', 'kubrick')) ?></div>
<div class="alignright"><?php previous_posts_link(__( 'Nowsze Porady &raquo;', '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:

  1. /**
  2.  * Display next post link that is adjacent to the current post.
  3.  *
  4.  * @since 1.5.0
  5.  *
  6.  * @param string $format Optional. Link anchor format.
  7.  * @param string $link Optional. Link permalink format.
  8.  * @param bool $in_same_cat Optional. Whether link should be in same category.
  9.  * @param string $excluded_categories Optional. Excluded categories IDs.
  10.  */
  11. function next_post_link($format='%link &raquo;', $link='%title', $in_same_cat = false, $excluded_categories = '') {
  12. adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
  13. }
  14.  
  15. /**
  16.  * Display adjacent post link.
  17.  *
  18.  * Can be either next post link or previous.
  19.  *
  20.  * @since 2.5.0
  21.  *
  22.  * @param string $format Link anchor format.
  23.  * @param string $link Link permalink format.
  24.  * @param bool $in_same_cat Optional. Whether link should be in same category.
  25.  * @param string $excluded_categories Optional. Excluded categories IDs.
  26.  * @param bool $previous Optional, default is true. Whether display link to previous post.
  27.  */
  28. function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
  29. if ( $previous && is_attachment() )
  30. $post = & get_post($GLOBALS['post']->post_parent);
  31. else
  32. $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
  33.  
  34. if ( !$post )
  35. return;
  36.  
  37. $title = $post->post_title;
  38.  
  39. if ( empty($post->post_title) )
  40. $title = $previous ? __('Previous Post') : __('Next Post');
  41.  
  42. $title = apply_filters('the_title', $title, $post);
  43. $date = mysql2date(get_option('date_format'), $post->post_date);
  44.  
  45. $string = '<a href="'.get_permalink($post).'">';
  46. $link = str_replace('%title', $title, $link);
  47. $link = str_replace('%date', $date, $link);
  48. $link = $string . $link . '</a>';
  49.  
  50. $format = str_replace('%link', $link, $format);
  51.  
  52. $adjacent = $previous ? 'previous' : 'next';
  53. echo apply_filters( "{$adjacent}_post_link", $format, $link );
  54. }
  55.  
  56. /**
  57.  * Retrieve get links for page numbers.
  58.  *
  59.  * @since 1.5.0
  60.  *
  61.  * @param int $pagenum Optional. Page ID.
  62.  * @return string
  63.  */
  64. function get_pagenum_link($pagenum = 1) {
  65. global $wp_rewrite;
  66.  
  67. $pagenum = (int) $pagenum;
  68.  
  69. $request = remove_query_arg( 'paged' );
  70.  
  71. $home_root = parse_url(get_option('home'));
  72. $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
  73. $home_root = preg_quote( trailingslashit( $home_root ), '|' );
  74.  
  75. $request = preg_replace('|^'. $home_root . '|', '', $request);
  76. $request = preg_replace('|^/+|', '', $request);
  77.  
  78. if ( !$wp_rewrite->using_permalinks() || is_admin() ) {
  79. $base = trailingslashit( get_bloginfo( 'home' ) );
  80.  
  81. if ( $pagenum > 1 ) {
  82. $result = add_query_arg( 'paged', $pagenum, $base . $request );
  83. } else {
  84. $result = $base . $request;
  85. }
  86. } else {
  87. $qs_regex = '|\?.*?$|';
  88. preg_match( $qs_regex, $request, $qs_match );
  89.  
  90. if ( !empty( $qs_match[0] ) ) {
  91. $query_string = $qs_match[0];
  92. $request = preg_replace( $qs_regex, '', $request );
  93. } else {
  94. $query_string = '';
  95. }
  96.  
  97. $request = preg_replace( '|page/\d+/?$|', '', $request);
  98. $request = preg_replace( '|^index\.php|', '', $request);
  99. $request = ltrim($request, '/');
  100.  
  101. $base = trailingslashit( get_bloginfo( 'url' ) );
  102.  
  103. if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )
  104. $base .= 'index.php/';
  105.  
  106. if ( $pagenum > 1 ) {
  107. $request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( 'page/' . $pagenum, 'paged' );
  108. }
  109.  
  110. $result = $base . $request . $query_string;
  111. }
  112.  
  113. $result = apply_filters('get_pagenum_link', $result);
  114.  
  115. return $result;
  116. }
  117.  
  118. /**
  119.  * Retrieve next posts pages link.
  120.  *
  121.  * Backported from 2.1.3 to 2.0.10.
  122.  *
  123.  * @since 2.0.10
  124.  *
  125.  * @param int $max_page Optional. Max pages.
  126.  * @return string
  127.  */
  128. function get_next_posts_page_link($max_page = 0) {
  129. global $paged;
  130.  
  131. if ( !is_single() ) {
  132. if ( !$paged )
  133. $paged = 1;
  134. $nextpage = intval($paged) + 1;
  135. if ( !$max_page || $max_page >= $nextpage )
  136. return get_pagenum_link($nextpage);
  137. }
  138. }
  139.  
  140. /**
  141.  * Display or return the next posts pages link.
  142.  *
  143.  * @since 0.71
  144.  *
  145.  * @param int $max_page Optional. Max pages.
  146.  * @param boolean $echo Optional. Echo or return;
  147.  */
  148. function next_posts( $max_page = 0, $echo = true ) {
  149. $output = esc_url( get_next_posts_page_link( $max_page ) );
  150.  
  151. if ( $echo )
  152. echo $output;
  153. else
  154. return $output;
  155. }
  156.  
  157. /**
  158.  * Return the next posts pages link.
  159.  *
  160.  * @since 2.7.0
  161.  *
  162.  * @param string $label Content for link text.
  163.  * @param int $max_page Optional. Max pages.
  164.  * @return string|null
  165.  */
  166. function get_next_posts_link( $label = 'Next Page &raquo;', $max_page = 0 ) {
  167. global $paged, $wp_query;
  168.  
  169. if ( !$max_page ) {
  170. $max_page = $wp_query->max_num_pages;
  171. }
  172.  
  173. if ( !$paged )
  174. $paged = 1;
  175.  
  176. $nextpage = intval($paged) + 1;
  177.  
  178. if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) {
  179. $attr = apply_filters( 'next_posts_link_attributes', '' );
  180. return '<a href="' . next_posts( $max_page, false ) . "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';
  181. }
  182. }
  183.  
  184. /**
  185.  * Display the next posts pages link.
  186.  *
  187.  * @since 0.71
  188.  * @uses get_next_posts_link()
  189.  *
  190.  * @param string $label Content for link text.
  191.  * @param int $max_page Optional. Max pages.
  192.  */
  193. function next_posts_link( $label = 'Next Page &raquo;', $max_page = 0 ) {
  194. echo get_next_posts_link( $label, $max_page );
  195. }
  196.  
  197. /**
  198.  * Retrieve previous post pages link.
  199.  *
  200.  * Will only return string, if not on a single page or post.
  201.  *
  202.  * Backported to 2.0.10 from 2.1.3.
  203.  *
  204.  * @since 2.0.10
  205.  *
  206.  * @return string|null
  207.  */
  208. function get_previous_posts_page_link() {
  209. global $paged;
  210.  
  211. if ( !is_single() ) {
  212. $nextpage = intval($paged) - 1;
  213. if ( $nextpage < 1 )
  214. $nextpage = 1;
  215. return get_pagenum_link($nextpage);
  216. }
  217. }
  218.  
  219. /**
  220.  * Display or return the previous posts pages link.
  221.  *
  222.  * @since 0.71
  223.  *
  224.  * @param boolean $echo Optional. Echo or return;
  225.  */
  226. function previous_posts( $echo = true ) {
  227. $output = esc_url( get_previous_posts_page_link() );
  228.  
  229. if ( $echo )
  230. echo $output;
  231. else
  232. return $output;
  233. }
  234.  
  235. /**
  236.  * Return the previous posts pages link.
  237.  *
  238.  * @since 2.7.0
  239.  *
  240.  * @param string $label Optional. Previous page link text.
  241.  * @return string|null
  242.  */
  243. function get_previous_posts_link( $label = '&laquo; Previous Page' ) {
  244. global $paged;
  245.  
  246. if ( !is_single() && $paged > 1 ) {
  247. $attr = apply_filters( 'previous_posts_link_attributes', '' );
  248. return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/', '&$1', $label ) .'</a>';
  249. }
  250. }
  251.  
  252. /**
  253.  * Display the previous posts page link.
  254.  *
  255.  * @since 0.71
  256.  * @uses get_previous_posts_link()
  257.  *
  258.  * @param string $label Optional. Previous page link text.
  259.  */
  260. function previous_posts_link( $label = '&laquo; Previous Page' ) {
  261. echo get_previous_posts_link( $label );
  262. }
  263.  
  264. /**
  265.  * Return post pages link navigation for previous and next pages.
  266.  *
  267.  * @since 2.8
  268.  *
  269.  * @param string|array $args Optional args.
  270.  * @return string The posts link navigation.
  271.  */
  272. function get_posts_nav_link( $args = array() ) {
  273. global $wp_query;
  274.  
  275. $return = '';
  276.  
  277. if ( !is_singular() ) {
  278. $defaults = array(
  279. 'sep' => ' — ',
  280. 'prelabel' => __('&laquo; Previous Page'),
  281. 'nxtlabel' => __('Next Page &raquo;'),
  282. );
  283. $args = wp_parse_args( $args, $defaults );
  284.  
  285. $max_num_pages = $wp_query->max_num_pages;
  286. $paged = get_query_var('paged');
  287.  
  288. //only have sep if there's both prev and next results
  289. if ($paged < 2 || $paged >= $max_num_pages) {
  290. $args['sep'] = '';
  291. }
  292.  
  293. if ( $max_num_pages > 1 ) {
  294. $return = get_previous_posts_link($args['prelabel']);
  295. $return .= preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $args['sep']);
  296. $return .= get_next_posts_link($args['nxtlabel']);
  297. }
  298. }
  299. return $return;
  300.  
  301. }
  302.  
  303. /**
  304.  * Display post pages link navigation for previous and next pages.
  305.  *
  306.  * @since 0.71
  307.  *
  308.  * @param string $sep Optional. Separator for posts navigation links.
  309.  * @param string $prelabel Optional. Label for previous pages.
  310.  * @param string $nxtlabel Optional Label for next pages.
  311.  */
  312. function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) {
  313. $args = array_filter( compact('sep', 'prelabel', 'nxtlabel') );
  314. echo get_posts_nav_link($args);
  315. }



Będę wdzięczna za pomoc.