WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] I have a doozy..... (12 posts)

  1. mkbclr
    Member
    Posted 1 year ago #

    Ok - this is crazy....

    on a single.php i have this

    <?php
    $query = new WP_Query(

    array(
    'paged' => curPageURL(),
    'post_type' => 'video',
    'order_by' => 'date',
    'order' => 'desc',
    'cat' => $cat_ID,
    'posts_per_page' => 18

    )

    ); ?>

    i found that no pagination plugins work on single.php - so i wrote my own using and manipulating the URI based on which page you are currently on.

    My problem is that no matter how many numbers you put after the url, the page still loads. the pagination will say page 11111111111111 of 4. then.... the previous link gets all screwy.

    the real issue is that somehow google has indexed about 18000 of these crazy urls, and they show as crawl errors and we are losing traffic.

    here is a sample url...
    /video/how-to-plant-ground-cover-to-prevent-erosion/11111111111111111111111111111111-9223372036854775808

    i feel pretty sure it has something to do with the query - but i have no idea what it could be.

    please help!

    thanks

  2. Umbercode
    Member
    Posted 1 year ago #

    What does curPageURL() do? Judging from the function-name it returns the url of the current page? If so, the 'paged' key only accepts the current page NUMBER, not the URL. Perhaps that is the problem?

  3. mkbclr
    Member
    Posted 1 year ago #

    oh yea h- that makes sense :)

    how does this look? (it still servers the crazy 11111111111 urls btw)

    <?php function curPageURL() {
    $pageURL = 'http';
    //check what if its secure or not
    if ($_SERVER["HTTPS"] == "on") {
    $pageURL .= "s";
    }
    //add the protocol
    $pageURL .= "://";
    //check what port we are on
    if ($_SERVER["SERVER_PORT"] != "80") {
    $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
    $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }
    //cut off everything on the URL except the last 3 characters
    $urlEnd = substr($pageURL, -3);
    //strip off the two forward shashes
    $page = str_replace("/", "", $urlEnd);
    //return just the number
    return intval($page);

    }

    ?>

    <?php
    $query = new WP_Query(

    array(
    'paged' => $page,
    'post_type' => 'video',
    'order_by' => 'date',
    'order' => 'desc',
    'cat' => $cat_ID,
    'posts_per_page' => 18

    )

    ); ?>
    <h3><?php $num = $query->found_posts;
    $totalpages = ceil($num / 18);
    echo $num;?>

  4. Umbercode
    Member
    Posted 1 year ago #

    Hmm, I am not sure what the context is in which you try to do this, but if I remember correctly you can display the current page of a pages set like so:

    $query = new WP_Query(
      array(
        'paged' => get_query_var('paged'),
        'post_type' => 'video',
        'order_by' => 'date',
        'order' => 'DESC',
        'cat' => $cat_ID,
        'posts_per_page' => 18
    )

    No need to use a custom function to get the current pagenumber.
    Also, where does $cat_ID come from?
    I am however suspecting that your problem resides elsewhere in your code.

  5. mkbclr
    Member
    Posted 1 year ago #

    the whole problem came about when i wasn't able to use pagination on a single.php. that's when i had to start all this craziness rather than just the plain ole' use the loop - use a pagination plug like normal.

    $cat_ID is just an if statement so i can control which wordpress category is used.

    you got any idea where i should start looking? i have the standard wordpress stuff in htaccess - and i dont have any other ideas...

  6. Umbercode
    Member
    Posted 1 year ago #

    oh, sorry I missed the part about this code being in single.php. That clears up something.
    I don't think there is a "current page" on a single page (the name says it all) because a single page is just that, single (please correct me if I am wrong). So in order to create a WP_Query on that page showing multiple (I am assuming related to the current page) video's in pages (it is probably better to speak of "sets" in this case) you probably need to "manually" keep track of the current "set". Or use the 'offset' key http://codex.wordpress.org/Class_Reference/WP_Query#Offset_Parameter

  7. mkbclr
    Member
    Posted 1 year ago #

    as if it is not obvious - i am kind of a php / wordpress hack.

    and chance you could help me out with what would work?

    i have never heard of offset, but am reading the link you sent now. i just don't quite understand yet.

  8. mkbclr
    Member
    Posted 1 year ago #

    as best i can tell i should remove the paged key and replace with 'offset' => 1

    am i on the right track?

  9. Umbercode
    Member
    Posted 1 year ago #

    Perhaps it would help if you try to explain what it is exactly that you want to accomplish?
    The way I understand it is as follows:
    You have a post and when showing that post you want to include video's on the same page that relate to that post. Is that correct?

  10. mkbclr
    Member
    Posted 1 year ago #

    fwiw i put in the offset key and removed paged
    everything works the same - with the crazy urls still serving.

    as for what i am trying to do....
    take a look here -

    http://www.todayshomeowner.com/video/installing-bifold-doors/2/

    this will give you the second page

    everything works like i want it to, but it will still serve these crazy urls ending with a long string of numbers (if you replace the 2 with 111111111111111111 the page will load)

    google has indexed all these crazy urls and it's causing us trouble. i don't know how they got to the bad urls, since there is no link to them. you can only get there by typing the numbers in.

    all i want it for those crazy urls not to load a page - a 404 would be nice.

  11. Umbercode
    Member
    Posted 1 year ago #

    Can you email me, perhaps we can get more "productive" that way. As long as you post the solution here later when we find it.

  12. mkbclr
    Member
    Posted 1 year ago #

    This was resolved thanks to Umbercode - all around good guy

    Here's his response

    So I did some test on my testsite and found that any single.php page accepts any slug behind it. For example, taking wordpress's own site if you go to this link: http://wordpress.org/news/2012/09/wordpress-3-5-beta-1
    is the same as going to this link:
    http://wordpress.org/news/2012/09/wordpress-3-5-beta-1/11111111111111111111111111/

    Bit of a weird behaviour, but it seems to be "normal" so at least it is not something in your code. So as long as you make sure there are no links to any of these strange pages Google will be happy and so will you ;-)

Topic Closed

This topic has been closed to new replies.

About this Topic