Recent Topics

1 Jul 09, 2008 03:43    

My b2evolution Version: 2.x

Is there any way of having the posts on my home page

http://www.comiclist.com

appear in a different order each time a person visits the page, within some parameter like the last day or two? I have found whatever item is first gets lots of hits, and the items underneath it get far fewer.

2 Jul 09, 2008 09:12

$timestamp_min = time() - ( 2 * 24 * 60 * 60 );
$order = 'RAND';

¥

3 Jul 09, 2008 11:24

Thank you - which file do I edit?

4 Jul 09, 2008 11:39

That'd need to go in your index.php, but it will affect all hits that come through it.

You could possibly add some checks to only show it if there's no get/post params, which might work

if( empty( $_GET ) && empty( $_POST ) )
{ // this should be a direct hit to domain.com/
$timestamp_min = time() - ( 2 * 24 * 60 * 60 );
$order = 'RAND';
}

¥

5 Jul 09, 2008 11:44

Bad Request!

The parameters of your request are invalid.

It appears to be "$order = 'RAND';" that is upsetting it.

6 Jul 09, 2008 17:42

Ok, that's weird because I'm sure I coded rand into 2.4.x :P

I guess I need to go play/test code now ;)

¥

7 Jul 10, 2008 11:13

ack, it looks like I didn't add that bit where I thought I had :-S

It looks like you need to hack the core ( inc/items/model/_itemlistlight.class.php approx 477 ), amend the last line to match this:

		/*
		 * Ordering:
		 */
		$this->filters['order'] = param( $this->param_prefix.'order', '/^(ASC|asc|DESC|desc|RAND|rand)$/', $this->default_filters['order'], true );		// ASC or DESC

Then the above solution should work

¥

8 Jul 10, 2008 11:46

Yes it does, thank you!

Now, is there any way to eliminate

"Start at: 1215510052"

from the top of the page?

9 Jul 10, 2008 11:53

Sheesh give yah an inch and you want a mile :p

You'd need to wrap the RequestTitle ( skins/skin/index.main.php or summat )

		<?php
		if( empty( $_GET ) && empty( $_POST ) )
		{
			// ------------------------- TITLE FOR THE CURRENT REQUEST -------------------------
			request_title( array(
					'title_before'=> '<h2>',
					'title_after' => '</h2>',
					'title_none'  => '',
					'glue'        => ' - ',
					'title_single_disp' => false,
					'format'      => 'htmlbody',
				) );
			// ------------------------------ END OF REQUEST TITLE -----------------------------
		}
		?>

¥

10 Jul 10, 2008 12:19

ooops, that should have been the reverse :

        <?php
        if( !empty( $_GET ) || !empty( $_POST ) )
        {
            // ------------------------- TITLE FOR THE CURRENT REQUEST -------------------------
            request_title( array(
                    'title_before'Arrow '<h2>',
                    'title_after' Arrow '</h2>',
                    'title_none'  Arrow '',
                    'glue'        Arrow ' - ',
                    'title_single_disp' Arrow false,
                    'format'      Arrow 'htmlbody',
                ) );
            // ------------------------------ END OF REQUEST TITLE -----------------------------
        }
        ?> 

I'm not seeing your date problem ( or the posts in reverse problem )

¥

*edit*
Ohhh you disappeared ... that's a good trick!

11 Jul 10, 2008 12:21

¥åßßå wrote:

I'm not seeing your date problem ( or the posts in reverse problem )

¥

That's because I stumbled across what I did wrong.

I will try the above out later when I am more awake and have more time to experiment, thank you again.

12 Jul 10, 2008 13:23

Sorry This is a machine translation. I am using b2evolution 2.4.2 "Palms". The categories are arranged alphabetically. I want to be sorted in order of entry. How can I change this?
Thanks in advance

13 Jul 10, 2008 18:20

Hi Pau,
Please don't hijack other peoples threads it's counter productive. You already have an open thread for this problem, any answers will be made there

¥

14 Jul 10, 2008 18:44

Sorry, sorry. I altered the categories

15 Jul 11, 2008 11:32

¥åßßå wrote:

Sheesh give yah an inch and you want a mile :p

You'd need to wrap the RequestTitle ( skins/skin/index.main.php or summat )
¥

When I wrap it, I get

