• I am having a problem getting the more tag to work in a custom page I have designed for a WordPress website I am currently working on, I have read through the codex and have used the following inside the loop of my custom page:

    <?php
    global $more;
    $more = 0;
    ?>
    //The code must be inserted ahead of the call to the content

    <?php the_content(‘Continue Reading’); ?>

    This has successfully shown the ‘continue reading’ tag on my page but when I click the tag nothing happens, is there something else I have to do in order for it to reveal the content?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Anonymous User 7658014

    (@anonymized_7658014)

    Does your site have a URL?

    Thread Starter saffa803

    (@saffa803)

    At the moment I’m running it on a local testing server(MAMP)

    Thread Starter saffa803

    (@saffa803)

    This is what I have in my custom page template:

    get_header(); ?>
    
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    
    				<h3><?php the_title(); ?></h3>
    				<?php global $more;$more = 0;?>
    				<?php the_content('More on the Artist >>'); ?>
    				<?php wp_link_pages( array( 'before' => '' . __( 'Pages:', 'twentyten' ), 'after' => '' ) ); ?>
    				<?php edit_post_link( __( 'Edit', 'twentyten' ), '', '' ); ?>
    
    				<?php comments_template( '', true ); ?>
    
    <?php endwhile; ?>
    
    <?php get_footer(); ?>

    I’m using the Starkers naked theme as a building block as I’m new to wordpress.

    Anonymous User 7658014

    (@anonymized_7658014)

    So you actually see the more link and click on it and nothing happens? Where does the link point to? When you place your cursor on it without clicking, what URL is shown in the bottom status bar of your browser?

    Thread Starter saffa803

    (@saffa803)

    Anonymous User 7658014

    (@anonymized_7658014)

    There are a colon and an endif-tag missing in your template. Try:

    get_header(); ?>
    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    				<h3><?php the_title(); ?></h3>
    				<?php global $more;$more = 0;?>
    				<?php the_content('More on the Artist >>'); ?>
    				<?php wp_link_pages( array( 'before' => '' . __( 'Pages:', 'twentyten' ), 'after' => '' ) ); ?>
    				<?php edit_post_link( __( 'Edit', 'twentyten' ), '', '' ); ?>
    
    				<?php comments_template( '', true ); ?>
    
    <?php endwhile; endif; ?>
    
    <?php get_footer(); ?>
    Thread Starter saffa803

    (@saffa803)

    Thanks for the suggestion, I added the colon and endif-tag as above but still no luck in getting the content to show once the more tag is clicked.

    Anonymous User 7658014

    (@anonymized_7658014)

    Sorry, I’m sort of trying to figure out what you’re trying to achieve with that page template of yours. Is it supposed to display an actual page (that is: the post-type “page”)? Because if so, then there is no “more” functionality. WordPress just doesn’t do it on pages, only on posts (post-type “post”).

    On the other hand, if you’re trying to display a chronological list of posts (post-type “post”) with that page template, you need to set up a custom loop first. Check out the Codex for WP_Query. It’s a fine piece of machinery!
    In your case, you’d probably want to set up something like:

    get_header(); 
    
    // Set up a new WP_Query to tell WordPress what kind of posts you want
    $my_query = new WP_Query( array( 'post_type' => 'post', 'status' => 'published' ) );
    
    // Now start your new loop with those if and while statements
    if ( $my_query->have_posts() ) :
    	while ( $my_query->have_posts() ) :
    		$my_query->the_post();
    		global $more; // don't forget to reset the $more variable
    		$more = 0;
    ?>
    
    <h3><?php the_title(); ?></h3>
    <?php the_content( 'More on the Artist >>' ); ?>
    <?php wp_link_pages( array( 'before' => '' . __( 'Pages:', 'twentyten' ), 'after' => '' ) ); ?>
    <?php edit_post_link( __( 'Edit', 'twentyten' ), '', '' ); ?>
    
    <?php comments_template( '', true ); ?>
    
    <?php endwhile; // ends the while statement from above
    endif; // ends the if statement from above
    
    // Because you used the_post(), you need to reset all post data,
    // otherwise things will likely get messed up for you later
    wp_reset_postdata();
    
    // And that was your custom loop!
    ?>
    
    <?php get_footer(); ?>

    Hope that helps!

    Thread Starter saffa803

    (@saffa803)

    Thanks for getting back to me. I will have a look into the codex for WP_Query.

    What I am trying to achieve is: I have four paragraphs of content which I would to be displayed after the more tag is clicked.

    Anonymous User 7658014

    (@anonymized_7658014)

    Well, if that’s all you’re trying to do, forget about WP_Query! The more tag is just not the way to go then, because you have a single page content, not a query of posts. The more tag simply does not work with pages, that’s it.

    You could use Javascript, i.e. a jQuery function, to achieve what you want to do. But to be honest, if it was my project, I’d re-evaluate if the effect I get from it is worth the effort of adding a bunch of Javscript.

    Thread Starter saffa803

    (@saffa803)

    Thanks for your help.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘More tag on custom pages’ is closed to new replies.