WordPress.org

Ready to get started?Download WordPress

Forums

Second page of a post different design (7 posts)

  1. ben1234
    Member
    Posted 4 years ago #

    Hi everyone,

    I have a wordpress blog and have paginated the posts. I would like to have the second and following pages of each post a different layout to the first page (eg. no sidebar on pages 2 and onwards). This is so there is more more room on the posts for big photos and videos.

    Any ideas would be greatly appreciated. Thanks Ben

  2. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    wordpress offers a conditional tag to see if you are on a paged page:
    http://codex.wordpress.org/Conditional_Tags#A_Paged_Page

    you can then build your different structure from there:

    <?php if(is_paged()) :
    different layout;
    else :
    first page layout;
    endif; ?>
  3. ben1234
    Member
    Posted 4 years ago #

    Thanks alchymyth, just about to test it out.

  4. ben1234
    Member
    Posted 4 years ago #

    Hi again, I am new very to php and the code below isn't working properly, can anyone see why? (probably really obvious)

    <?php
    if(is_paged())
    <?php get_sidebar(); ?>
    <?php get_header(); ?>
    
    else
    
     <?php get_header(); ?>
    ?>

    Thanks Ben

  5. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    <?php
    get_header();
    if(!is_paged()) {
    get_sidebar(); }
    
    ?>

    removed excess code, sorted it into the right order; and made sure that the php tags are opened and closed in the right order.

    (what was unusual with your code, was that you called the sidebar.php before the header.php, as the header.php would usually contain the DOCTYPE declaration and the html 'head' section and would be called first.)

    also, you were including the sidebar especially on the paged pages, so i changed it to !is_paged() which is the negation ( 'if is not paged' ).

  6. ben1234
    Member
    Posted 4 years ago #

    Thats works now, thanks for your help! One more questions, why can't you have a <div> inside an if statement?

  7. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    you cannot have html tags within php tags;
    ie. the if statement is written in php, and the div would be html.

    take a bit of time and look closely into some themes, and see how they change from php to html and back to php.

    an if statement example could be written like this:

    <?php if(!is_paged()) { ?>
    <div id="pagenumber">
    you are on page no:
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    echo $paged; ?>
    </div>
    <?php } ?>
    back to normal html etc.

    the php tag is always closed before a html tag is opened or any html code is entered.

Topic Closed

This topic has been closed to new replies.

About this Topic