Parse error: syntax error, unexpected '<' in /home/comlist/public_html/skins/b2evo_ru/index.main.php on line 91

16 Jul 11, 2008 16:28

Assusming line 91 is <?php just remove it and the ?> at the end of the snippet I pasted ;)

¥

17 Jul 12, 2008 03:34

¥åßßå wrote:

Assusming line 91 is <?php just remove it and the ?> at the end of the snippet I pasted ;)

¥

Parse error: syntax error, unexpected T_STRING, expecting ')' in /home/comlist/public_html/skins/b2evo_ru/index.main.php on line 96

Line 96 is

'title_before'Arrow '<h2>',

18 Jul 12, 2008 08:03

Ahhh, t'was me doing a naff copy+paste .... I knew I should have asked John for help, he's the copy+paste expert :roll:

All the "Arrow" should be =>'s

        <?php
        if( !empty( $_GET ) || !empty( $_POST ) )
        {
            // ------------------------- TITLE FOR THE CURRENT REQUEST -------------------------
            request_title( array(
                    'title_before' => '<h2>',
                    'title_after' => '</h2>',
                    'title_none'  => '',
                    'glue'        => ' - ',
                    'title_single_disp' => false,
                    'format'      => 'htmlbody',
                ) );
            // ------------------------------ END OF REQUEST TITLE -----------------------------
        }
        ?> 

¥

19 Jul 12, 2008 08:51

He's so right
This is a Copy N Paste

I may have opened the door but you entered of your own free will

20 Jul 12, 2008 14:36

I took out the "php" and it's working. The only remaining issue is, this renames my blog from ComicList to "Starting at ....". Is there any way for the name to be "ComicList" again?

21 Jul 13, 2008 07:29

Lets try this from a completely different direction. Instead of all the other changes you've made crack open your skins index.main.php and paste this just before "display_if_empty()"

	global $ReqURI;
	if( $ReqURI == '/' && empty( $_POST ) && empty( $_GET ) )
	{
		$timestamp_min = time() - ( 2 * 24 * 60 * 60 ); 
		$MainList = new ItemList2( $Blog, $timestamp_min,NULL, 5 );// change "5" to the number of posts you want
		$MainList->set_default_filters( array(
				'order' => 'RAND',
				) );
		// Run the query:
		$MainList->query();
	}

¥

22 Jul 13, 2008 13:45

Okay, here's how the PHP looks now:

<?php
            // --------------------------------- START OF POSTS -------------------------------------

    global $ReqURI;
    if( $ReqURI == '/' && empty( $_POST ) && empty( $_GET ) )
    {
        $timestamp_min = time() - ( 2 * 24 * 60 * 60 );
        $MainList = new ItemList2( $Blog, $timestamp_min,NULL, 5 );// change "5" to the number of posts you want
        $MainList->set_default_filters( array(
                'order' => 'RAND',
                ) );
        // Run the query:
        $MainList->query();
    }

            // Display message if no post:
            display_if_empty();
            while( $Item = & mainlist_get_item() )
            {	// For each blog post, do everything below up to the closing curly brace "}"

				?>


There's no error or odd result, but it also doesn't randomize the order of the posts. It seems to ignore it.

23 Jul 13, 2008 20:09

Hmmm, weird, I spent at least 30 seconds checking my code worked before I posted .... could you possibly amend it to :

   global $ReqURI;
pre_dump( $ReqURI, $_POST, $_GET );
    if( $ReqURI == '/' && empty( $_POST ) && empty( $_GET ) )
......

and copy/paste ( ask John for detailed instructions on how to copy paste, he's is the undisputed Master ) the results of the pre_dump() here ( undo the line once you've copy/pasted ... lets not annoy your visitors )

¥

24 Jul 13, 2008 20:15

Only change I can see is

string(10) "/index.php"

is displayed on my home page.

If I go to a particular post, it changes to

string(86) "/index.php/news/hero-initiative-s-ultimate-hulk-100-covers-ebay-auction-begins-july-14"

25 Jul 13, 2008 20:24

Cool, in that case change :

if( $ReqURI == '/index.php' && empty( $_POST ) && empty( $_GET ) ) 

¥

26 Jul 13, 2008 20:31

Now it's random, with only three pages worth to view (is this two days or something else?), and the code above the posts is:

string(10) "/index.php"

array(0) {
}

array(0) {
}

27 Jul 14, 2008 07:33

Yep, that's the 2 days thing. The paging won't work as expected though as each page will have it's listings generated randomly.

You can remove the pre_dump() code whenever you like ;)

