• hey…

    i have a custom home page that has 3 columns and each column shows a snippet / excerpt of content from a page so my query is what code would i use to show just 20 characters from a page post on the front page in each column ?

    the post ids are 2,3 and 4

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter nyckidd

    (@nyckidd)

    ok i got this code but how do i specify a specific post using its id ?

    <?php
    //The Query To Get Posts
    $my_query = new WP_Query('showposts=3');
    
    //Run the Query and Loop Through Results
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID;
    
    ?>
    
    <?php
    $string = get_the_content('');
    $newString = substr($string, 0, 20);
    echo $newString;
    ?>
    
    <?php endwhile; ?>
    Thread Starter nyckidd

    (@nyckidd)

    Well i was able to figure it out…ehe!! after 3 hours 🙂 for anyone who needs to know here is the code i used…

    <?php
    $post_id = 5;
    $queried_post = get_post($post_id);
    ?>
    <?php
    $string = get_the_content('');
    $newString = substr($string, 0, 120);
    echo $newString;
    ?>
    Thread Starter nyckidd

    (@nyckidd)

    well…need some help…its pulling the content but on one page when i have this

    <?php
    $post_id = 5;
    $queried_post = get_post($post_id);
    ?>
    <?php
    $string = get_the_content('');
    $newString = substr($string, 0, 100);
    echo $newString;
    ?>
    
    <?php
    $post_id = 4;
    $queried_post = get_post($post_id);
    ?>
    <?php
    $string = get_the_content('');
    $newString = substr($string, 0, 100);
    echo $newString;
    ?>

    and instead of pulling post with id 4 its pulling the same post so if we are on post with id 4 it pulls the same post though we have specified that it should pull post with id 4 and 5

    Thread Starter nyckidd

    (@nyckidd)

    Am so close…i just need to know what i need to adjust in this code to enable the character limit to work..

    <?php
    $post_id = 4;
    $queried_post = get_post($post_id);
    echo $queried_post->post_excerpt;
    ?>
    <?php
    $string = get_the_content('');
    $newString = substr($string, 0, 100);
    echo $newString;
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show just post with 20 characters’ is closed to new replies.