Recent Topics

put date in front of post name

Started by on Feb 21, 2005 – Contents updated: Feb 21, 2005

Feb 21, 2005 19:41    

my archives are made by post, so every post appears in the archive page. Is it possible to put the date in front of the post name?

Feb 22, 2005 05:34

Yes, but it's also gonna show up in your sidebar (unless you use CSS to hide it).

What you need to modify is your _archives.php file. It will be in one (or possibly two locations). 1st - check the /skins/[whatever skin your using] folder. There will be an archives.php file there, but it may only call the file in the /skins/ folder.

What I'd recommend doing would be to copy the "guts" of the archives.php file in the /skins/ folder, INTO the archives.php file that's in your /skins/[whatever skin you're using] folder. (That way, whatever changes you make will only affect that skin).

In any case, inside the ARchives.php file you'll find "// --- post by post archives ---- " comment. Below that is what you'll want to change.

Look for

echo '<a href="';
permalink_link( '', 'id', $post_ID );
echo '">';

This is where the PHP builds the post-by-post archive links for the archive list. What you'll want to do is COPY the Daily (date) construction

archive_link( $arc_year, $arc_month, $arc_dayofmonth );

and INSERT it, so it now looks like:

echo '<a href="';
archive_link( $arc_year, $arc_month, $arc_dayofmonth );
permalink_link( '', 'id', $post_ID );

I haven't tried it, but it should work. You might want to play around with the date order to your liking, but I believe this should yield the effect you're looking for. :)

Cheers,
Scott

PS: IF you only want the date to show up on the archive LIST, but not the sidebar list, change the code to:

echo '<a class="hide" href="';
archive_link( $arc_year, $arc_month, $arc_dayofmonth );
echo '"> <a href="';
permalink_link( '', 'id', $post_ID );

This puts the date in it's own <a> tag, with the classname "hide". Then, in your CSS, you will need to add a selector that looks LIKE (won't be exact, because I don't know what you've got in your sidebar) ...

div.sidebar a.hide {display:none}