¥

28 Jul 15, 2008 00:51

I have. :)

It works like a charm, though, I've noticed whichever post is the newest is still the one getting the most hits. Initially I thought this was due to people clicking on the first story on my site, but now your randomizing code indicates it's more likely due to hits from feeds and such. I'm still going to keep the randomizing code, however, just because it's so cool.

29 Jul 15, 2008 17:42

You can actually randomise your feed as well ( in a similar manner ) ... but the chances are that'd upset feed readers ;)

Of course it's cool ... sheesh ;)

¥

30 Jul 15, 2008 18:12

One thing I have noticed is, if someone accesses the "home page" via "www.comiclist.com" or "comiclist.com" as opposed to "www.comiclist.com/index.php" or "comiclist.com/index.php", the posts that display are not randomized.

31 Jul 15, 2008 18:31

Change the if( $ReqURI == '/index.php" to $ReqURI == '/index.php' || $ReqURI == '/'

¥

32 Jul 15, 2008 18:35

I left the " if( " in there and it seems to work-- is that correct?

33 Jul 15, 2008 19:52

You'd have known if you hadn't have left it in there ;)

¥

34 Jul 17, 2008 23:04

Hello!
I tried to make this, but i can't find "display_if_empty()" in evocamp skin index.main.php.
I don't know where should i insert the code, please help. Thanks!

37 Sep 08, 2008 06:45

I have implemented this on my site, and overall it works great, but it's giving some weird results. I have it setup to randomize all posts by forcing the time/date to be older than all my posts.

The weird results is this...

Let's say I am allowing 10 posts per page, but I have 11 posts. It randomizes them as desired, showing 10 random posts on the first page, and 1 on the next.

However, when I click to view page 2, it appears to try and randomize things again and displays more than the single post that I expected on page two. In fact, it seems to think are are many more pages to be displayed and re-displays some of the previous pages posts.

Is there an easy way to tell it to not randomize when someone clicks on subsequent pages? In other words, to do the randomization once, and then allow the user to navigate to the various pages and keep the same order that it setup in the beginning?

Sorry to resurrect an old topic, if this should be moved to it's own topic I hope you will let me know.

Thanks in advance.

38 Sep 08, 2008 17:33

The code I posted shouldn't have randomised posts on page 2 ( $_GET will not be empty ) ?

¥

39 Sep 08, 2008 18:39

Btw, thanks for this, other than the issue I am having, it's working great.

So I did some more troubleshooting and I have discovered some more information that may be useful.

You are right (of course), _GET is not empty and it is not randomizing things on the second page. The 'weirdness' I was seeing was because the post settings I had in my dashboard were not in sync with the ones in my randomization.

In other words, I had the randomization code setup to display 10 posts per page, but my dashboard was setup to display 3 posts per page, and display them in time order.

What was happening was that when I click the second page, the randomization code was not running (as you pointed out) and the dashboard settings were kicking in. This caused there to suddenly be many more pages and the posts appeared random to me. This explains the weird behavior.

But this only fixes part of my problem.

We are in agreement that when I click page 2, it is NOT randomizing. It is instead using the default selected settings I have in my dashboard. This results in the second page always having the very oldest post. Even if that post was already on the first page.

So basically, a user would see 10 random posts on the first page, and there would be 1 post left to display on the second page. But if they click to see that last post on the second page, they will not necessarily see the outstanding post that was left off the front page.

It appears that each time you click a page, it re-runs the code to determine which posts to display (but the logic has now changed!) instead of using the previous query and going to the next page.

Sorry this is so long, and I hope it is clear. Thanks.

40 Sep 08, 2008 19:30

Ok, without a link to your blog I can only gaze into my crystal ball and utter words that may or may not be wisdom .... a betting man would put his money on the latter and accept the crap odds :P

*if* you have (first page ) "random 10 posts" then on page 2(+) ( assuming 11 posts ), you should see posts 4 -> 6 ( assuming 3 posts per page ) ++ page links for pages 1 -> 4

All off the posts from page 2 onwards should be in date order ( newest first )

¥

41 Sep 08, 2008 21:50

