Jump to content

I am trying to modify this code to show only most viewed post in 7 days instead of all time


YSGmesh

Recommended Posts

<?php query_posts('meta_key=post_views_count&posts_per_page=3&orderby=meta_value_num& order=DESC'); if (have_posts()) : while (have_posts()) : the_post(); ?> <ul class="rpul"> <li> <div class="class="post-thumb wp-post-image" style=' '> <?php if ( has_post_thumbnail() ) : ?> <?php the_post_thumbnail('thumbnail') ?> <?php endif ?> </div><div class='cat-post-text'> <h1> <a href="<?php the_permalink(); ?>"><?php the_title(); ?>

 

Link to comment
Share on other sites

First thing you should do is get a keyboard that that has return and tab keys. That will enable you to format your code into separate lines with indents so it is understandable.

When you've done that, repost your code using a code box ("<>" button in the toolbar).

If it's readable there's a chance someone might read it.

  • Like 1
Link to comment
Share on other sites

2 minutes ago, Barand said:

First thing you should do is get a keyboard that that has return and tab keys. That will enable you to format your code into separate lines with indents so it is understandable.

When you've done that, repost your code using a code box ("<>" button in the toolbar).

If it's readable there's a chance someone might read it. Thanks for the guide. let me edit

 

Link to comment
Share on other sites

<?php 
   query_posts('meta_key=post_views_count&posts_per_page=3&orderby=meta_value_num&
order=DESC');

    if (have_posts()) : while (have_posts()) : the_post();
?> 
<ul class="rpul">
    <li>    
        
            <?php endif ?> 
      
                <a href="<?php the_permalink(); ?>"><?php the_title();?>

Please I edited the code as directed. Anyone to help make this only most viewed post of 7 days? Thanks

Link to comment
Share on other sites

As ginerjm stated we don't have any insight into how the function query_posts() works or what are the valid values to use.

query_posts('meta_key=post_views_count&posts_per_page=3&orderby=meta_value_num& order=DESC');

Does that function allow for parameters based on date ranges? Does it exclude records with 0 views? Even if it does, we have no idea how those parameters are to be formatted. But, generally speaking the query might look something like this:

SELECT *, COUNT(v.id) as viewCount
FROM posts_table as p
JOIN views_table as v
  ON p.id = v.post_id
  AND v.date >= DATE(NOW()) - INTERVAL 7 DAY
ORDER BY viewCount DESC

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.