WordPress.org

Forums

[resolved] PHP Code Help for Archive Timeline Plugin (3 posts)

  1. lok1728
    Member
    Posted 10 years ago #

    I'm trying to change the WordPress Archive Timeline Plugin http://www.lalala.fr/blog/?p=25
    so that I can have posts show only in the timeline archive per the category showing. (I've left a post at the authors site and have emailed but I can't seem to get a response.)

    Basically I want posts related to category selected by viewer to show in the archive.

    Here's the original code where I am thinking to change so it will only show the category posts (not my entire archive of posts):

    // Get all posts
    $posts = $wpdb->get_results(
    "SELECT post.* FROM $tableposts as post WHERE post.post_status='publish' ORDER BY post.post_date DESC" . $Limit
    );

    The code I've changed/added:

    I've added the global variable (note: I'm not very PHP literate) $tablepost2cat so I can pull only the category posts for that page. I'm calling the plugin from within my category.php file.

    function wp_timeline() {

    global
    $wpdb, $tableposts, $tablepost2cat, $wp_query,
    $IMAGE_URI, $MAX_NB_POSTS, $TIMELINE_URI, $USE_TITLES, $THEME_URI;

    // Get all posts
    $posts = $wpdb->get_results(
    "SELECT post.* FROM
    $tableposts as post,
    $tablepost2cat as post2cat
    WHERE
    (post.post_status='publish') AND
    (post2cat.category_id=$category->cat_ID) AND
    (post2cat.post_id=post.ID)
    ORDER BY post.post_date DESC" . $Limit
    );

    Here's the error received:

    WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND (post2cat.post_id=post.ID) ORDER BY post.post_date DESC' at line 6]
    SELECT post.* FROM wp_posts as post, wp_post2cat as post2cat WHERE (post.post_status='publish') AND (post2cat.category_id=) AND (post2cat.post_id=post.ID) ORDER BY post.post_date DESC

    ----
    So, I must have my query and/or syntax wrong but since I'm not fluent with MYSQL or PHP I've not been able to fix this.

    Could someone point out where I'm going wrong?

  2. lok1728
    Member
    Posted 10 years ago #

    My apologies for failing to use the backtick for code display. Here's the post again with the code properly show. ;)

    I'm trying to change the WordPress Archive Timeline Plugin ( lalala.fr/blog/?p=25 )so that I can have posts show only in the timeline archive per the category showing. (I've left a post at the authors site and have emailed but I can't seem to get a response.)

    Basically I want posts related to category selected by viewer to show in the timeline.

    Here's the original code where I am thinking to change so it will only show the category posts (not my entire archive of posts):

    // Get all posts
    $posts = $wpdb->get_results(
    "SELECT post.* FROM $tableposts as post WHERE post.post_status='publish' ORDER BY post.post_date DESC" . $Limit
    );

    The code I've changed/added:

    I've added the global variable (note: I'm not very PHP literate) $tablepost2cat so I can pull only the category posts for that page. I'm calling the plugin from within my category.php file.

    function wp_timeline()

    global
    $wpdb, $tableposts, $tablepost2cat, $wp_query,
    $IMAGE_URI, $MAX_NB_POSTS, $TIMELINE_URI, $USE_TITLES, $THEME_URI;

    // Get all posts
    $posts = $wpdb->get_results(
    "SELECT post.* FROM
    $tableposts as post,
    $tablepost2cat as post2cat
    WHERE
    (post.post_status='publish') AND
    (post2cat.category_id=$category->cat_ID) AND
    (post2cat.post_id=post.ID)
    ORDER BY post.post_date DESC" . $Limit
    );

    Here's the error received:

    WordPress database error:
    [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND (post2cat.post_id=post.ID) ORDER BY post.post_date DESC' at line 6]
    SELECT post.* FROM wp_posts as post, wp_post2cat as post2cat WHERE (post.post_status='publish') AND (post2cat.category_id=) AND (post2cat.post_id=post.ID) ORDER BY post.post_date DESC

    ----
    So, I must have my query and/or syntax wrong but since I'm not fluent with MYSQL or PHP I've not been able to fix this.

    Could someone point out where I'm going wrong?

  3. lok1728
    Member
    Posted 10 years ago #

    Author of the plugin has updated the code to filter posts per category.

Topic Closed

This topic has been closed to new replies.

About this Topic