You're pretty good with your crystal ball ;), that's exactly what I see.

However, herein lies the rub.

When you are looking at page 1, it says there are two pages total (10 + 1).

But when you are looking at page 2, it says there are 4 pages total (for the reasons you described).

I think you see my problem now. Different number of pages, depending on which page you are on = confusion.

Why does this happen?

Because the query to determine which posts go on which pages is run each time a page is selected. The end result is a dynamically generated list of posts to display on each page.

I'm assuming it would be a large change to have it generate the list once and keep it static as you navigate the pages in that single static generated list. ?

42 Sep 09, 2008 07:46

The reason why it happens is because you override the settings when you generate the first page then, when you hit page 2 ( onwards ) it reverts back to the blog settings of 3 per page.

You can cure it one of 2 ways :
1) Change the first page to display 3 posts
2) Change your blog settings to 10 posts per page

¥

43 Sep 09, 2008 19:36

Yes, it would seem that should fix it, and I tried this. I set my blog settings to be 10 per page to match my random settings. HOWEVER there is still the dynamic query issue I eluded to above.

To make this problem as succinct as I can... consider these question/answers:

Q: When you are looking at page 1, what do you see?
A: 10 random posts.

Q: When you are looking at page 2, what is on page 1?
A: 10 time ordered posts.

http://www.clipartof.com/images/thumbnail/1892.gif

Basically, the contents of page 1 are different depending on whether or not you are looking at it (it's like the Heisenberg uncertainty principle of blogs!).

The same thing applies to page 2. When you are looking at page 1, the contents of page 2 is a single 11th random post. When you are looking at page 2, the contents of page 2 is the oldest post (not random anymore).

This forbids someone from being able to truly navigate your posts. You think you can go to page 2 to see the post that was not on page 1, but you can't.

I'm surprised no one has noticed this yet.

Again, the reason this happens is because when you display page 1, it does a query to determine which posts should go on which pages. The query is run given the random seed, and all the pages are laid out with this information (i.e. it knows what posts to place on page 1, and how many other pages you will need to display the rest). Then when you click on page 2, it re-runs the query instead of using the previous query. Now the contents of the pages have changed.

I realize that this is likely a bit more than a one line fix that someone can just put in their main index page, but I still think it's worth pointing out for anyone who treads this path in the future.

I can see one way to fix it, and one way to do a workaround:

FIX - have it do a static one-time query. When you click on home or index.php or whatever, it runs the query 1 time only. It then knows the entire list of what posts will go on what pages. Then when you navigate to the subsequent pages it uses the already created list instead of trying to re-generate a new query that is now different in logic.

WORKAROUND - allow some sort of 'front page' where some number of random posts are displayed from the entire collection of total posts. Then the subsequent pages are a complete list of posts according to the default blog settings (like time ordered or whatever). This would result in the entire 'front page' being duplicates of the posts somewhere in the default list, but at least it would be navigatable.

Sorry for the long post. :)

I'm still not sure what I'm going to do to get around this, but I understand if my choices are to deal with it or ditch it.

(edited for clarity. Clear as mud I hope.)

44 Sep 09, 2008 20:00

kurious wrote:

Basically, the contents of page 2 are different depending on whether or not you are looking at it (it's like the Heisenberg uncertainty principle of blogs!). When you are looking at page 1, the contents of page 2 is a random post. When you are looking at page 2, the contents of page 2 is the oldest post (not random anymore).

Schrödinger has a cat that may or may not be alive .... the question is, should you feed it or save your money? ;)

kurious wrote:

Again, the reason this happens is because when you display page 1, it does a query to determine which posts should go on which pages.

Not *entirely* correct, sql picks the "limit 1,10" based on "rand" and the core counts the posts that "could" have been shown and says "hey, there's 11 ... we have a page 2" .... page 2's post are never determined until you click on the "next page" link .... and then you find out that the cat is bloody old and grey .... or it's died of malnutrition :p

kurious wrote:

FIX - have it do a static one-time query. When you click on home or index.php or whatever, it runs the query 1 time only. It then knows the entire list of what posts will go on what pages. Then when you navigate to the subsequent pages it uses the already created list instead of trying to re-generate a new query that is now different in logic.

That's *doable* ( would require that user allowed cookies so you could store the whole "post id's in this order" in the sessions table ), but it's a smidge outside the scope of what this hack was ( initially ) about .... you'd need to rebuild $MainList based on the stored array and then the "page = 2+" ... but doable.

