How to create pagination on wordpress? - wordpress

Hi all I am a new of wordpress,I want to create pagination next and previous, I have problame with pagination next and previous, I cant find the way to do it.I try to hard to do it, but still can not, How can I do it , Help me please. thanks you.
here is my code page_movie.php
<?php
global $wpdb;
$lastedate = $wpdb->get_var("
SELECT substr(meta_value,1,7) as Date
FROM ".$wpdb->prefix."postmeta
WHERE meta_key = 'details_release_date'
AND meta_value <> ''
AND meta_value >= '".date('Y-m-d')."'
GROUP BY substr(meta_value,1,7)
ORDER BY substr(meta_value,1,7) ASC
LIMIT 1
");
_e(do_shortcode('[movies limit="-1" type="Now Showing"]'));
_e(do_shortcode('[movies limit="-1" type="Coming Soon" compare="BETWEEN" start="'.date('Y-m-d').'" end="'.$lastedate.'-31"]'));
_e(do_shortcode('[movies limit="-1" type="Released" compare="BETWEEN" start="'.date('Y').'-01-01" end="'.date('Y-m-d').'"]'));
?>
<?php the_posts_pagination( $lastedate ); ?>

Related

Paginate, search & sort WordPress $wpdb query for external table

I have a custom table (ERA_Data) in my WP database, which I'd like to add pagination, column sort & search to.
Currently the following code successfully grabs the data (over 4000 entries) & displays them;
<?php
global $wpdb;
$ERA_Data = $wpdb->get_results("SELECT * FROM ERA_Data;");
echo "<table>";
foreach($ERA_Data as $ERA_Data){
echo "<tr>";
echo "<td>".$ERA_Data->PartNo."</td>";
echo "<td>".$ERA_Data->Make."</td>";
echo "<td>".$ERA_Data->Carline."</td>";
echo "<td>".$ERA_Data->Model."</td>";
echo "<td>".$ERA_Data->Description."</td>";
echo "<td>".$ERA_Data->Start_Year."</td>";
echo "<td>".$ERA_Data->End_Year."</td>";
echo "</tr>";
}
echo "</table>";
?>
Just so you know, this is all new to me - so I'm happy to read up on further info, but if anyone can provide some code examples that may help - I'd be extremely appreciative.
With regards to pagination, I think 50 or 100 items per page would do.
I'd imagine sort order & search will be far more useful in any case.
I would juts work on this line for anything you need:
$ERA_Data = $wpdb->get_results("SELECT * FROM ERA_Data;");
so change it like this for showing only a 100, 50, etc. results
$ERA_Data = $wpdb->get_results("SELECT * FROM ERA_Data LIMIT 100;");
or
$ERA_Data = $wpdb->get_results("SELECT * FROM ERA_Data LIMIT 50;");
and for pagination, this link would help so much What is the best way to paginate results in SQL Server
for sorting, depending on your column, use this syntax
$ERA_Data = $wpdb->get_results("SELECT * FROM ERA_Data ORDER BY ***COLUMN NAME HERE***;");
Let me know if you have any questions!

php count users post

i am having some problem counting users posts from db, it's kind of confusing because all the id's/row are in the same table.
the table:
categories | id1 | id2 | title | msg | userid
<?php
$query = "SELECT * FROM topics WHERE authorid='".$id2."'";
$rows = mysql_query($query);
echo $rows['id2'] ;
?>
Thank's
Read the documentation. mysql_query doesn't return rows. And the way you access it, it's more like you expect a single row there. Besides, you may want to connect to the database (depends on your php.ini, though, IIRC).
Try this:
<?php
$query = "SELECT COUNT(*) as count FROM topics WHERE authorid='".$id2."'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo $row['count'] ;
?>
$query = "SELECT COUNT(*)AS count FROM topics WHERE authorid='".$id2."'";
Then after you fetch the row (this will depend on what database library you're using), you can do something like:
echo $rows['count'];

Show post count in Wordpress

Is it possible to get the exact counter of each post for display in a theme I'm making? So for example if I have 100 posts, the last post will have a number of 100, the one before that: 99, and so on. I can't use the post's ID on this since this is always incremented by 2 (most of the time) making it highly inappropriate as a counter.
Try this, look at the results you will get the idea.
Don't forget the array starts with 0 not 1.
Each array item will contain the post ID. so if Item(key) nr 15 is the same as the current page ID, then the current item is #16(15+1)
<?php
global $wpdb;
$query = "SELECT `ID`
FROM `$wpdb->posts`
WHERE `post_status` = 'publish'
AND `post_type` = 'post'
ORDER BY `post_date` ASC
"
;
$count = $wpdb->get_col($query);
var_dump($count);
moar info: wpdb
Do look at the query if you agree with my order.
You'll have to use a "counter" there, something like this:
$i=1;
while(have_posts):
....
<h2><?php echo $i.' - ';?><?php the_title();?>
...
$i++;
endwhile;

Get this code I made to also do month/day/week post count? Wordpress

I finally got some code made for to output this years total published posts.
get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND `post_date` > '" . date("Y") . "-01-01 00:00:00'");
if (0 < $numposts) $numposts = number_format($numposts); ?>
I'm looking at the WP time paramters to try and make it also do day then week then month.
http://codex.wordpress.org/Function_Reference/query_posts#Time_Parameters
Can anyone advise me on what to do? Thanks
I think this thread should help you along.
This Query will give you the number of posts by year and month.
SELECT YEAR(post_date) as yer, MONTH(post_date) as mnth, COUNT(post_date) as num
FROM your_table
WHERE post_status = 'publish'
GROUP BY YEAR(post_date), MONTH(post_date)

Show Only Pings (Pingbacks+Trackbacks) Number on Wordpress

Is there a way to display just ping counts (number) on Wordpress?
Actually there are comments_number function but that showing total count of comments, pingbacks and trackbacks.
The following code works on WordPress 2.9.1. It may work on other versions, but I only tested it against 2.9.1.
<?php
global $wpdb;
$post_id = get_the_ID();
$total_ping_count = $wpdb->get_var("SELECT count(comment_id) FROM $wpdb->comments WHERE comment_type = 'pingback'");
$total_approved_pings = $wpdb->get_var("SELECT count(comment_id) FROM $wpdb->comments WHERE comment_type = 'pingback' and comment_approved = 1");
$post_ping_count = $wpdb->get_var("SELECT count(comment_id) FROM $wpdb->comments WHERE comment_type = 'pingback' and comment_approved = 1 and comment_post_id = $post_id");
echo "The total number of pings on this site is $total_ping_count.\n";
echo "The total number of approved pings on this site is $total_approved_pings.\n";
echo "The total number of approved pings on this post is $post_ping_count.\n";
?>
The above code gives counts just for pingbacks. If you want trackbacks instead of pingbacks simply change comment_type = 'pingback' to comment_type = 'trackback' or if you want a combined count change it to comment_type IN ('pingback', 'trackback').
Not exactly sure what you want: only show pingbacks? If so, and I haven't tried it, but Template Tags/wp list comments « WordPress Codex shows listing pingbacks and options.

Resources