How do I list my posts in Wordpress ordered by modified date instead of created date?
I have it as
<?php $posts=query_posts($query_string . '&orderby=post_modified&order=ASC'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
Having orderby=title does sort the posts by title but my above query doesn't work.
Looks like orderby=post_modified isn't recognized.
Ah ok... I figured it out.
orderby=post_modified needs to be orderby=modified.
Thanks,
Tee
Related
Can help somebody. I spent several hours to find solution but without results
I tried to display the list of categories on homepage wordpress blog thru following code
<?php $category = Mage::registry('wordpress_category') ?>
<?php if ($category): ?>
<?php echo $category->getId() ?>: <?php echo $category->getName() ?>
<?php endif; ?>
But the method
Mage::registry('wordpress_category')
always return null.
I found that, i should probably be using the Fishpig_Wordpress_Block_Category_View. But i dont know where i should put it.
The following code will retrieve the current category when viewing a category page in your blog:
<?php Mage::registry('wordpress_category') ?>
This is not what you need. To view a list of categories, you could create a custom collection using the following:
<?php $categories = Mage::getResourceModel('wordpress/post_category_collection') ?>
A better way would be to use the category widget block:
<block type="wordpress/sidebar_widget_categories" name="wp.categories" template="wordpress/sidebar/widget/categories.phtml" />
You can create this in PHP using the following code:
<?php echo Mage::getSingleton('core/layout')
->createBlock('wordpress/sidebar_widget_categories')
->setTemplate('wordpress/sidebar/widget/categories.phtml')
->toHtml() ?>
The above code uses the default template, however, feel free to use your own custom template.
I have a page that displays certain posts from a certain category, in this case category 33:
<?php $top_query = new WP_Query('cat=33'); ?>
<?php while($top_query->have_posts()) : $top_query->the_post(); ?>
How Can I specify that the posts returned should only be ones that have comments enabled?.
I have tried wrapping it in:
<?php if(comments_open()) : ?>
Hover that needs to be used within the loop :(
Thanks in advance
In the wordpress database the post status is saved in the $wpdb->posts table in the comment_status column. Try passing this variable to WP_Query also like this:
<?php $top_query = new WP_Query( array('cat'=>33, 'comment_status'=>'open'); ?>
<?php while($top_query->have_posts()) : $top_query->the_post(); ?>
this should do it.
I have a while loop in my wordpress site. How to print its query details ?
while (have_posts()) : the_post();
I tried, but not working:
print_r($GLOBALS['wp_query']->request);
Add this in your functions.php then add ?debug=sql after the url, for example
http://someUrl.com/something?debug=sql
Or
http://localhost/localCopy?debug=sql
Also <?php echo $GLOBALS['wp_query']->request; ?> should work, just put it right after the loop if you didn't it before.
I create a loop in Wordpress with the condition like this:
Display a specific post format (example: video)
Limiting the post number. In this case, I only want to display 2 posts.
Here my code:
<?php $i = 1; if (have_posts()) : while (have_posts() && $i < 3) : the_post(); ?>
<?php get_template_part( 'content-video', get_post_format() ); ?>
<?php $i++; endwhile; ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
I already have file name content-video.php.
Unfortunately, the loop does not work. Only displayed the first post, not a specific post (video post format) with template from content-video.php.
Appreciate for any help, or alternative code. Thanks in advance.
My remarks about your code:
I think you have bad wrapping for if else while statements. You are missing an endif at the end in the case your approach is correct.
Why use inside your code the i variable since you can customize any query in WP, especially for number of post using the parameter posts_per_page.
Why not to use the loop inside content-video.php and write only:get_template_part('content-video', get_post_format()); Like in single.php and loop-single.php the themes provided with wordpress installation (twenty themes) .
Good luck
the best way would be to get posts of "video" post format from a query, but I'm not sure how:)
As a workaround you could do this inside the loop:
if (!has_post_format('video'))
continue;
I have Developed WordPress Site Successfully, but i have doubt in Getting all the post by
Categories.
My Code is like this
new WP_Query("cat=54,71,72&order=ASC");
Default it is getting the first category id and the Post.
Thanks
If you want to get ALL your categories instead of a selected few, you don't need to query by category.
new WP_Query("order=ASC");
If you want to query a particular category, but you're not sure what's the category ID number, query it by category slug
new WP_Query("category_name=your-category-slug&order=ASC");
You can also use this code as well, just need to change the number of post, like as of now, below listed code is use for display 5 post only, so you have to change this limit.
<?php query_posts('showposts=5'); ?>
<ul>
<?php while (have_posts()) : the_post(); ?>
<li><?php the_title(); ?></li>
<?php the_content();?>
<?php endwhile;?>
</ul>