[Support request] Page template ?

Home Forums Support Page template ?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #968022
    Vuong

    Hello..could you pls help me.
    Im using WP U Like to make a like system for wordpress..trouble is,i dont know how to show most liked post..i checked faq then they said :
    use this code
    “<?php
    $the_query = new WP_Query(array(
    ‘post_status’ =>’published’,
    ‘post_type’ =>’post’,
    ‘orderby’ => ‘meta_value_num’,
    ‘meta_key’ => ‘_liked’,
    ‘paged’ => (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1
    ));
    ?>”
    i dont know how to use,somebody said i need page template..but i dont see any page template in my wordpress.
    so could you pls help me..tks 😀

    #968209
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    That’s just the query – you would still need to build the HTML for the posts, which would include your title, excerpt, featured images etc.. It gets complex if you aren’t familiar with the templates.

    Maybe a plugin like this might help?: https://wordpress.org/plugins/wp-show-posts/

    If so, this topic should help: https://wpshowposts.com/support/topic/sort-by-custom-field-value/#post-7803

    #968274
    Vuong

    Tks for reply..but it doesn work..but nvm..could you help me another problem ?
    here my code to get post view and show post view..
    i put it in function file,its show ok,but i cant make it to show most viewed post,even using wp-show-posts plugin..so any chance to make it possible ?
    Here my screenshots on wp-show-posts config and my database

    View post on imgur.com

    View post on imgur.com


    Sorry for disturb too much.

    function setPostViews($postID) { 
        $count_key = 'post_views_count';
        $count = get_post_meta($postID, $count_key, true);
        if($count==''){
            $count = 0;
            delete_post_meta($postID, $count_key);
            add_post_meta($postID, $count_key, '0');
        }else{
            $count++;
            update_post_meta($postID, $count_key, $count);
        }
    }
    function post_like_table_create() {
    
    global $wpdb;
    $table_name = $wpdb->prefix. "post_like_table";
    global $charset_collate;
    $charset_collate = $wpdb->get_charset_collate();
    global $db_version;
    
    if( $wpdb->get_var("SHOW TABLES LIKE '" . $table_name . "'") != $table_name)
    { $create_sql = "CREATE TABLE " . $table_name . " (
    id INT(11) NOT NULL auto_increment,
    postid INT(11) NOT NULL ,
    
    clientip VARCHAR(40) NOT NULL ,
    
    PRIMARY KEY (id))$charset_collate;";
    require_once(ABSPATH . "wp-admin/includes/upgrade.php");
    dbDelta( $create_sql );
    }
    
    //register the new table with the wpdb object
    if (!isset($wpdb->post_like_table))
    {
    $wpdb->post_like_table = $table_name;
    //add the shortcut so you can use $wpdb->stats
    $wpdb->tables[] = str_replace($wpdb->prefix, '', $table_name);
    }
    
    }
    add_action( 'init', 'post_like_table_create');
    
    #968509
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Just to confirm, you want to show the one post with the most views? I’m not really sure how you’d do that, unfortunately. I’ll think about it today – will hopefully come up with a solution.

    If I can’t come up with something, you may need to use a service like codeable.io to have it coded.

    #969031
    Vuong

    Tks..but not just 1 post,i want to show all posts,ordered by likes count descending

    #969167
    Tom
    Lead Developer
    Lead Developer

    That’s exactly what this should do: https://generatepress.com/forums/topic/page-template-2/#post-968209

    It would list out the posts, and order them by the number specified in that custom post meta.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.