2010-10-06 24 views
6

इस बुनियादी पाशWordpress पाश शो सीमा पदों

<?php while (have_posts()) : the_post(); ?>

मैं खोज परिणाम पृष्ठ पर 20 पोस्ट दिखाने के लिए चाहते हैं, मुझे पता है हम व्यवस्थापक पैनल विकल्पों पर मूल्य बदल सकते हैं। लेकिन यह सभी i.e. इंडेक्स पेज और संग्रह पृष्ठ आदि को बदल देगा। मुझे उन्हें अलग-अलग करने की आवश्यकता है।

धन्यवाद!

उत्तर

8

महान संदर्भ: http://codex.wordpress.org/The_Loop

बस इससे पहले कि आप बयान कहते हैं, आप पोस्ट क्वेरी करने के लिए की जरूरत है। तो:

<?php query_posts('posts_per_page=20'); ?> 

    <?php while (have_posts()) : the_post(); ?> 
    <!-- Do stuff... --> 
    <?php endwhile;?> 

संपादित करें: पृष्ठांकन के बारे में क्षमा करें, यह प्रयास करें:

<?php 
     global $query_string; 
     query_posts ('posts_per_page=20'); 
     if (have_posts()) : while (have_posts()) : the_post(); 
    ?> 
    <!-- Do stuff --> 
    <?php endwhile; ?> 

    <!-- pagination links go here --> 

    <? endif; ?> 
+0

यह बढ़िया है! अच्छा काम करता है। धन्यवाद! – ray

+1

ऐसा लगता है कि पेजिनेशन अब और काम नहीं करेगा! कोई उपाय? – ray

+2

'post_per_page' को 'showposts' में बदलें? – Gipetto

1

आप विभिन्न पृष्ठों के लिए अलग अलग छोरों के साथ टेम्पलेट फ़ाइलों का एक समूह बनाने और पृष्ठांकन संरक्षित करने के लिए नहीं करना चाहते हैं, http://wordpress.org/extend/plugins/custom-post-limits/

0

आप $ wp_query ऑब्जेक्ट के माध्यम से प्रति लूप पोस्ट की संख्या सीमित कर सकते हैं। यह उदाहरण के लिए एक से अधिक पैरामीटर लेता है:

<?php 
$args = array('posts_per_page' => 2, 'post_type' => 'type of post goes here'); 
$query = new WP_Query($args); 
while($query->have_posts()) : $query->the_post(); 
<!-- DO stuff here--> 
?> 

अधिक wp_query वस्तु पर here->

0

जोड़े 'पर पृष्ठांकित' => $ पृष्ठांकित पृष्ठांकन काम करेगा!

<?php 
$args = array('posts_per_page' => 2, 'paged' => $paged); 
$query = new WP_Query($args); 
while($query->have_posts()) : $query->the_post(); 
<!-- DO stuff here--> 
?> 
1

टेम्पलेट के अंदर नई क्वेरी के साथ उत्तर कस्टम पोस्ट प्रकारों के साथ सही ढंग से काम नहीं करेंगे।

लेकिन documentation किसी भी प्रश्न पर हुक करने की पेशकश करता है, चेक यह मुख्य प्रश्न है, और इसे निष्पादन से पहले संशोधित करें। यह टेम्पलेट कार्यों के अंदर किया जा सकता है:

function my_post_queries($query) { 
    // do not alter the query on wp-admin pages and only alter it if it's the main query 
    if (!is_admin() && $query->is_main_query()) { 
    // alter the query for the home and category pages 
    if(is_home()){ 
     $query->set('posts_per_page', 3); 
    } 

    if(is_category()){ 
     $query->set('posts_per_page', 3); 
    } 
    } 
} 
add_action('pre_get_posts', 'my_post_queries'); 
0

मुझे यह समाधान मिल गया है और यह मेरे लिए काम करता है।

global $wp_query; 
$args = array_merge($wp_query->query_vars, ['posts_per_page' => 20 ]); 
query_posts($args); 

if(have_posts()){ 
    while(have_posts()) { 
    the_post(); 
    //Your code here ... 
    } 
}