One more: Posts from individual categories on a page (4 posts)

  1. Anonymous
    Posted 7 years ago #

    Dear all

    I know this is the millionth time this question is asked, but I still haven't managed to find a proper answer for me. However - I'm almost there, so if someone (especially moshu) would like to comment, please do.

    I am trying to...
    ..set up two different pages, each to display the two different categories of posts I have. Then on the frontpage I would like to display the most recent post form one category (with a list of the few recent ones) and then a random post from the other.

    I have two very different categories and I want things to work as described above. It wouldn't work with pages. One is 'news' and the other is 'recipies'. And last, but not least, I build the sites navigation menu from the pages. On one page people can click to read the recipies and vice versa

    You still with me? Thanks!

    So far..
    I have managed to get almost there. With the php exec plugin I can execute php code from my page and my code is like this.

    global $post;
     $postslist = get_posts('category=4');
     foreach ($postslist as $post) :
     <br />
    <h2><a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a> </h2>
     <?php the_content('More..'); ?>
     <?php endforeach; ?>

    And what does it do? It displays the posts from my category, as it should EXCEPT the content doesn't come right. You see, it should only display the excerpt and then a link saying 'more' but it doesn't and there lies my problem. Everything else is working fine.

    All help appreciated.

  2. xamataca
    Posted 7 years ago #

    Then use the_excerpt() instead of the_content('More...')
    The only problem is that the excerpt dont show the "more" link, anyway people can always click on the title link...

    Sometimes is more meaningful to use only the_content() function. the_content() will decide what to display according to whether <!--More--> tag was used.

    <!--More--> tag splits post/page into two parts: only content before tag should be displayed in listing.

    Remember that <!--More--> is (of course) ignored when showing only post/page (singles).

  3. Anonymous
    Posted 7 years ago #

    Well - that works. But 55 words are too much, and I don't want to cut off in the wrong place. It's all about being in control you see..

  4. arouth1
    Posted 7 years ago #

    Apologies for the bump, but has anyone figured out the issue with content('more...')?


    The code posted in the first post works, but like the OP, it doesn't adhere to the <!--More--> tag. And like the OP, the_excerpt() doesn't really help me out either.

Topic Closed

This topic has been closed to new replies.

About this Topic