WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to make MORE tag work on Pages? (12 posts)

  1. Ivovic
    Member
    Posted 6 years ago #

    Hi guys,

    I realise MORE tags don't work on pages, but that is a little bit limiting with regard to my sidebar. I have a couple of (the) loops in my sidebar to display short posts from certain categories, but they often have more tags which need to be respected in the sidebar, regardless of which page is being viewed.

    Is there a good reason for disabling MORE on pages? - I mean, unless there's a more tag in the page text itself, it shouldn't really be an issue should it?

    How to I "fix" that to behave as I'd like it to?

    Cheers for the help guys :)

  2. moshu
    Member
    Posted 6 years ago #

    There is a "good reason": in WP there is no such thing like multiple display of Pages, like there is in the case of posts. Hence, there is no need to have a "more" tag in Pages.

    I admit, since the introduction of the "pick-a-Page-as-your-homepage" feature things started to be messed up because now you can have a Page to display your posts... but WP is still 'recognizing' those Pages as Page - and not letting the "more" tag to work properly. (In the core files a Page is defined as something that will not display the "more".)

    On a test install where I have a Page set as home/main and still wanted to list several recent posts with the "more" link... I put this into the custom query:
    <?php $more = 0; ?>
    It worked.

    HTH

  3. Ivovic
    Member
    Posted 6 years ago #

    Thanks for the quick response moshu.

    <?php $more=0; query_posts('cat=66'); while (have_posts()) : the_post(); ?>

    Is this what you mean't moshu?... because it doesn't work when it's in the sidebar. :(

    I understand the good reason to a certain degree... but there must be a better way to check for the MORE tag.

    Ideally, wordpress should check the entry being displayed to see if it is Page Text or Category Text before deciding to strip the more tag... this would avoid disabling the more function entirely for page.php

    As you say, with more people "extracting" content for display in various areas, it will be important to treat the more tag differently than it is being treated now.

    In the mean time though, I need to get this resolved...

    Cheers again for your help so far.

  4. moshu
    Member
    Posted 6 years ago #

    Actually, I have something like this:

    Recent posts
    <?php $more = 0; ?>
    <?php query_posts('category_name=uncategorized&showposts=5'); ?>
    
    <?php while (have_posts()) : the_post(); ?>
      <div class="post" id="post-<?php the_ID(); ?>">
    		<ul><li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li></ul>
    			<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    	</div>
    <?php endwhile; ?>
  5. Ivovic
    Member
    Posted 6 years ago #

    I shouldn't make any difference, but I changed it to reflect what you have as closely as I could.

    I tried:

    <?php $more = 0; ?>
    <?php query_posts('category_name=passing-thoughts&showposts=5'); ?>
    <?php while (have_posts()) : the_post(); ?>

    It's not doing anything at all, in sidebar.php anyway :(

    I really appreciate your effort moshu, not sure why yours works and mine does not.

  6. Ivovic
    Member
    Posted 6 years ago #

    Just bumping this with fingers crossed :)

  7. Ivovic
    Member
    Posted 6 years ago #

    ok, I want to thank moshu for the very valuable hint here - for some reason the solution which works for him, didn't work for me, but now I know why.

    The problem came down to 'variable scope'. The issue was that for me adding $more=0 wasn't being treated as a global for whatever reason. The solution was to explicitly state it as a global.

    So, the quick fix for reliably forcing WordPress to respect the MORE tag in any (the) loops in your sidebar is to:

    Add the following function to 'functions.php' in your theme:

    function force_more() {
    	global $more;
    	$more = 0;
    }

    In your sidebar.php, begin your loop as follows:

    <?php
      force_more();
      query_posts('category_name=mycategory&showposts=5');
      while (have_posts()) : the_post();
    ?>

    all done.

    Now on any page/single/whatever you can force any of your custom loops to respect the MORE tag.

    Thanks a lot for the help moshu, it just took me a little reading wordpress' code to realise that it had to be a global definition... then a little longer to realise that what you had suggested wasn't behaving as a global for me.

    Cheers!

  8. moshu
    Member
    Posted 6 years ago #

    Glad you solved it.
    Keep in mind I am not a coder, so I found that bit of code somewhere in the forum (probably, one of Kaf's posts) and added to my query, moving it around until it worked :)

  9. Ivovic
    Member
    Posted 6 years ago #

    clearly I'm not a coder either lol... I'm still confused as to why I had to explicitly state it as a global, and you didn't, but that feeling will pass as I quickly move on to other things :)

    Anyway, I learned things, and every day you learn something is a good day.

    Cheers :)

  10. thestonewailer
    Member
    Posted 6 years ago #

    Add the following function to 'functions.php' in your theme:

    function force_more() {
    global $more;
    $more = 0;
    }

    In your sidebar.php, begin your loop as follows:

    <?php
    force_more();
    query_posts('category_name=mycategory&showposts=5');
    while (have_posts()) : the_post();
    ?>

    all done.

    Can someone walk me through exactly how to do this? I get weird error messages when I try to make this change to my functions.php file. I haven't made it far enough to place the force_more code in my page template, since I can't get past the first hurdle.

    I have a static page that displays posts, but I want to be able to use the MORE tag in my longer posts and I think that the above code will help, if I can figure out how to place it correctly.

    Thanks,
    Josh
    [sig moderated]

  11. WPITn2shape
    Member
    Posted 6 years ago #

    I don't know if this was said, I skimmed.

    Note if you tell blog.php to use index.php's template. You add the

    $more = 0;

    code to blog.php. :-)

  12. mysteryjones
    Member
    Posted 5 years ago #

    Just went through the same issue - found that I had to put the force_more() function inside the loop displaying the posts so that it forced the more variable EVERY TIME it displayed a post. Give it a try and let me know.

Topic Closed

This topic has been closed to new replies.

About this Topic