(If you just put a.hide {display:none}, then BOTH will disappear. You NEED to specify the 'hide' in the sidebar and NOT the one in 'bPosts'.

But, I'm getting ahead of myself. You might want to SHOW both?! ;)

Feb 22, 2005 13:04

thank you for your help. Unfortunately, nothing happened. I tried it all, but nothing. too bad, ah well, maybe it's not that important after all.

Feb 23, 2005 03:20

Doh! My BAD. :oops:

I had you copy & paste the wrong part (the <a hreg=""> part).

What you WANT is the part AFTER the <a href="">.

HERE ... (I swear it'll do it for you). :p

Change:

				// --------------------------------- MONTHLY ARCHIVES ---------------------------------------
				echo 'howdy <a href="';
				archive_link( $arc_year, $arc_month );
				echo '">';
				echo T_($month[zeroise($arc_month,2)]),' ',$arc_year;
				echo '</a> <span class="dimmed" title=" Number of Entries during the Month ">('.$arc_count.')</span>';
				break;

to:

				// --------------------------------- MONTHLY ARCHIVES ---------------------------------------
				echo 'howdy <a href="';
				archive_link( $arc_year, $arc_month );
				echo '">';
echo mysql2date($archive_day_date_format, $arc_year.'-'.zeroise($arc_month,2).'-'.zeroise($arc_dayofmonth,2).' 00:00:00  ');

				echo T_($month[zeroise($arc_month,2)]),' ',$arc_year;
				echo '</a> <span class="dimmed" title=" Number of Entries during the Month ">('.$arc_count.')</span>';
				break;
	

(assuming that you're currently using "MONTHLY" as your archive choice.)[/code]

I tested it ... it works. :)

Don't forget about hiding it in the sidebar, if that's what you want to do (still applies). In that case ... echo a <span class="blah"> in front and a an echo </span> at the back, then control it in the CSS.

Feb 23, 2005 13:25

yeah it worked, but everything I posted now has the same date: 01-01-70

this cannot be right, can it?

Feb 23, 2005 15:58

Hmmm. You're right (I didn't look close enough). I am embarrassing myself. :oops:

OKAY ... I tested this EXTENSIVELY this morning and have come to the conclusion that what you want to do isn't as easy as originally thought.

Here's why.

In the _archives.php file, the sticky point is the 'ArchiveList()' function, which looks like:

$ArchiveList = & new ArchiveList( $blog, $Settings->get('archive_mode'), $show_statuses, $timestamp_min, $timestamp_max, $archive_limit );

Looking at the line immediately below it, I (incorrectly) assumed that all these variables

while( $ArchiveList->get_item( $arc_year, $arc_month, $arc_dayofmonth, $arc_w, $arc_count, $post_ID, $post_title) )

would be available for use. WRONG.

The ArchiveList() function only pulls SOME of the variables, depending on the 'archive_mode'. No matter how you slice it, you can have only ONE archive mode (and you're really wanting to merge information from TWO archive modes).

Don't despair. I've got the solution, BUT it's not as simple as just changing the _archives.php file for your one skin. No sirree, you're going to have to HACK a core file. (Which means that you're customizing the very guts of b2evo ... when you do an upgrade, you'll have to be careful, or you'll lose these custom changes).

Ready?

We've got to change the way ArchiveList() works, which is done in the /b2evocore folder, in the _class_archivelist.php file.

We need to change two things: (1) the SQL query from:


				// ----------------------------- POSY BY POST ARCHIVES --------------------------------
				$this->request = 'SELECT DISTINCT ID, post_issue_date, post_title
													FROM (T_posts INNER JOIN T_postcats ON ID = postcat_post_ID)
																INNER JOIN T_categories ON postcat_cat_ID = cat_ID
													'.$where.'
													ORDER BY post_issue_date DESC
													'.$limit;

To this:

				// ----------------------------- POSY BY POST ARCHIVES -------------------------------- 
				$this->request = 'SELECT DISTINCT ID, post_issue_date, post_title, YEAR(post_issue_date) AS year, MONTH(post_issue_date) AS month,
																	DAYOFMONTH(post_issue_date) AS day

													FROM (T_posts INNER JOIN T_postcats ON ID = postcat_post_ID)
																INNER JOIN T_categories ON postcat_cat_ID = cat_ID
													'.$where.'
													ORDER BY post_issue_date DESC
													'.$limit;

(2) The variable statements a bit further down from:

			case 'postbypost':
			default:
				$post_ID = $arc_row['ID'];
				$post_title = $arc_row['post_title'];
				return true;

To this:

			default:
				$post_ID = $arc_row['ID'];
				$post_title = $arc_row['post_title'];
 				$arc_year = $arc_row['year'];
 				$arc_month = $arc_row['month'];
 				$arc_dayofmonth = $arc_row['day'];
				return true;

Hopefully, you haven't changed your _archives.php file back, because if you did, you need to go back and make sure that it looks like I suggested last time:

				// ------------------------------ POSY BY POST ARCHIVES --------------------------------
				echo '<a href="';
				permalink_link( '', 'id', $post_ID );
				echo '">';
				if ($post_title) {
				echo mysql2date($archive_day_date_format, $arc_year.'-'.zeroise($arc_month,2).'-'.zeroise($arc_dayofmonth,2).' 00:00:00 '); echo '&nbsp;';

                              echo strip_tags($post_title);
				} else {
					echo $post_ID;
				}
				echo '</a>';

NOW ... the postbypost case has access to BOTH the [daily] & [postbypost] variables.

Whew! There you go. :D

Sorry I didn't get it the first time ... but there's ALWAYS a way. ;)

Feb 24, 2005 00:22

wow, it worked like a charm. Thank you very much, i didn't know it would be so difficult. now you can look at the beautiful result on www.kannibaal.be.

Feb 24, 2005 12:53

wow man, seemed like a nice trip from mexico to canada, hope to do it myself soon, although i've been to canada twice and loved it.

but the zoom thing is very interesting, just have to figure out if i really need it, it might be cool for some pics. Thanks. The one problem is that it pushes the text down! There isn't a possibility that the pictures slides over the text, instead of pushing the text down?

Feb 24, 2005 13:40

and maybe I can ask you one last thing about my archive. The archive list now is composed of the date and the post title, which is perfect. But the date is clickable, and I only want the post title to be clickable. I tried to fix this myself, but my b2 knowlegde is very small. Maybe you have a suggestion. And yes I know, I'm quite demanding.

Feb 24, 2005 15:43

Yes, our 5-month wilderness journey was quite the adventure!

I have fiddled with the zoom, so it behaves as you suggest (lots of folks want the picture over the text, with the text in a fixed position). This creates problems and I have yet to find a satisfactory solution. (Doesn't mean one doesn't exist ... just haven't found it yet! ;) )

The clickable date thing should be no problem. Try changing:

            // ------------------------------ POSY BY POST ARCHIVES --------------------------------
            echo '<a href="';
            permalink_link( '', 'id', $post_ID );
            echo '">';
            if ($post_title) {
            echo mysql2date($archive_day_date_format, $arc_year.'-'.zeroise($arc_month,2).'-'.zeroise($arc_dayofmonth,2).' 00:00:00 '); echo '&nbsp;';

                              echo strip_tags($post_title);
            } else {
               echo $post_ID;
            }
            echo '</a>';  

by pulling the date out of the <a> tag. I think this should work (not tested):

            // ------------------------------ POSY BY POST ARCHIVES --------------------------------
	echo mysql2date($archive_day_date_format, $arc_year.'-'.zeroise($arc_month,2).'-'.zeroise($arc_dayofmonth,2).' 00:00:00 '); 
	echo '&nbsp;';            
	echo '<a href="';
            permalink_link( '', 'id', $post_ID );
            echo '">';
            if ($post_title) { 
                             	echo strip_tags($post_title);
            } else {
               		echo $post_ID;
            }
            echo '</a>';  

You may be new to b2 and not know all of the ins-and-outs, but you sure can design a very nice-looking site. One of the best I've seen. Elegant, simple, clean. I'm serious, that's a great design. :D

Feb 24, 2005 15:56

worked like a charm. thanks man. You're a life saver. Wish I could treat you to a nice belgian beer, but canada might be too far to send one.

Feb 24, 2005 17:21

It's the thought that counts! THanks. :D


Form is loading...

Build your own site! – This forum is powered by b2evolution CMS, a complete engine for your website.