DEV Community

Kelvince
Kelvince

Posted on

web programming

Need a pagination for my website
To output one post only in the home page

Top comments (16)

Collapse
 
pgrab86 profile image
Paweł Grabowski • Edited

Has your website any CMS? Any framework? What's the technology used to build it?

Collapse
 
kelvince profile image
Kelvince

Used php,sql,html,js and css
Only

Collapse
 
pgrab86 profile image
Paweł Grabowski

Don't know, what exactly you need, but maybe a simple slider would work. Get 5 posts from database and use slick for example (kenwheeler.github.io/slick/) with dots (you can style it as numbers).

Thread Thread
 
kelvince profile image
Kelvince

Some sort of that.
Exactly what i need is pagination in php, where it will display one recent post from the database only in the homepage and display the previous post as a link

Thread Thread
 
pgrab86 profile image
Paweł Grabowski

So the same for me. Get a few posts (or partial of posts like thumb, short description, id and slug), and in a loop make a condition: if first - show article (part of article) and if next - put just links. So you have to generate links by slug or by id (no idea, what your database looks like).

Thread Thread
 
kelvince profile image
Kelvince

Yeah this but display the post body for one post

Thread Thread
 
pgrab86 profile image
Paweł Grabowski

You will get more content from database, than you need, but if it is just a 5-10 posts, there is completely no problem at all. And to show only one post content you have to make a simple condition like:


for( $x = 0; $x <= 10; $x++ ) {
if( $x == 0 ) {
echo $result[$i]->title;
echo $result[$i]->content;
} else {
echo '<a href="'. $result[$i]->link .'">'. $result[$i]->title .'</a>';
}
}

where $result is data from your database

Thread Thread
 
kelvince profile image
Kelvince

Ok let me work on this,thanks alot

Thread Thread
 
pgrab86 profile image
Paweł Grabowski

Good luck and if you will have any problems, paste here (or codepen) some part of code you have. It will be easier to help

Thread Thread
 
kelvince profile image
Kelvince

My pleasure

Collapse
 
tux0r profile image
tux0r

Need a pagination for my website

Uhm...?

<a href="page2.html">page 2</a>
Collapse
 
kelvince profile image
Kelvince

Using php,getting the posts from the database

Collapse
 
tux0r profile image
tux0r

Which connector do you use? PDO?

Thread Thread
 
kelvince profile image
Kelvince

mysql_query()

Thread Thread
 
tux0r profile image
tux0r • Edited

Are you aware that this is deprecated and removed with PHP 7?

So, anyway: stackoverflow.com/a/12316180

Thread Thread
 
kelvince profile image
Kelvince

Saw the code near to what i wanted,thanks