• Resolved pj

    (@psinco)


    In single posts that I divided into multiple pages using <!–nextpage–>, I would like to style the extra pages differently. I probably need to use a conditional tag in the Loop, but I can’t figure out how WordPress distinguishes the remaining pages in a multi-page post from the opening post page. In other words, I don’t know how WordPress knows it’s on Page 3 of a long post rather than on Page 1. I want Page 2, Page 3, etc., to look slightly different than Page 1.

    Does anyone have any suggestions on how to accomplish this?

Viewing 9 replies - 1 through 9 (of 9 total)
  • One way to do this would be to wrap the contents of page2 in a div and assign a class of page2. Then you can assign CSS styling in your stylesheet to override the default styling of page2, page3, etc. You’d assign those classes on the editor’s HTML tab.

    <!--nextpage-->
    <div class="page2>
    <h2>Page 2 content goes here</h2>
    <p>some text</p>
    </div>
    
    <!--nextpage-->
    <div class="page3>
    <h2>Page 3 content goes here</h2>
    <p>some text</p>
    </div>

    stylesheet:

    #content .page2 p { color: #123456; margin-top: 20px; }
    #content .page3 p { color: #654321; margin-top: 10px; }

    I have the same question. There is a bug in WordPress that causes the_content not to work properly in sidebars after pagination (i.e., the_content() works in sidebars on page 1 of a paginated post, but not on subsequent pages 2, 3, 4, 5, etc).

    Because of this, I want to disable a sidebar block based on whether or not it’s the first page of a paginated post. Therefore, the aforementioned solution (for styling purposes) will not work for me.

    WordPress has some way of knowing what page it is – some kind of property. What is this property, and how can I create a conditional statement using it?

    Thanks!

    @robbono:
    When on the 1st page of paginated post, this variable will not exist:
    $wp_query->query_vars['page']

    When on the second page its value will be “2”.

    you can test for 1st page with
    if ( isset($wp_query->query_vars['page'] ))
    if it returns false you are on the 1st page.

    Great! At least if I can’t fix the sidebar the_content() bug, I can disable the block in question on the 2nd and later posts. Thanks again!

    I don’t know what you are after, but I just displayed post content that is displayed in the main post area, in the sidebar, on all pages of a paginated post with echo $post->post_content

    However it’s the full content, not paged. It would have to be run through some filters to page it.

    If you are trying to display posts in the sidebar, you are better off using a custom WP query – see
    https://weblogtoolscollection.com/archives/2008/04/13/define-your-own-wordpress-loop-using-wp_query/

    Thread Starter pj

    (@psinco)

    you can test for 1st page with
    if ( isset($wp_query->query_vars[‘page’] ))
    if it returns false you are on the 1st page.

    This works beautifully. Thank you for the great suggestions.

    @stvwlf – Yep, I could use $post->post_content, but what I’m trying to display is a poll using WP-Polls – so the content only displays as [poll-id: 8], which triggers WP-Polls to display the poll. It only works when it’s run through the_content(), not when echoed as a variable. My knowledge of filters doesn’t go far enough for me to figure out how to get it to trigger WP-Polls plugin, so I’m just going to have to hide the block until the sidebar issue is fixed.

    BTW, I’m using a custom WP-Query, but there’s a reported bug with WordPress not clearing out globals on the 2nd page (even when using wp_reset_query() ), so no matter what I do, the_content() always displays the wrong content – but that’s a topic for another post.

    Thanks again for the conditional advice! I’ll be using that for now!

    you can test for 1st page with
    if ( isset($wp_query->query_vars[‘page’] ))
    if it returns false you are on the 1st page.

    so there is no function to determine if a post is on the paginated page. not like is_paged();

    Hello,
    Can I change the way numbers are showing up in multi-page posts in Twenty Ten theme? I can’t find the piece of CSS code that is responsible for that.
    (I would like to remove the grey background and use some border-radius for the corners.)
    thnx.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Styling multiple-page posts’ is closed to new replies.