Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Turn <p class="date"> i into a <li> tag  (Read 1723 times)

Hoel

  • Guest
Turn <p class="date"> i into a <li> tag
« on: November 10, 2007, 04:22:46 pm »

Hi

I'm using a moddified version of N33 template "terrafirma"

Under each post i have a <ul> that contains two different <li> classes:
 
    * Comments
    * Read more

The code looks like this:

<div class="post">
            
               
            <div class="content">
               <?php center(); ?>
     </div>         
            <div class="footer">
               <ul>
                  
                  <li class="comments"><a href="#">Comments (18)</a></li>
                  <li class="readmore"><a href="#">Read more</a></li>
               </ul>
            </div>
         </div>


Is there any way to turn the default <p class="date"> into a li class ? currently the comments are floating around at the top of the page....

You can find the site here: Nerdy.se
 
Thank You!
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Turn <p class="date"> i into a <li> tag
« Reply #1 on: November 10, 2007, 05:04:47 pm »

Tjena Hoel (I'm assuming you understand Swedish, given that you have an .se domain)

Backup first, this is highly untested!

In snews.php, find this part (starts at ~ line 258)
Quote
$tags = array(); $tags['infoline'] = '<p class="date">,'.l('filed_in').' ,category_name,&nbsp;,date, '.l('divider').' ,comments, ,readmore,edit,</p>';

And change it to something like this:
Quote
$tags = array(); $tags['infoline'] = '<ul>,<li class="anything">,comments,</li>,<li class="anything">,readmore,</li>,<li class="admin_anything">,edit,</li>,</ul>';

Obviously you can name the li classes in the tags array anything you like.

Then, in function center(), around line 530, find this block:
Quote
if (!empty($currentPage)) {
if ($infoline == true) {
$tag = explode(',', tags('infoline'));
foreach ($tag as $tag) {
switch (true) {
case ($tag == 'date'): echo $a_date_format; break;
case ($tag == 'category_name'): echo $link.$category.'/" title="'.$category.'">'.$cat_name.'</a> '; break;
case ($tag == 'readmore' && strlen($r['text']) > $shorten):
echo $link.$category.'/'.$r['seftitle'].'/" title="'.l('read_more').'">'.l('read_more').'</a> '; break;
case ($tag == 'comments' && ($commentable == 'YES' || $commentable == 'FREEZ')):
echo $link.$category.'/'.$r['seftitle'].'/#'.l('comment').'1" title="'.l('comments').'">'.l('comments').' ('.$comments_num.')</a> '; break;
case ($tag == 'edit' && $_SESSION[db('website').'Logged_In'] == token()): echo ' '.$edit_link; break;
case ($tag != 'readmore' && $tag != 'comments' && $tag != 'edit'): echo $tag; break;
}

Comment out the cases you don't need, e.g
Quote
if (!empty($currentPage)) {
if ($infoline == true) {
$tag = explode(',', tags('infoline'));
foreach ($tag as $tag) {
switch (true) {
//case ($tag == 'date'): echo $a_date_format; break;
//case ($tag == 'category_name'): echo $link.$category.'/" title="'.$category.'">'.$cat_name.'</a> '; break;
case ($tag == 'readmore' && strlen($r['text']) > $shorten):
echo $link.$category.'/'.$r['seftitle'].'/" title="'.l('read_more').'">'.l('read_more').'</a> '; break;
case ($tag == 'comments' && ($commentable == 'YES' || $commentable == 'FREEZ')):
echo $link.$category.'/'.$r['seftitle'].'/#'.l('comment').'1" title="'.l('comments').'">'.l('comments').' ('.$comments_num.')</a> '; break;
case ($tag == 'edit' && $_SESSION[db('website').'Logged_In'] == token()): echo ' '.$edit_link; break;
case ($tag != 'readmore' && $tag != 'comments' && $tag != 'edit'): echo $tag; break;
}

Then repeat the procedure for the next infoline block, a few lines below:
Quote
if ($infoline == true) {
$tag = explode(',', tags('infoline'));
foreach ($tag as $tag ) {
switch ($tag) {
//case 'date': echo $a_date_format; break;
//case ($tag == 'category_name'): echo $link.$category.'/" title="'.$category.'">'.$cat_name.'</a> '; break;
case 'readmore':
case 'comments': ; break;
case 'edit': if ($_SESSION[db('website').'Logged_In'] == token()) {echo ' '.$edit_link;} break;
default: echo $tag;

I'll repeat: this is highly untested, so proceed with caution. But it could work.
Logged

Hoel

  • Guest
Re: Turn <p class="date"> i into a <li> tag
« Reply #2 on: November 10, 2007, 06:42:12 pm »

Tackar ödmjukast!

It works, i would like to separate the comments and readmore link with a div tag

Now the code looks like this:

<div class="content">
               <h2>   title  </h2>

The post text goes here

<ul>
<li class="comments">Comments (0) </li>
<li class="readmore"></li><li class="admin_anything"></li>
</ul>    

</div>         


Its a big improvment, but i would like the code to look like this:

            
               
            <div class="content">
               <h2>title</h2>
The text goes here

     </div>         
            <div class="footer">
               <ul>
                  

               <li class="comments"><a href="#">Comments (0)</a></li>
               <li class="readmore"><a href="#">Read more</a></li>
                                         <li class="admin_anything"></li>
               </ul>
            </div>

Thank You!
         </div>
      
       
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Turn <p class="date"> i into a <li> tag
« Reply #3 on: November 10, 2007, 08:04:10 pm »

Oki-doki. You'll need to hack snews.php some more to get that result. I think, something like this might work.

First: We'll leave <div class="content"> as it is in index.php, it'll serve as a wrapper for the whole center() function.
Second, in snews.php, around line 523, find this block:
Quote
if ($r['displaytitle'] == 'YES') {echo '<h2>'.(strlen($text) > $shorten ? $link.$category.'/'.$r['seftitle'].'/" title="'.$title.'">'.$title.'</a>' : $title).'</h2>';}
file_include(str_replace('[break]', '', $text), $shorten);

Change it to this:
Quote
if ($r['displaytitle'] == 'YES') {
echo '<div class="article">'; //new stuff. old stuff follows below.
echo '<h2>'.(strlen($text) > $shorten ? $link.$category.'/'.$r['seftitle'].'/" title="'.$title.'">'.$title.'</a>' : $title).'</h2>';}
file_include(str_replace('[break]', '', $text), $shorten);
echo '</div>'; //more new stuff

That gives you:
<div class="content">
  <div class="article">
    <h2>Article Title</h2>
    Artcle here in short or long form
  </div>

---

Next bit is to add the "footer" div. On line 527 (around there anyway), find this block:
Quote
if (!empty($currentPage)) {
if ($infoline == true) {

Now add echo '<div class="footer">'; after the brace following $currentPage)), but before if ($infoline...

Then on line 542, after
Quote
else if ($_SESSION[db('website').'Logged_In'] == token()) {echo '<p>'.$edit_link.'</p>';}
make a new line and input echo '</div>';

And then again on line 558, after the closing brace, make a new line and input echo '</div>';

The whole thing should be something like this:
Quote
$commentable = $r['commentable'];
$edit_link = $link.'index.php?action=admin_article&amp;id='.$r['id'].'" title="'.l('edit').' '.$title.'">'.l('edit').'</a>';
if (!empty($currentPage)) {
echo 'div class="footer">';
if ($infoline == true) {
$tag = explode(',', tags('infoline'));
foreach ($tag as $tag) {
switch (true) {
//case ($tag == 'date'): echo $a_date_format; break;
//case ($tag == 'readmore' && strlen($r['text']) > $shorten):
//echo $link.$category.'/'.$r['seftitle'].'/" title="'.l('read_more').'">'.l('read_more').'</a> '; break;
case ($tag == 'comments' && ($commentable == 'YES' || $commentable == 'FREEZ')):
echo $link.$category.'/'.$r['seftitle'].'/#'.l('comment').'1" title="'.l('comments').'">'.l('comments').' ('.$comments_num.')</a> '; break;
case ($tag == 'edit' && $_SESSION[db('website').'Logged_In'] == token()): echo ' '.$edit_link; break;
case ($tag != 'readmore' && $tag != 'comments' && $tag != 'edit'): echo $tag; break;
}
}
}
else if ($_SESSION[db('website').'Logged_In'] == token()) {echo '<p>'.$edit_link.'</p>';}
echo '</div>';
}
else if (substr($position, 0, 1) != '2' && empty($currentPage)) {
if ($infoline == true) {
$tag = explode(',', tags('infoline'));
foreach ($tag as $tag ) {
switch ($tag) {
//case 'date': echo $a_date_format; break;
case 'readmore':
case 'comments': ; break;
case 'edit': if ($_SESSION[db('website').'Logged_In'] == token()) {echo ' '.$edit_link;} break;
default: echo $tag;
}
}
}
else if ($_SESSION[db('website').'Logged_In'] == token()) {echo '<p>'.$edit_link.'</p>';}
}
echo '</div>';
}

Note: I'm not exactly sure if the final echo '</div>' should go on line 558 or line 559, you'll have to try it out.
It should output the whole article-comments block as:
<div class="article">
   <h2>Title</h2>
   Article thing here
</div>
<div class="footer">
<ul><li>comments</li>..etc..</ul>
</div>

And, again, this is not tested. Proceed with caution and make a backup of your snews.php before doing changes. Always.
« Last Edit: November 10, 2007, 08:07:54 pm by Fred K (agentsmith) »
Logged