nyckidd
Member
Posted 2 years ago #
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
nyckidd
Member
Posted 2 years ago #
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; ?>
nyckidd
Member
Posted 2 years ago #
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;
?>
nyckidd
Member
Posted 2 years ago #
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
nyckidd
Member
Posted 2 years ago #
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;
?>