PHP Question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BSleazy
    Confirmed User
    • Aug 2002
    • 6721

    #1

    PHP Question

    I'm trying to use some code I found to add numbers next to post titles in wordpress. I'm getting a unexpected t string error when using it. Any idea what the problem is?

    Code:
    <?php if ( $paged < 2 ) {
    $my_paged = 0;
    } else {
    $my_paged = ($paged ? 1) * get_option(?posts_per_page?);         <---this is the line thats causing the error it says.
    }
    $count = 1;
    ?>
    icq 156131086
  • Klen
    • Aug 2006
    • 32235

    #2
    Maybe you puted code to wrong wordpress file ?

    Comment

    • grumpy
      Too lazy to set a custom title
      • Jan 2002
      • 9870

      #3
      is get_option(‘posts_per_page’) defined?
      Don't let greediness blur your vision | You gotta let some shit slide
      icq - 441-456-888

      Comment

      • BSleazy
        Confirmed User
        • Aug 2002
        • 6721

        #4
        Hell if I know. These are the instructions I followed.

        http://blog.dembowski.net/2007/08/02/numbered-titles/
        icq 156131086

        Comment

        • harvey
          Confirmed User
          • Jul 2001
          • 9266

          #5
          try replacing this
          Code:
          $my_paged = ($paged ? 1) * get_option(?posts_per_page?);         <---this is the line thats
          with this:

          Code:
          $my_paged = ($paged ? 1) * get_option('posts_per_page');         <---this is the line thats
          This post is endorsed by CIA, KGB, MI6, the Mafia, Illuminati, Kim Jong Il, Worldwide Ninjas Association, Klingon Empire and lolcats. Don't mess around with it, just accept it and embrace the truth

          Comment

          • woj
            <&(©¿©)&>
            • Jul 2002
            • 47882

            #6
            wrong quotes, use single quotes -> '
            Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
            Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
            Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager

            Comment

            • BSleazy
              Confirmed User
              • Aug 2002
              • 6721

              #7
              Originally posted by harvey
              try replacing this
              Code:
              $my_paged = ($paged ? 1) * get_option(?posts_per_page?);         <---this is the line thats
              with this:

              Code:
              $my_paged = ($paged ? 1) * get_option('posts_per_page');         <---this is the line thats
              I'm still getting the same error on the same line.
              icq 156131086

              Comment

              • Brujah
                Beer Money Baron
                • Jan 2001
                • 22157

                #8
                Please don't listen to harvey, pete or woj. What you need here is to replace the ` backtick with a single quote character.


                lol

                Comment

                • woj
                  <&(©¿©)&>
                  • Jul 2002
                  • 47882

                  #9
                  Originally posted by Brujah
                  Please don't listen to harvey, pete or woj. What you need here is to replace the ` backtick with a single quote character.


                  lol
                  hey now, that's exactly what I said
                  Last edited by woj; 08-24-2011, 02:28 PM.
                  Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
                  Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
                  Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager

                  Comment

                  • Brujah
                    Beer Money Baron
                    • Jan 2001
                    • 22157

                    #10
                    Originally posted by BCyber
                    I'm still getting the same error on the same line.
                    It must be something else then. Try: get_option( "posts_per_page" )
                    just to compare

                    Comment

                    • V_RocKs
                      Damn Right I Kiss Ass!
                      • Nov 2003
                      • 32449

                      #11
                      Aldo 0 * something can generate an error...

                      Comment

                      • BSleazy
                        Confirmed User
                        • Aug 2002
                        • 6721

                        #12
                        Nothing seems to work
                        icq 156131086

                        Comment

                        • Brujah
                          Beer Money Baron
                          • Jan 2001
                          • 22157

                          #13
                          Originally posted by BCyber
                          Nothing seems to work
                          It's probably something else. Paste the lines before and after that, and or the exact error message.

                          Comment

                          • BSleazy
                            Confirmed User
                            • Aug 2002
                            • 6721

                            #14
                            I've moved it around which doesn't seem to help either.

                            Parse error: syntax error, unexpected T_STRING in *****/index.php on line 43

                            Code:
                            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                            
                            <?php $key="featured_external"; $custom = get_post_meta($post->ID, $key, true); ?>
                            
                            <?php if ( $paged < 2 ) {
                            $my_paged = 0;
                            } else {
                            $my_paged = ($paged ? 1) * get_option('posts_per_page');
                            }
                            $count = 1;
                            ?>
                            <div class="site clearfix" id="rgmevlsotukficza6158">
                            
                            <a href="<?php $key="featured_external"; echo get_post_meta($post->ID, $key, true); ?>"title="<?php the_title(); ?>">
                            <?php if ( has_post_thumbnail()) the_post_thumbnail('featured-thumb', array('class' => 'thumb')); ?>
                            </a>
                            
                            <a target="_blank" href="http://www.link-paysite.com" class="join-link">Visit Paysite # 01 NOW !</a>
                            <h1><?php echo $my_paged + $count . ?. ?; ?> <a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
                            <p><?php the_content(''); ?></p>
                            <a target="_blank" href="http://www.link.com" class="tour" id="ukplowdzgxbhtncyeqf7410">Free Preview</a>
                            <p class="clear"></p>
                            </div>
                            <?php $count = $count + 1; ?>
                            <?php endwhile; endif; ?>
                            icq 156131086

                            Comment

                            • harvey
                              Confirmed User
                              • Jul 2001
                              • 9266

                              #15
                              Originally posted by BCyber
                              I've moved it around which doesn't seem to help either.

                              Parse error: syntax error, unexpected T_STRING in *****/index.php on line 43

                              Code:
                              <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                              
                              <?php $key="featured_external"; $custom = get_post_meta($post->ID, $key, true); ?>
                              
                              <?php if ( $paged < 2 ) {
                              $my_paged = 0;
                              } else {
                              $my_paged = ($paged ? 1) * get_option('posts_per_page');
                              }
                              $count = 1;
                              ?>
                              <div class="site clearfix" id="rgmevlsotukficza6158">
                              
                              <a href="<?php $key="featured_external"; echo get_post_meta($post->ID, $key, true); ?>"title="<?php the_title(); ?>">
                              <?php if ( has_post_thumbnail()) the_post_thumbnail('featured-thumb', array('class' => 'thumb')); ?>
                              </a>
                              
                              <a target="_blank" href="http://www.link-paysite.com" class="join-link">Visit Paysite # 01 NOW !</a>
                              <h1><?php echo $my_paged + $count . ?. ?; ?> <a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
                              <p><?php the_content(''); ?></p>
                              <a target="_blank" href="http://www.link.com" class="tour" id="ukplowdzgxbhtncyeqf7410">Free Preview</a>
                              <p class="clear"></p>
                              </div>
                              <?php $count = $count + 1; ?>
                              <?php endwhile; endif; ?>
                              well, the code is pretty much a mess and it has several things to fix, but related to this function, I'd say your problem is in the formatting AGAIN. Just replace those ?. ?; with ". "; and see if it solves the issue. Also, I don't know why you need those strange id or 2 different clears or class + id for the same element, just clean things up and it will be a lot easier for you to locate errors
                              This post is endorsed by CIA, KGB, MI6, the Mafia, Illuminati, Kim Jong Il, Worldwide Ninjas Association, Klingon Empire and lolcats. Don't mess around with it, just accept it and embrace the truth

                              Comment

                              • Brujah
                                Beer Money Baron
                                • Jan 2001
                                • 22157

                                #16
                                The minus character is not a minus character in this:
                                ($paged – 1)

                                Fix that and you should be good.

                                Comment

                                • Brujah
                                  Beer Money Baron
                                  • Jan 2001
                                  • 22157

                                  #17
                                  Originally posted by harvey
                                  well, the code is pretty much a mess and it has several things to fix, but related to this function, I'd say your problem is in the formatting AGAIN. Just replace those ?. ?; with ". "; and see if it solves the issue. Also, I don't know why you need those strange id or 2 different clears or class + id for the same element, just clean things up and it will be a lot easier for you to locate errors
                                  I think the copy+paste just does that for a lot of people who copy code from blogs.

                                  Comment

                                  • BSleazy
                                    Confirmed User
                                    • Aug 2002
                                    • 6721

                                    #18
                                    Originally posted by Brujah
                                    The minus character is not a minus character in this:
                                    ($paged ? 1)

                                    Fix that and you should be good.
                                    Cool. It had to be ( $paged ? 1 )

                                    That removed the error but fuckin a now it just shows the number 1 next to every post. This is annoying
                                    icq 156131086

                                    Comment

                                    • Brujah
                                      Beer Money Baron
                                      • Jan 2001
                                      • 22157

                                      #19
                                      Originally posted by BCyber
                                      Cool. It had to be ( $paged ? 1 )

                                      That removed the error but fuckin a now it just shows the number 1 next to every post. This is annoying
                                      You keep resetting $count = 1; at the top of the loop.
                                      change $count = 1; to this
                                      if ( ! isset( $count ) ) $count = 1;

                                      Comment

                                      • BSleazy
                                        Confirmed User
                                        • Aug 2002
                                        • 6721

                                        #20
                                        Originally posted by Brujah
                                        You keep resetting $count = 1; at the top of the loop.
                                        change $count = 1; to this
                                        if ( ! isset( $count ) ) $count = 1;
                                        Alright I just pulled it back out of the loop and it's working right now. Thanks for all the help guys!
                                        icq 156131086

                                        Comment

                                        • Brujah
                                          Beer Money Baron
                                          • Jan 2001
                                          • 22157

                                          #21
                                          when you see code on a blog like that
                                          http://blog.dembowski.net/2007/08/02/numbered-titles/

                                          Mouseover the code snippet, and look at the icons. mouseover each of those and select either the view source, or copy to clipboard. That'd fix the errors introduced by trying to copy/paste the code from the blog formatting.

                                          Comment

                                          • BSleazy
                                            Confirmed User
                                            • Aug 2002
                                            • 6721

                                            #22
                                            Alright thanks.
                                            icq 156131086

                                            Comment

                                            • fris
                                              Too lazy to set a custom title
                                              • Aug 2002
                                              • 55679

                                              #23
                                              that sure is messy code ;)
                                              Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

                                              Comment

                                              • BSleazy
                                                Confirmed User
                                                • Aug 2002
                                                • 6721

                                                #24
                                                It's from a template I'm changing to a wordpress theme. I haven't edited the html yet. I know there's a bunch of unneeded crap in there. As far as the php goes...I'm not a programmer but it works.
                                                icq 156131086

                                                Comment

                                                Working...