WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] More tag ignored on home page (20 posts)

  1. heriz
    Member
    Posted 6 years ago #

    So my home page is set to display according to a template file as per Moshu's superb Static Frontpage with Dynamic Content tutorial. It is set up to pull only the 'news' category posts, using a second loop. Here is the code for the second loop:

    <?php $temp_query = $wp_query; ?>
    <?php query_posts('category_name=news&showposts=8'); ?>
    <?php while (have_posts()) : ?> <?php the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>"> <div class="post-title">
    <h3>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></h3>
    </div>

    <div class="entry">
    <p><?php the_content('(Read on) »'); ?></p>
    <span class="post-date"><?php the_time('l F j, Y'); ?></span>
    <span class="post-comments-home"><?php comments_popup_link('No comments yet', '1 Comment »', '% Comments »'); ?></span>

    etc...

    The only problem is that my 'more' tags are removed. As I really only want excerpts (but with the 'read more' option as opposed to the standard no-linked [...] when using the_excerpt), this is frustrating.

    Adding

    <?php global $more;
    $more = 0; ?>

    Under the template name does nothing, and including it within the php template tags

    <?php
    /*Template Name: Main*/
    global $more;
    $more = 0;
    ?>

    breaks it completely. (Bear in mind I'm a novice in PHP, but this was suggested in a tutorial so it ought to work).

    Any suggestions on how to fix this please?

    Thanks...

  2. heriz
    Member
    Posted 6 years ago #

    Solved it.

    The

    <?php global $more;
    $more = 0; ?>

    code needs to be placed under the "entry" div tag in the second loop.

    Sorry to keep starting support questions then solving them myself! Hopefully this will help someone...

  3. Ivovic
    Member
    Posted 6 years ago #

    Just blame Moshu, that's what the rest of us do ;)

  4. Libor Jelinek
    Member
    Posted 6 years ago #

    Can somebody explain me why is <!--More--> tag ignored on home (front) page? (is_home() == TRUE)?

    It's very inconsistent behaviour and for me it was difficult to resolve why my posts are not cutted after <!--More--> on home page post listing.

    If you understand the reasons, please consider explaint it to following Codex pages where is the_content() and excerpt described.

    http://codex.wordpress.org/Customizing_the_Read_More
    http://codex.wordpress.org/Template_Tags/the_excerpt

    Cheers
    Libor

  5. VoinG
    Member
    Posted 5 years ago #

    Can somebody explain me please, why <!--More--> tag isn't working here:

    <?php rewind_posts();
    global $more;
    $more = 0;
    $my_query = new WP_Query('order=asc&showposts=500');
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID; ?>

    <div class="post" id="post-<?php the_ID(); ?>">
    <h2>" rel="bookmark" title=" <?php the_title_attribute(); ?>"><?php the_title(); ?></h2>
    <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
    <div class="entry">
    <?php the_content('Read the rest of this entry »'); ?>
    </div>
    </div>
    <?php endwhile; ?>

    I receive the whole text and something like this

    <p><span id="more-45"></span></p>

    but not more-tag.
    Thanks!
    (i found that here: http://www.texto.de/texto/wordpress-als-cms-printausgabe-statische-seite)

  6. acmc
    Member
    Posted 5 years ago #

    heriz - THANK YOU!!! Trying to solve this problem - and your post did it - greatly appreciated;-) I placed under the entry in the loop on the template page - worked like a charm!

  7. karl19
    Member
    Posted 5 years ago #

    Heriz,
    Thanks for posting this, I was looking everywhere for a fix to why the more-tag didn't work and only when I palced the "global $more.." part further down in the loop did it work.

  8. Gr1f
    Member
    Posted 5 years ago #

    good grief, for the LIFE of me i cannot get this to work!

    creating a new page, using a custom templte like this:

    <?php
    /*
    Template Name: allowcomments-template
    */
    ?>
    
    <?php get_header(); ?>
    
    	<div id="wordpress-content">
    <h2><?php the_title(); ?></h2>
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<div class="post" id="post-<?php the_ID(); ?>">
    
    				<div class="entry">
    					<?php the_content('Read the rest of this entry &raquo;'); ?>
    				</div>
                    <?php global $more;
    $more = 0; ?>
    
    				<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    <?php comments_template(); ?>
    
    			</div>
    		</div>
    		<?php endwhile; endif; ?>
            <br clear="all" />
    	<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    	</div>
    
    <?php //get_sidebar(); ?>
    <?php get_footer(); ?>

    and it doesn't work.
    It DOES work on the default index page if i place a long post. but not if i add
    <!--more-->
    to a Page.

    Any help appreciated!!

  9. nellcooper
    Member
    Posted 5 years ago #

    The problem is that you are putting the code in the wrong place. You are putting the code after the call to write the content instead of before. Try:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
      <?php global $more; $more = 0; ?>
        <div class="post" id="post-<?php the_ID(); ?>">
    	<div class="entry">
    	 <?php the_content('Read the rest of this entry &raquo;'); ?>
    	 </div>

    Move the code for the global more before the call to the_content ('Read the rest...

    What you are doing is setting the $more variable BEFORE the WordPress Loop uses it.

    What you were doing was setting the variable AFTER the WordPress Loop wrote the_content. I hope this makes sense.

    I like to put my global call immediately after theif (have_posts()) line, but some folks say it works better in the entry division. That seems to produce unnecessary repeated code calls. But either way should work. Sorry I didn't come across this post sooner.

  10. tonymcclellan
    Member
    Posted 5 years ago #

    So my code looks like this:

    function the_content('more_link_text', $stripteaser = 0, 'more_file = ''') {
    	$content = get_the_content($more_link_text);
    	$content = apply_filters('the_content', $content);
    	$content = str_replace(']]>', ']]>', $content);
    	echo $content;
    }
    
    function get_the_content($more_link_text = null, $stripteaser = 0, $more_file = '') {
    	global $id, $post, $more, $page, $pages, $multipage, $preview, $pagenow;
    
    	if ( null === $more_link_text )
    		$more_link_text = __( '(more...)' );
    
    	$output = '';

    What does null mean? Where exactly do I enter global more using php because none of this has php tags. This is in the wp-includes/post-template.php file. Please help because I am tired of using excerpt editor.

  11. asmirnov
    Member
    Posted 5 years ago #

    Hi all. I found this thread very informative and I already solved some of my problems. However, I have a problem I do not know how to solve. The WP blog is displaying the excerpt correctly (using the <!--more--> tag), except when I click on the post name to see it it only gives me the excerpt again, not the entire text. I hope I am not double, triple or quadruple-posting the same question but I was not able to find an answer in the support forum. Here is the index.php code:

    <?php
    get_header();
    ?>
    <?php global $more; $more = 0; ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <div class="post">
    	 <h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    	<div class="meta"><?php _e("Posted by"); ?> <?php the_author() ?> | <?php the_category(',') ?> | <?php the_time('l j F Y'); ?> <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>
    
    	<div class="storycontent">
    
    <?php the_excerpt(__('(more...)'));?>
    
    	</div>
    
    	<div class="feedback">
                <?php wp_link_pages(); ?>
                <?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?>
    	</div>
    
    </div>
    
    <?php comments_template(); // Get wp-comments.php template ?>
    
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
    
    <?php posts_nav_link(' — ', __('&laquo; Previous Page'), __('Next Page &raquo;')); ?>
    
    <?php get_footer(); ?>
  12. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    Why are you using the_excerpt? Use the_content instead.

  13. asmirnov
    Member
    Posted 5 years ago #

    Thank you for pointing that out Otto. I changed it to <?php the_content(__('(more...)'));?> and it worked! With one problem though. Now, it seems to have screwed up the layout of the front page (displays the text properly excerpted). I have no idea why, because when I click on "more" to display the entire post, everything is displayed and laid out properly.

    So it is either the previous situation where the layout is correct but the entire post is not showing, or the other way around. For the past two hours I have been reading the WP tutorials and searching the forum for pointers and still have no idea why. Any help will be much appreciated.

  14. tonymcclellan
    Member
    Posted 5 years ago #

    What file is the_content in?

  15. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    We really can't help you with the layout without a link to the actual page, to see what it's doing.

  16. asmirnov
    Member
    Posted 5 years ago #

    The URL is: http://www.asmirnov.org/blog/. Oddly enough (to me) it seems to display correctly in IE, not in FF.

  17. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    Your "Lorem Ipsum" post has a DIV in it which is messing up the remainder of the page.

    Remember, the "more" tag cuts off the post at that point. So if you start a DIV before the more and then end it after the more, your page gets hosed because the DIV remains unclosed on the main page.

    It's best to simply not to use DIVs in posts.

  18. asmirnov
    Member
    Posted 5 years ago #

    Otto, fantastic. That did the trick. I have no idea, how those <div> tags got in there in the first place. Can't believe I missed that. Thanks a MILLION.

  19. erictr1ck
    Member
    Posted 5 years ago #

    anyone have trouble doing this with 2.7? i can get this to work at all in a template file.

  20. mcarun
    Member
    Posted 5 years ago #

    I already edited some stuff to change the read more text to Dutch for 'Read the full article', but it doesnt seem to display on the index page of my blog..

    I read the topic and the infopages on read more text editing here on wordpress, but I still didnt manage to change it properly.

    Problem is: on my index page I list my latest posts with a teaser which I cut off with the MORE TAG in the editor. But when I view the home page not after every teaser the more text is displayed.

    anyone please?

Topic Closed

This topic has been closed to new replies.

About this Topic