• ben1234

    (@ben1234)


    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

Viewing 6 replies - 1 through 6 (of 6 total)
  • Michael

    (@alchymyth)

    wordpress offers a conditional tag to see if you are on a paged page:
    https://codex.www.ads-software.com/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; ?>
    Thread Starter ben1234

    (@ben1234)

    Thanks alchymyth, just about to test it out.

    Thread Starter ben1234

    (@ben1234)

    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

    Michael

    (@alchymyth)

    <?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’ ).

    Thread Starter ben1234

    (@ben1234)

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

    Michael

    (@alchymyth)

    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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Second page of a post different design’ is closed to new replies.