Created WordPress as CMS? I am guarantee you’ll need this tricks. Because WordPress Custom Page is Gregorius tools we can use to create custom design/layout and whatever we want. I will show you how to Create Custom Page with Custom Loop and Query in WordPress and we’ll put some custom query (added extra query) to create custom loop as like in front page.
Example we want to put on Custom Loop content only from special category such as Tricks category. So all articles category will be loaded in our custom page example WordPress Tricks pages. Let’s move on.
We need to duplicate your default page.php template and rename it to page-tricks.php and added extra line on top header.
<?php /* Template Name: Page WordPress Tricks */ ?>
And we need added extra loop or remove default query. Whatever you want, I keep my original query and added extra query to create new loop. Here’s what I do. After original loop, I write some code below
<?php $temp_query = $wp_query; ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$sticky=get_option('sticky_posts');
$args=array(
'caller_get_posts'=>1,
'category_name' => 'Tricks',
'post__not_in' => $sticky,
'paged'=>$paged,
'posts_per_page'=>6,
);
//query_posts($args);
$my_query = new WP_Query($args);
while ($my_query->have_posts()) : $my_query->the_post();
?>
<div class="post-theme post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<div class="entry">
<p><?php the_excerpt(); ?></p>
</div>
<div class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> <?php if(function_exists('echo_tptn_post_count')) echo_tptn_post_count(); ?></div>
<div class="clear"></div>
</div>
<!-- Post -->
<?php endwhile; ?>
<br class="clear" />
<?php if(function_exists('wp_pagenavi')) { ?>
<div class="navinavi">
<?php
wp_pagenavi(); ?>
</div>
<br class="clear" />
<?php } else { ?>
<div class="navigation">
<div class="alignleft">
<?php next_posts_link(__('← Previous Entries','public')) ?>
</div>
<div class="alignright">
<?php previous_posts_link(__('Next Entries →','public')) ?>
</div>
</div>
<?php } ?>
<?php
$wp_query = $temp_query;
wp_reset_query();
?>
And done, you can upload you page-tricks.php to your theme folder and create new page and choose WordPress Tricks page template and done. Now all content on our Tricks category will be show up on my WordPress Tricks page. If you got some problem, please let’s me know and I hope tutorial Create Custom Page with Custom Loop and Query useful for you




Pingback: Tweets that mention How To Create Custom Page with Custom Query in WordPress # WordPress Tricks & Tips -- Topsy.com
Pingback: Cara Membuat Custom Page Special / ID-JAUHARI
Hi, thanks for this tip. But can I link a search form to this page, so I search only in a specific category? If so how do I do that? I have been trying to create a search only in specific pages, and in the search form I have – action=”/pesquisar-criaturas”
“pesquisar-criaturas” is the permalink for the page, using the template for my specific search. And the page is there if you go directly to that link, but if I make a search it gives me a 404 error.
Can you give me any help with this?
Thanks
HI Margarida Fernandes
Can you explain more details? What’s you mean with link a search form? Of course you can add search form on this custom template. If you need searching method and display on some page… (with custom template) I think you need a little bit more complicated code or plugins..
if you go to criaturas.magaworks.com (still in development) there is a search form there, and it is supposed to search only in pages, not posts, so it only gives results of pages.
So I created a new search page template “searchResults.php”, and added a new page “pesquisar-criaturas” using that “searchResults.php” as template. Then in my search form I added the code – action=”/pesquisar-criaturas”. But if I make a search it gives a 404 error. But if you go to the page “http://criaturas.magaworks.com/pesquisar-criaturas/” there is no error, the page is there.
The code to search just pages is not implemented yet. Right now the “searchResults.php” has the same code has my search page, but it should work just the same right? Giving results for posts and pages.
I just can’t figure out what is happening.
I was looking out on http://criaturas.magaworks.com/pesquisar-criaturas/ and your code still display pure… I think this is not Custom Page, because your PHP code still displayed without executed
Margarida, have you figured this out at all yet? On this page
http://blogs.terrapinn.com/topic/energy%20and%20resources
I get “Page not found” which is wrong. I’ve not been able to override the wp-title via action/filter, and I’ve been led towards $wp_query being false and setting is_404=true -from source:
“@return bool True, if nothing is found matching WordPress Query.”
but unable to fix as yet! Any help greatly appreciated..
Pingback: uberVU - social comments
Pingback: How To Create "Dynamics Statics" Pages on WordPress # WordPress Tricks & Tips
Pingback: How To Create “Dynamics Statics” Pages | Silver Blog
Pingback: How To Create “Dynamics Statics” Pages | Unlock IMEI Cellphones
Pingback: Custom Query String (Reloaded) | Unlock IMEI Cellphones
Pingback: Automatically Create a Custom Field | Unlock IMEI Cellphones
if i create a page like page tricks, what is the file name of the page. and how to access this page. in the admin section i added my custom page in one menu.
also, how to give link to access this page.
suppose i want to access user custom page by clicking the link in another page, then how should i give the link to tag.
Please explain more..
how do I make a special page category. where now a category that we are open, that there is not a list of posts, but the list of categories that exist underneath. after we open again, there are new posts list.
Thank you. please help