Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Custom link for pagination WordPress

  • SOLVED

I am working on a Wordpress site (pstol.com). They like the home page format but would like to change the format/template to change when you click on pagination at the bottom of the page.

So the first item is the home page and is fine. Once they select 2, 3, 4, etc or any other number they want the format of the page to change to look like http://pstol.com/category/inspiration-board/

Is there an easy way to set this up.

A portion of home page code.

<div id="homepage">

<?php include(TEMPLATEPATH."/sidebar_left_home.php");?>

<div id="homepagemid" class="homepagemid">

<?php $wp_query = new WP_Query(array('cat'=>of_get_option('category_home'),'showposts'=>of_get_option('postnumber_home'), 'paged'=>$paged)); ?>
<?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php $meta_box = get_post_custom($post->ID); $video = $meta_box['custom_meta_video'][0]; ?>
<?php global $more; $more = 0; ?>

<div class="homepagecontent">

<?php if ( $video ) : ?>
<?php echo $video; ?>
<?php else: ?>

<?php if ( has_post_thumbnail() ) : ?>

<h1 class="featuredtitle"><span><?php echo (of_get_option('text_center') == '' ? cat_id_to_name(of_get_option('category_home')) : of_get_option('text_center')); ?></span></h1>

<?php endif; ?>


<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_post_thumbnail( 'home-thumbnail' ); ?> </a>
<?php endif; ?>

<div class="homeinfo">
<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>

<?php if(of_get_option('display_socialhome') == '1') { ?>
<div class="social_links">
<div class="tweet_btn">
<a href="http://twitter.com/share" class="twitter-share-button"
data-url="<?php the_permalink(); ?>"
data-via="<?php echo of_get_option('social_twitter_url'); ?>"
data-text="<?php the_title(); ?>"
data-related=""
data-count="horizontal"><?php _e("Tweet", 'organicthemes'); ?></a>
</div>
<div class="like_btn">
<fb:like href="<?php echo urlencode(get_permalink($post->ID)); ?>" layout="button_count" show_faces="false" width="100" font=""></fb:like>
</div>
<div class="plus_btn">
<g:plusone size="medium"></g:plusone>
</div>
</div>
<?php } else { ?>
<?php } ?>

</div>

</div>

<?php endwhile; ?>

<div id="pagination">
<?php if (function_exists("number_paginate")) { number_paginate(); } ?>
</div>

<?php else : ?>
<?php endif; ?>

</div>

<?php include(TEMPLATEPATH."/sidebar_home.php");?>

</div>

</div>

<?php get_footer(); ?>

Answers (2)

2012-10-18

John Cotton answers:

Hi Carlos

You haven't shown us the alternative HTML.

However, there is any easy way to do this. The code below shows you how:



$page = (get_query_var('paged')) ? get_query_var('paged') : 1;

// Code/HTML appearing in both

if( $page && $page > 1 ) {
// Do your page 2 layout

} else {
// Do your page 1 layout

}

// Code/HTML appearing in both

2012-10-18

Dbranes answers:

hi Carlos, here is one way to do it:

you can fx. copy the "category.php" or "archive.php" to "custom-template.php" and edit it the way you want.

(category.php or archive.php normally contains the category template, it depends on the template)

Then you have to include this into your "functions.php" file

function my_custom_template(){

if(is_front_page()){
$currpage = (get_query_var('paged'))?get_query_var('paged'):1;
if($currpage>1){
include(TEMPLATEPATH.'/custom-template.php');
exit;
}
}
}
add_action('template_redirect','my_custom_template');


This code check the current page number and kicks in if page>1, fx:

http://pstol.com/page/2/

and then it loads the custom-template.php instead of the default template page you are using.