WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Read More function with Pages (11 posts)

  1. jessicalane
    Member
    Posted 1 year ago #

    Hi,

    I use pages for my website, except for the 'news' page, which is a page full of posts- each news item is an individual post.

    On my homepage i list three posts in a sidebar- so i need to keep them short!

    The problem is i can't get the 'read more' function to work correctly. this is the code i'm using at the moment.

    <h2>Latest NEWS</h2>
    <?php wp_reset_query(); ?>
    <?php query_posts("post_type=post&posts_per_page=3");?>
    <?php if (have_posts()): while (have_posts()): the_post() ; ?>
    <?php the_title();?>
    <?php global $more;$more = 0;?>
    <?php the_content(__('more...')); ?>
    <?php endwhile; endif; ?>

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

    the titles display correctly, and the content cuts off at the right place (where i've placed the <!--more--> tag), but instead of just saying 'more...' is says 'Continue reading '[the title of the news post]'.

    How do i make it so it cuts off the post and just says 'more...', linking to the rest of the post.

    Thank you!

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    what theme are you using?

    your theme might be using a filter to change the 'more link' text...

  3. jessicalane
    Member
    Posted 1 year ago #

    thanks for helping! I'm using my own custom theme. it says this concerning the content / more function in function.php

    function short_content($post_id, $content, $char_length, $read_more_class, $read_more_text) {
    $count = strlen($content);
    if ($count >= $char_length) {
    $content = substr($content, 0, $char_length);
    $content.= '... <a class="'.$read_more_class.'"
    href="' . get_permalink($post_id) . '">'.$read_more_text.'';
    	}
    echo $content;
    }

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

    is this where it's gone wrong?

  4. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    it says this concerning the content / more function in function.php

    the snippet does not seem to refer to your problem.

    I'm using my own custom theme

    in which case you should be very familiar with where what output comes from.

    this unfortunately makes any support more complicated as the forum's helpers do not have free access to the code as it would be with themes from http://wordpress.org/extend/themes/

    you could try and post the full code of functions.php - http://codex.wordpress.org/Forum_Welcome#Posting_Code

  5. jessicalane
    Member
    Posted 1 year ago #

    This is why i'm having difficulty- i'm new to PHP.

    I posted that snippet because i thought it was the most relevant- it is the only part of function.php that refers to the 'more' function- i'm sure of this. Is there anywhere else other than functions.php i should check?

  6. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    coming back to: "I'm using my own custom theme"

    this makes it virtually impossible to suggest any actions - as you don't seem to know what is going on in the theme, is there somebody else you might be able to contact directly for support with your problem?

    where is the theme coming from?
    did you buy it or got it custom made?

  7. jessicalane
    Member
    Posted 1 year ago #

    I've taken over the website and inherited it- i come from a html/css/jquery background and am new to wordpress. I'm afraid i can't even point to to the site as it's on a local server at present. I had just hoped i was making an obvious error that i had overlooked.

    If you've got no other suggestions then i'll think of something different.

    Thank you for your help.

  8. esmi
    Forum Moderator
    Posted 1 year ago #

    Have you reviewed Theme Development?

  9. jessicalane
    Member
    Posted 1 year ago #

    Thank you esmi! but i think i've just found the root of the problem- the wordpress on this server is an old version- the following code works on version 3.5.1 , but not on the server i was using, which is version 3.3.1 does that sounds like it could be the problem??

    the code i'm using now:

    <h2>Latest NEWS</h2>
    <br/>
    <?php wp_reset_query(); ?>
    <?php query_posts("post_type=post&posts_per_page=3");?>
    <?php if (have_posts()): while (have_posts()): the_post() ; ?>
    <h5><?php the_title();?></h5>
    <?php
    global $more;
    $more = 0;
    the_content("More...");
    ?>
    <?php endwhile; endif; ?>
  10. esmi
    Forum Moderator
    Posted 1 year ago #

    does that sounds like it could be the problem??

    Absolutely! A lot has changed since 3.3.1.

  11. jessicalane
    Member
    Posted 1 year ago #

    Brilliant, Thanks a lot :)

Topic Closed

This topic has been closed to new replies.

About this Topic