Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP Help Required

  • 12-03-2011 8:34pm
    #1
    Closed Accounts Posts: 112 ✭✭


    I have a wordpress powered site, which uses a classified ads theme.

    The blog page on my site is set to show videos. I would like the blog to show only one video per page.

    If I change the posts per page settings in the wordpress admin, then that interferes with the classifieds theme. I need to change one of the php files.

    Here is the file that distinguishes the blog from the classifieds in the theme.
    <?php get_header(); ?>
    
    <!-- CONTENT -->
      <div class="content">
    
          <div class="content_botbg">
    
              <div class="content_res">
    
                  <div id="breadcrumb">
                      <?php if(function_exists('cp_breadcrumb')) cp_breadcrumb(); ?>
                  </div>
    
                    <div class="content_left">
    
                        <?php if(have_posts()) : ?>
    
                            <?php while(have_posts()) : the_post() ?>
    
                            <?php $category = get_the_category(); // To show only 1 Category ?>
    
                                <div class="shadowblock_out">
    
                                    <div class="shadowblock">
    
                                        <div class="post">
    
                                            <h2 class="dotted"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
                                                <p class="meta"><?php _e('Posted','cp'); ?> <?php echo cp_ad_posted($post->post_date); ?> <?php _e('by','cp'); ?> <?php the_author_posts_link(); ?> <?php _e('in','cp'); ?> <?php the_category(', ') ?> | <?php comments_popup_link( __('No comments yet', 'cp'), __('1 comment', 'cp'), __('% comments', 'cp')); ?></p>
                                            </h2>
    
                                            <?php if (has_post_thumbnail()) { the_post_thumbnail('blog-thumbnail');} ?>
    
                                            <?php the_content('Continue reading &raquo;', 'cp'); ?>
    
                                        </div><!-- /post-->
    
                                       </div><!-- /shadowblock -->
    
                                </div><!-- /shadowblock_out -->
    
    
                                <?php endwhile; ?>
    
                                    <?php if(function_exists('cp_pagination')) { cp_pagination(); } ?>
    
                                <?php else: ?>
    
                                    <p><?php _e('Sorry, no posts matched your criteria.','cp'); ?></p>
    
                                <?php endif; ?>
    
                    
                            <div class="clr"></div>
    
       
                        </div><!-- /content_left -->
    
    
                    <?php get_sidebar('blog'); ?>
    
    
                <div class="clr"></div>
    
          </div><!-- /content_res -->
    
        </div><!-- /content_botbg -->
    
      </div><!-- /content -->
    
    
    <?php get_footer(); ?>
    

    Here is what I believe to be the relevant piece of code from a settings php file.
    function cp_pagination($before = '', $after = '') {
        global $wpdb, $wp_query;
        if (!is_single()) {
    
            $pagenavi_options = array(
                    'pages_text' => __('Page %CURRENT_PAGE% of %TOTAL_PAGES%','cp'),
                    'current_text' => '%PAGE_NUMBER%',
                    'page_text' => '%PAGE_NUMBER%',
                    'first_text' => __('&lsaquo;&lsaquo; First','cp'),
                    'last_text' => __('Last &rsaquo;&rsaquo;','cp'),
                    'next_text' => __('&rsaquo;&rsaquo;','cp'),
                    'prev_text' => __('&lsaquo;&lsaquo;','cp'),
                    'dotright_text' => '',
                    'dotleft_text' => '',
                    'style' => 1,
                    'num_pages' => 15,                
                    'always_show' => 0,
                    'num_larger_page_numbers' => 3,
                    'larger_page_numbers_multiple' => 10,
            );
    
            $posts_per_page = intval(get_query_var('posts_per_page'));
            $paged = intval(get_query_var('paged'));
            $numposts = $wp_query->found_posts;
            $max_page = $wp_query->max_num_pages;
            if(empty($paged) || $paged == 0) {
                $paged = 1;
            }
            $pages_to_show = intval($pagenavi_options['num_pages']);
    

    Thank YOu!

    I tried the following but it didnae work:
    $posts_per_page = 1;
    


Comments

  • Closed Accounts Posts: 112 ✭✭DeanSmedley


    Is a bump permissible?


  • Registered Users, Registered Users 2 Posts: 5,246 ✭✭✭conor.hogan.2


    You dont seem to be getting much help here which is unusual but anyway you should try a php irc channel - most likely on freenode but google around for it.


  • Registered Users, Registered Users 2 Posts: 6,602 ✭✭✭daymobrew


    I don't think that the cp_pagination() function is what you need to change it is called after the loop. I think that you need to add code before the loop starts.
    [PHP]<div class="content_left">

    // Only return 1 post.
    global $query_string;
    query_posts( $query_string . '&posts_per_page=1 );

    <?php if(have_posts()) : ?>[/PHP]


  • Closed Accounts Posts: 112 ✭✭DeanSmedley


    Thanks daymobrew, but when I do that this is what I get..

    http://www.farmads.ie/new/Sem%20t%C3%ADtulo.jpg


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    you have to wrap it in php tags <?php ?> to have it interpreted.


  • Advertisement
  • Closed Accounts Posts: 112 ✭✭DeanSmedley


    Thanks Webmonkey !!

    Then I get this error:

    Parse error: syntax error, unexpected '=' in /home/farmads/public_html/new/wp-content/themes/classipress/archive-blog.php on line 19




    When I put in this -
    // Only return 1 post.
     <?php global $query_string; ?>
     <?php query_posts( $query_string . '&posts_per_page'=1 ); ?>
    


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    The error suggest's the problem The ' should be outside = 1.

    So:

    <?php query_posts( $query_string . '&posts_per_page=1' ); ?>


  • Closed Accounts Posts: 112 ✭✭DeanSmedley


    Thanks webmonkey !!

    I have been trying to solve this for a long time! I appreciate it alot..


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    No prob but I think it's really daymobrew that deserves the credit ;)


  • Closed Accounts Posts: 112 ✭✭DeanSmedley


    Ok it is showing one page but now it is doing something strange..

    Only the first 6 pages work, after that the pages are blank...

    http://www.farmads.ie/new/category/farming-videos/


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 6,602 ✭✭✭daymobrew


    Webmonkey wrote: »
    No prob but I think it's really daymobrew that deserves the credit ;)
    We should share the credit because you had to fix my typo and missing tags.


  • Closed Accounts Posts: 112 ✭✭DeanSmedley


    You should both take some credit !!

    But anyway,

    Can someone tell me why it stops after 6 pages ???


  • Registered Users, Registered Users 2 Posts: 6,602 ✭✭✭daymobrew


    Can someone tell me why it stops after 6 pages ???
    How many videos did it used to display per page? 7 or 8 perhaps?

    I am wondering if there is another bit of code that sets or uses the posts_per_page setting.


  • Closed Accounts Posts: 112 ✭✭DeanSmedley


    It used to display 8 per page.

    I am looking to for another piece of code that sets the posts_per_page.

    I am using the classipress theme from appthemes.org

    My site again is FarmAds.ie


  • Registered Users, Registered Users 2 Posts: 6,602 ✭✭✭daymobrew


    I am using the classipress theme from appthemes.org
    As it is not a free theme, we cannot download the source to look for the code in question.

    As you paid for the theme you should ask at their forums (or the Troubleshooting one). They will know the theme well.


  • Registered Users, Registered Users 2 Posts: 6,602 ✭✭✭daymobrew


    You should try setting [PHP]$posts_per_page = 1;[/PHP] like you did in your first post. While I doubt that it will work, it is worth trying.


  • Closed Accounts Posts: 112 ✭✭DeanSmedley


    Thanks daymo.

    I have tried asking for help on their forum, but there are very few serious programmers there who could help, and even less who are inclined to answer all the questions.

    I think the reason it is only showing 6 pages is that it is still calculating the number of pages needed based on the 8 posts per page, that I have the classified ads set to.

    Just like I am using a new query for this category, I need to set a new way for it to calculate the number of pages.

    The number of pages is calculated here:
    $posts_per_page = 1;
            $paged = intval(get_query_var('paged'));
            $numposts = $wp_query->found_posts;
            $max_page = $wp_query->max_num_pages;
            if(empty($paged) || $paged == 0) {
                $paged = 1;
            }
            $pages_to_show = intval($pagenavi_options['num_pages']);
            $larger_page_to_show = intval($pagenavi_options['num_larger_page_numbers']);
            $larger_page_multiple = intval($pagenavi_options['larger_page_numbers_multiple']);
            $pages_to_show_minus_1 = $pages_to_show - 1;
            $half_page_start = floor($pages_to_show_minus_1/2);
            $half_page_end = ceil($pages_to_show_minus_1/2);
            $start_page = $paged - $half_page_start;
            if($start_page <= 0) {
                $start_page = 1;
            }
            $end_page = $paged + $half_page_end;
            if(($end_page - $start_page) != $pages_to_show_minus_1) {
                $end_page = $start_page + $pages_to_show_minus_1;
            }
            if($end_page > $max_page) {
                $start_page = $max_page - $pages_to_show_minus_1;
                $end_page = $max_page;
            }
            if($start_page <= 0) {
                $start_page = 1;
            }
            $larger_per_page = $larger_page_to_show*$larger_page_multiple;
            $larger_start_page_start = (cp_round($start_page, 10) + $larger_page_multiple) - $larger_per_page;
            $larger_start_page_end = cp_round($start_page, 10) + $larger_page_multiple;
            $larger_end_page_start = cp_round($end_page, 10) + $larger_page_multiple;
            $larger_end_page_end = cp_round($end_page, 10) + ($larger_per_page);
            if($larger_start_page_end - $larger_page_multiple == $start_page) {
                $larger_start_page_start = $larger_start_page_start - $larger_page_multiple;
                $larger_start_page_end = $larger_start_page_end - $larger_page_multiple;
            }
            if($larger_start_page_start <= 0) {
                $larger_start_page_start = $larger_page_multiple;
            }
            if($larger_start_page_end > $max_page) {
                $larger_start_page_end = $max_page;
            }
            if($larger_end_page_end > $max_page) {
                $larger_end_page_end = $max_page;
            }
            if($max_page > 1 || intval($pagenavi_options['always_show']) == 1) {
                $pages_text = str_replace("%CURRENT_PAGE%", number_format_i18n($paged), $pagenavi_options['pages_text']);
                $pages_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pages_text);
                echo $before.'<div class="whiteblock">'."\n";
                    if(!empty($pages_text)) {
                        echo '<div class="pages"><span>'.$pages_text.'</span>';
                    }
                    if ($start_page >= 2 && $pages_to_show < $max_page) {
                        $first_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pagenavi_options['first_text']);
                        echo '<a href="'.clean_url(get_pagenum_link()).'" class="first" title="'.$first_page_text.'">'.$first_page_text.'</a>';
                        if(!empty($pagenavi_options['dotleft_text'])) {
                            echo '<span class="extend">'.$pagenavi_options['dotleft_text'].'</span>';
                        }
                    }
                    if($larger_page_to_show > 0 && $larger_start_page_start > 0 && $larger_start_page_end <= $max_page) {
                        for($i = $larger_start_page_start; $i < $larger_start_page_end; $i+=$larger_page_multiple) {
                            $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
                            echo '<a href="'.clean_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>';
                        }
                    }
                    previous_posts_link($pagenavi_options['prev_text']);
                    for($i = $start_page; $i  <= $end_page; $i++) {
                        if($i == $paged) {
                            $current_page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['current_text']);
                            echo '<span class="current">'.$current_page_text.'</span>';
                        } else {
                            $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
                            echo '<a href="'.clean_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>';
                        }
                    }
                    next_posts_link($pagenavi_options['next_text'], $max_page);
                    if($larger_page_to_show > 0 && $larger_end_page_start < $max_page) {
                        for($i = $larger_end_page_start; $i <= $larger_end_page_end; $i+=$larger_page_multiple) {
                            $page_text = str_replace("%PAGE_NUMBER%", number_format_i18n($i), $pagenavi_options['page_text']);
                            echo '<a href="'.clean_url(get_pagenum_link($i)).'" class="page" title="'.$page_text.'">'.$page_text.'</a>';
                        }
                    }
                    if ($end_page < $max_page) {
                        if(!empty($pagenavi_options['dotright_text'])) {
                            echo '<span class="extend">'.$pagenavi_options['dotright_text'].'</span>';
                        }
                        $last_page_text = str_replace("%TOTAL_PAGES%", number_format_i18n($max_page), $pagenavi_options['last_text']);
                        echo '<a href="'.clean_url(get_pagenum_link($max_page)).'" class="last" title="'.$last_page_text.'">'.$last_page_text.'</a>';
                    }
    
                echo '</div><div class="clr"></div></div>'.$after."\n";
            }
        }
    }
    


    SO! I am trying something like this, but its not working:
    <?php global $query_string; ?>
                       <?php query_posts( $query_string . '&posts_per_page=1', '&pages_to_show=&numposts' ); ?>
    


  • Registered Users, Registered Users 2 Posts: 981 ✭✭✭fasty


    You're building the query string wrong I think...
    <?php query_posts( $query_string . '&posts_per_page=1', '&pages_to_show=[b]&[/b]numposts' ); ?>
    

    It should be:
    <?php query_posts( $query_string . '&posts_per_page=1', '&pages_to_show=' . $numposts ); ?>
    

    Anything inside '' is a string, the . contatenates strings and you anything that's a PHP variable will always have a $ in front of it in your script. I'm terrible for making the same mistakes when I'm working with PHP :D


  • Registered Users, Registered Users 2 Posts: 6,602 ✭✭✭daymobrew


    SO! I am trying something like this, but its not working:
    <?php global $query_string; ?>
                       <?php query_posts( $query_string . '&posts_per_page=1', '&pages_to_show=&numposts' ); ?>
    
    Change the comma in that code to full stop
    <?php global $query_string; ?>
                       <?php query_posts( $query_string . '&posts_per_page=1' . '&pages_to_show=&numposts' ); ?>
    
    This may not make it work but the query_posts() call was wrong.

    I think that it would take a good bit of hands-on debugging with the live code to figure out this.

    Could you ask the appthemes.com support people how you can achieve what you are trying to do? I saw that they don't support modifications to the theme but you could approach it from the other direction - how to get this feature in an unmodified theme.


  • Closed Accounts Posts: 112 ✭✭DeanSmedley


    Thanks guys, I am almost certain that the $max_page is the one that I need to set, but when I do this it has no effect:
    <?php global $query_string; ?> 
    <?php query_posts( $query_string . '&posts_per_page=1' . '&max_page=&numposts' ); ?> 
    

    Neither of your suggestions worked, but I feel that we are almost there!!


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 981 ✭✭✭fasty


    Just looking at the docs for the query_post function here and the parameters here seems to say there is no num_posts param that you can pass to query_posts.

    I don't have a WP install in work to help you any more I'm afraid

    Have you already tried this?
    query_posts($query_string . '&posts_per_page=1');
    


  • Closed Accounts Posts: 112 ✭✭DeanSmedley


    ok, but I tried setting max_page to a number value and that didnt work either.


  • Registered Users, Registered Users 2 Posts: 539 ✭✭✭but43r


    Why don't you change this:
    $numposts = $wp_query->found_posts;
            $max_page = $wp_query->max_num_pages;
    

    to this:
    $numposts = $wp_query->found_posts;
    $max_page = $numposts ;
    


    Thats not right...
    You should be setting pages_to_show variable the same as $numposts varible


  • Closed Accounts Posts: 112 ✭✭DeanSmedley


    fasty wrote: »
    Have you already tried this?
    query_posts($query_string . '&posts_per_page=1');
    

    Yes, and that gives me only 6 or 7 pages, with the rest of the pages not showing - page 42 of 7, page 14 of 7 etc.


  • Closed Accounts Posts: 112 ✭✭DeanSmedley


    but43r wrote: »
    Why don't you change this:
    $numposts = $wp_query->found_posts;
            $max_page = $wp_query->max_num_pages;
    
    to this:
    $numposts = $wp_query->found_posts;
    $max_page = $numposts ;
    

    If I did that in the theme-functions.php file, then it would change the number of pages for the whole site, I just want to change it for this specific category, that;s why I;m using a query in the archive-blog.php which seperates the blog from the user generated classified posts.


  • Registered Users, Registered Users 2 Posts: 539 ✭✭✭but43r


    I see.
    Should the query not be this:
    <?php query_posts( $query_string . '&posts_per_page=1' . '&max_page=&numposts'.'&pages_to_show=&numposts' ); ?>
    


  • Closed Accounts Posts: 112 ✭✭DeanSmedley


    Nope it dont work sorry but43r


  • Registered Users, Registered Users 2 Posts: 105 ✭✭damoth


    Thanks guys, I am almost certain that the $max_page is the one that I need to set, but when I do this it has no effect:
    <?php global $query_string; ?> 
    <?php query_posts( $query_string . '&posts_per_page=1' . '&max_page=&numposts' ); ?> 
    

    Neither of your suggestions worked, but I feel that we are almost there!!

    Hi,

    Sorry, I haven't taken the time to read all the way back but just looking at the query_posts call I see two possible problems...

    &numposts should probably be $numposts

    secondly, i'd be careful to keep the variable name ($numposts) outside the quotes - can't remember exactly which way PHP interprets variables within single vs double quotes.

    query_posts( $query_string . '&posts_per_page=1&max_page=' . $numposts );

    similarly...
    query_posts( $query_string . '&posts_per_page=1&max_page=' . $numposts . '&pages_to_show=' . $numposts);


  • Closed Accounts Posts: 112 ✭✭DeanSmedley


    Ok Damoth thanks, I just applied that there, but sadly it doesnt work.

    We are getting close though I am sur!!!


  • Advertisement
  • Closed Accounts Posts: 112 ✭✭DeanSmedley


    Hi again guys, I have some progress.

    One of the guys in the appthemes forum, suggest I take a look at the following hacks and apply it to my case.

    I tried myself, but being a PHP novice, I find I am unable.

    1. - http://wordpress.org/support/topic/query_posts-pagination-not-working

    2. - http://buzz.hyperspective.com/?p=7


  • Registered Users, Registered Users 2 Posts: 105 ✭✭damoth


    Hi,

    I had a quick look at the two links you posted. I suggest you try modify the original code to look like this, adding the two lines before if(have_posts()).
    <div class="content_left">
    
       // Add these two lines
       <?php $args = array( 'posts_per_page' => 1, 'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1), ); ?>
       <?php query_posts($args); ?>
    				
       <?php if(have_posts()) : ?>
    


  • Closed Accounts Posts: 5 amk2010


    well i have visited the Appthemes website .... they are providing some good quality wrodpress themes.
    1.gif


  • Closed Accounts Posts: 5 amk2010


    daymobrew wrote: »
    As it is not a free theme, we cannot download the source to look for the code in question.

    As you paid for the theme you should ask at their forums (or the Troubleshooting one). They will know the theme well.

    yes exactly, Appthemes provide some good quality themes but they are not free :( can anybody please share some links having good quality free themes?


  • Closed Accounts Posts: 5 amk2010


    daymobrew wrote: »
    As it is not a free theme, we cannot download the source to look for the code in question.

    As you paid for the theme you should ask at their forums (or the Troubleshooting one). They will know the theme well.

    i have visited appthemes site for classipress and it looks good via demo but apptheme's themes are coslty ... can any body please let me know some good quality but a lillte bit cheap or free wordpress themes? Thanks
    1.gif


  • Registered Users, Registered Users 2 Posts: 6,602 ✭✭✭daymobrew


    amk2010 wrote: »
    i have visited appthemes site for classipress and it looks good via demo but apptheme's themes are coslty ... can any body please let me know some good quality but a lillte bit cheap or free wordpress themes? Thanks
    1.gif
    Beware: you get what you pay for!
    There is good value on http://themeforest.net/


  • Advertisement
Advertisement