Last Post Function in wordpress - php

I made my website http://test.costa.io/?page_id=4, with wordpress and I put here all my post. The problem is that I want to have a function to check if its the last post, and if it's so dont put the /hr/.
I tried with the function more_post() and last_post but didn't make it work.
This is the code of the plugin I use to get all the post in the web :
http://pastebin.com/Qv9Ff2T7

You can get the number of posts you have by count($posts) and then add a counter variable in the foreach loop. When the counter is equal to the number of posts you know that it's the last post, so don't output the hr.

Ok I make it work changing the way I did it, still the count was a good way to do it, so ill give u the credit for it. Thanks everyone

Related

Wordpress WP_QUERY with GET and AJAX

Recently I've been developing on a Wordpress theme, where you can filter different products (A post type) based on custom fields (metaboxes).
After a lot of hard work, I finally found a way to do it, by using the "array" from "get" url, check if it's set and if it is, then pass the array into the WP_QUERY.
Hope this image explains it a bit better
I'm doing it with this code: http://pastebin.com/T5ihsCw3
But now I would really like to update the query, every time a checkbox is checked (or unchecked), by using Ajax. I just can't get it to work, because I NEED to use the "GET" from the URL, and I can't find a guide on THAT specific thing.
Any help would be greatly appreciated!
Thanks!
Frederik
See this post. It shall give you an idea on how to solve your problem:
WordPress: How to get metadata of Custom Fields from Custom Taxonomy with using jQuery
You need to create a function that can be queried by Ajax and then every time one of the checkboxes is checked, you just issue an Ajax get request.

Wordpress post customising

i was wondering if this is feasible.
Supposing my i want to divide my post ... Lets say, i have all my post side by side in 2 rows.
Lets say a total of 8 from the category (Mypost)
Now assuming, i want to have a static between the first 2 rows and the rest of the columns below, is this feasible?
Also assuming i want latest post to show on the 2 up rows and the old post to move below my div.
I have tried , but did not come out with any feasible solution.
Great if someone could be able to assist. I have content.php where all my contents are being generated and index.php being the front end.
Thank you
using two WP query may help you ,use this one for latest post
<?php query_posts('category_name=Mypost&showposts=5');?>
And for the older posts use
<?php query_posts('category_name=Mypost&offset=5');?>
I really don't understand your problem clearly,hope this is what you want
THANK YOU Akhila - Ok, i needed to edit the code a little bit - This code works!:)
<?php query_posts('category_name=post&showposts=2'); ?>
<?php query_posts('category_name=post&showposts=100&offset=2'); ?>

PHP JQUERY AJAX PAGINATION

I'm just looking for some advice in this post.
I am currently using pagination via a $_GET variable in the url. However I am not paginating by first calculating a count and then using a LIMIT clause. Instead I am retrieving all values to paginate, then placing them in an array which is then sliced, so the first 10 items of the array are displayed on the first page, and the next 10 on the second page, etc. There is a reason for this madness.
However, this results in the entire query running every time a user clicks a different page number.
Is it at all possible to instead use jQuery/AJAX, so that I can run the query once, then simply cycle through the array without having to reload the page?
Any help would be greatly appreciated.
Thanks
Yeah if you have to get everything out in your query anyway you might as well divide everything up into pages in one go and put them on your page ready to be hidden/shown. Then your page links/buttons will just need to hide the current page and show the page clicked. Shouldn't be too much work.

Problem with pagination - no success yet

Hey guys I am really messing up with this.
This is I'm doing: If there are 100 users to fetch from Database, I'm using pagination and showing 10 users at a time. when user will click on next page, he will get next 10 users through ajax(called ajax on click) and so on. I'm showing 10 page-links right now with first, next last and previous links.
This is how flow will go: On a.php created links and called ajax function with every link, passing url(b.php) & target(where I will get result), with url also passing clicked pageno., this pageno. will go to b.php and next 10 users will be shown with the help of ajax.
This is the problem: Currently I'm showing 1-10 links with first and last links, unable to show next and previous links because to redirect to next or previous, I am not getting the current page number on a.php i.e i'm passing to b.php. also links are created in foreach loop.
I am trying hard to get this done, but no success yet.
waiting for valuable reply.
Ok, I think I understand...
I think what you need to do is store the current page number as a JavaScript variable. Use the function that is doing the Ajax to update this variable and also update the next/previous links.
Hope this helps.
Update:
On second thoughts, here's a better idea. Having your ajax call directly in your link means you have to put together a url and update it, which is awkward and annoying. This isn't ideal. Instead it is better to store the variables and have some set functions work with them in a set way. So, you could have something like:
<a href="javascript:void(0)" onclick="gotoNextPage()">
Rather than passing them the number of the page to go to, you can store the current page number in a javascript variable and do something like this:
gotoNextPage(){
// lets assume the current page number is stored in a
// variable defined outside of this function called curr_page
curr_page++; // increment the current
call_ajax('user_info.php?pageno='+curr_page);
}
This way the code for the link doesn't ever change.
You can still pass other variables (such as 'order', 'perpage' etc) to gotoNextPage() but you might find you don't need to.
A couple of things to bear in mind:
1. Using jQuery or something similar would probably make things easier for you.
2. Anyone without javascript enabled will not be able to use your site. Consider changing it to something like
<?php
echo '<a href="your_main_page.php?page_number=', ($curr_page + 1), '" onclick="gotoNextPage()">';
?>
This way it would work for via the ajax method but would also work (if not as smoothly and with a page reload) for people without javascript. It's a bit more work for you though...so hat's your choice!
Hope this makes sense. It's been a long day!

Wordpress | Automatically repost entries to the start page by date

I'm looking for a solution to regularly show a post on the startpage. The way to archieve this is to update the last modification date of a post, which can be easily done using an SQL statement. Alas this skips the regular Wordpress update hooks such as "post new entries to twitter".
So I'm looking for a PHP cronjob script to "emulate" the user updating the modification date of a post and clicking the publish button.
How can I do this? Adding wp_load.php to my script and then ... ?
Thanks for advice,
Johannes
You can't use the "Stick this post to the front page" function under "Visibilty" in the "Publish" section of the post editor? And then use your Twitter plugin posting options to retweet when the post is edited?
You can modify your template/theme file to show specific posts or almost anything else...
All you need to know is a little PHP and browse the WordPress Codex
Check out query_posts():
http://codex.wordpress.org/Function_Reference/query_posts
Thanks for your responses so far, but I'm not sure if I described my goals correctly. I don't want to stick posts, I need a feature similar to the Unix "touch" - modify a post's creation date to NOW and (in the case of wordpress) execute all new post handlers such as post to twitter.
query_posts is indeed a useful function to style the startpage, but it doesn't go far enough in my case.
What is this startpage?
I can only think of a Homepage in your case, and as you have stated before, You could include wp-load.php and then create the loop.
If you are trying to grab the latest post in your wordpress blog and update the date to today's current date, you will probably need to do a query in the wordpress database.
$wpdb->query("UPDATE wp_post SET post_date = date WHERE id = id");
The above query will need some modification. From there you can put that in a cronjob.

Categories