• Hello everybody.

    I’m trying to put a part of a page content in a static homepage,
    I use the following code:

    <?php
    $my_id = 19;
    $mypage = get_post($my_id);
    $mypage_title = $mypage->post_title;
    $mypage_content=$mypage->post_content;
    ?>
    <h2 class="boxTitle"><?php echo $post_title;?></h2>
    <?php echo $post_content;?>

    but this shows the entire contents and not the part before the more tag.
    Can anyone help me?
    Sorry for my english and thanks everybody.

Viewing 2 replies - 1 through 2 (of 2 total)
  • This should work:

    <?php
    $my_id = 19;
    $mypage = get_post($my_id);
    ?>
    <h2 class="boxTitle"><?php echo $mypage->post_title;?></h2>
    <?php echo substr($mypage->post_content,0,strpos($mypage->post_content, '<!--more-->'));?>

    Thread Starter ariele

    (@ariele)

    thanks you MichaelH, it works perfectly.

    Another little question:
    can I make the same thing with a random post and how?

    actually I’m using the following code:

    <?php
            query_posts(array('orderby' => 'rand', 'showposts' => 1));
            if (have_posts()) : while (have_posts()) : the_post(); ?>
            <div class="post" id="post-<?php the_ID(); ?>">
                <h2><?php the_title(); ?></h2>
                <?php
                    the_content();
                ?>
                <a href="<?php the_permalink() ?>">continua</a>
            </div>
            <?php endwhile; endif;?>

    But I have the same problem, this loop show me the whole post instead of the part before <!–more–>.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘how to take a part of specific page content’ is closed to new replies.