Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load the latest posts with score above 100?

SITUATION:

I currently load the latest posts chronologically with this code:


CODE:

        $scope.data = [];
        var _n = Math.ceil(($(window).height() - 50) / (350)) + 1;
        var _start = <%= lastID %>;
        var firstElementsLoaded = false;

        $scope.getDataset = function() {

            fb.orderByChild('id').startAt(_start).limitToFirst(_n).on("child_added", function(dataSnapshot) {

                _start = dataSnapshot.child("id").val() + 1;
                console.log("LAST TRUE ID:"+ _start);

                $scope.data.push(dataSnapshot.val());
                $scope.$apply()
                console.log("THE VALUE:"+$scope.data);

                firstElementsLoaded = true;
            });
        };


        $scope.getDataset();

QUESTION:

How should I modify it to essentially have the exact same behaviour but to only query posts with scores above 100 according to their chronological order ?


UPDATE:

I have finally found a way to use the "create another index" method with my architecture. But one hurdle remains:

How to copy a childNode from one node to another?

like image 802
Coder1000 Avatar asked Dec 29 '16 19:12

Coder1000


People also ask

What is a good SEO score out of 100?

A good SEO score is between 80 – 100. SEO scores in this range indicate that your website is meeting the top quality standards for search engine optimization in the areas of technical SEO, content, user experience, and mobile usability.

How many posts can I display in a post block?

By default, the block shows 5 posts, but you can display anywhere between 1 and 100 posts. You also have the option to display your recent posts in a column grid rather than a list. You can customize the grid to featured images for your posts, resize the image, and align them accordingly:

How do I get the latest post on my website?

Use WordPress’s Latest Posts Gutenberg Block The WordPress block (Gutenberg) editor has a built-in block for displaying your latest posts. You can easily add this to any of the posts or pages on your site. To use this block, simply edit the post where you to display recent posts.

How do I add the ‘latest posts’ block?

You can easily add this to any of the posts or pages on your site. To use this block, simply edit the post where you to display recent posts. On the post edit screen, you need to add the ‘Latest Posts’ block to the content area. There are lots of different ways you can configure this block.

How do I load posts automatically from the bottom of page?

You can also load the rest of the posts automatically on scroll instead of having to click on a button. This can be achieved by making it invisible by setting the visibility to hidden. The following code will run the load_posts () function when you’re 100px from the bottom of the page.


Video Answer


1 Answers

I rethought my architecture and created a specific index for top posts:

if (funPost.score >= global.hotNumber && funPost.hot == false) {
            var hotPostRef = firebase.database().ref("hot/section/"+key);
            var hotPost = {
                title: funPost.title,
                image: funPost.image,
                id: funPost.id,
                key: funPost.key
            }
            hotPostRef.set(hotPost);
            funPostRef.update({"hot": true});
        }
   else if (funPost.score <= (global.hotNumber - 25) && funPost.hot == true) {
        var hotPostRef = firebase.database().ref("hot/section/"+key);
        hotPostRef.remove();
        funPostRef.update({"hot": false});
   }
like image 124
Coder1000 Avatar answered Oct 06 '22 23:10

Coder1000