kurious wrote:

WORKAROUND - allow some sort of 'front page' where some number of random posts are displayed from the entire collection of total posts. Then the subsequent pages are a complete list of posts according to the default blog settings (like time ordered or whatever). This would result in the entire 'front page' being duplicates of the posts somewhere in the default list, but at least it would be navigatable.

That's also doable, possibly as easily as subtracting 1 from the $page if $_GET['page'] is present ... tad late in the day for me to go play with code and see if that's fubar'd though :P

¥

*edit*
Now I'm not sure if you were talking about cats or not! :p

The above is in reply to what may have been there before I opened the box :p

45 Sep 09, 2008 20:19

¥åßßå wrote:

Now I'm not sure if you were talking about cats or not! :p

The above is in reply to what may have been there before I opened the box :p

Yes, your dead cat does pertain to my Copenhagen interpretation, but at least we both agree the issue exists, if not where it exists.

If you do find yourself concocting a solution to this, I do hope you will let me know.

Thanks again.

46 Sep 16, 2008 02:44

For those who might follow this path in the future, here's how I fixed the issues I was having. I made it so that my main 'home' page is a random selection of 7 posts from my full collection, and then I put a link at the bottom that will take you to the entire ordered listing of posts on a page per page basis. It wasn't too difficult. (You could also do something similar if you wanted to have a welcome post always show up on your front page, it would work for that too).

Near the start of your main post area in index.main.php, you have something like:

if( $ReqURI == '/index.php' || $ReqURI == '/' || $ReqURI == '/home.php' && empty( $_POST ) && empty( $_GET ) )
{
  $timestamp_min = 1; 
  $MainList = new ItemList2( $Blog, $timestamp_min, NULL, 7 );// last arg = number of posts you want per page)
  $MainList->set_default_filters( array(
         'order' => 'RAND',                                     
) );
  // Run the query:
  $MainList->query();
}

(Note that you won't have this line if you're not using the randomization i.e. you are creating a welcome post only. If you are doing this, you will need to add this IF statement and put a link to your welcome post if it is met.)

This says that if you access the page via the address directly or through the home link it will show the randomized posts, all on one page. The important part here is that this randomization if statement does NOT catch the case where you select page 1 from the page navigation.

At the bottom of your home page, you will see the page navigation links that allow you to navigate to various pages. Locate the code for these links in your index.main.php. It looks like:

mainlist_page_links( array(
                                     'block_start'              =>      '<p class="center">',
                                     'block_end'                =>      '</p>',
                                     'prev_text'                =>      '&lt;&lt;',
                                     'next_text'                =>      '&gt;&gt;',
                                     ) );

Replace this with something like:

if( $ReqURI == '/index.php' || $ReqURI == '/' || $ReqURI == '/home.php' && empty( $_POST ) && empty( $_GET ) ) {
          echo '<p class="center"><a href="http://yourwebsite.com/?blog=4">SEE ALL POSTS &gt;&gt></a></p>';
        } else {
          mainlist_page_links( array(
                                     'block_start'              =>      '<p class="center">',
                                     'block_end'                =>      '</p>',
                                     'prev_text'                =>      '&lt;&lt;',
                                     'next_text'                =>      '&gt;&gt;',
                                     ) );
        }

This tells it to put a link at the bottom that will direct you to the first non-random page (you may likely use something other than blog=4 for your blog) if you are viewing the randomized 'home' page. If you are not viewing the randomized home page, it will display the old page navigations and you will see all your posts with the settings from your dashboard as far as the ordering and the number of posts per page.

The great thing about this is now the number of posts on your randomized page, and the number of posts on your other default pages does not need to match. This is how you can use this method to create a welcome page with little effort. Then underneath the welcome post you just put a link that takes you to page 1 of your full post collection.

That's all.

**Edited for clarity, and it's still probably not that clear.

47 Aug 14, 2009 12:36

Should this randomization work in 3.3.1? I ask because I duplicated my blog so I could test out the upgrade, and it isn't working on the test blog.

48 Aug 21, 2009 04:23

Okay, I now see 3.31 can show "random order!". But, is there any way to specify the number of posts (3) AND the number of days (2) at the same time?


Form is loading...