PhpDig.net

Go Back   PhpDig.net > PhpDig Forums > How-to Forum

Reply
 
Thread Tools
Old 02-25-2005, 02:19 PM   #1
mdavila
Green Mole
 
Join Date: Feb 2005
Posts: 11
Question Display first H2 tag as title instead of page title

We have thousands of pages in our site and most of the pages within a section share the same page title, so the search results can look confusing since all the titles on the results page have the same text. Is it possible to get phpdig to display the text in between the h2 tags on the page? since that is a better reflection of the title of the page?

Thanks,
-Marc
mdavila is offline   Reply With Quote
Old 02-26-2005, 09:37 PM   #2
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
Look for the phpdigCleanHtml function in the robot_functions.php file, and in the if-else "//extract title" code snippet, try replacing title with h2 and see if that works.
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 02-27-2005, 07:04 PM   #3
mdavila
Green Mole
 
Join Date: Feb 2005
Posts: 11
Such as this?

//extracts title
if (preg_match('/< *h2 *>(.*?)< *\/ *h2 *>/is',$text,$regs)) {
$title = trim($regs[1]);
}
else {
$title = "";
}
mdavila is offline   Reply With Quote
Old 02-27-2005, 07:29 PM   #4
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
Yes, try that and see if it sets the title to be the content between the h2 tags. BTW, how many h2 tags are there per page? The preg_match will look for the first h2 to match.
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 02-27-2005, 07:30 PM   #5
mdavila
Green Mole
 
Join Date: Feb 2005
Posts: 11
there are more than 1. I tried it but it picks up the first one, so it works but shows the content for the wrong H2. Is it possible to choose which H2 it picks up?
mdavila is offline   Reply With Quote
Old 02-27-2005, 07:48 PM   #6
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
Yep, preg_match matches on the first h2 tag. Try the following instead:
Code:
//extracts title
if (preg_match_all('/< *h2 *>(.*?)< *\/ *h2 *>/is',$text,$regs,PREG_SET_ORDER)) {
    $title = trim($regs[X][1]); // set X to a number
}
else {
    $title = "";
}
Where X in the above code indicates the h2 tag to match: $regs[0][1] means to match the first h2 tag, $regs[1][1] means to match the second h2 tag, $regs[2][1] means to match the third h2 tag, and so on.

You could also do something like the following:
Code:
    // assumes there are at least three h2 tags
    $title = trim($regs[0][1]." ".$regs[1][1]." ".$regs[2][1]);
A thing to remember is that whatever you set X to, that will be used across all pages, so there needs to be at least X+1 h2 tags in all pages.
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplications of Title and Meta Tag Info mokele Troubleshooting 1 03-24-2006 12:15 PM
title tag worldwealth How-to Forum 1 12-13-2005 05:19 PM
Manually set title for spidered page bvr How-to Forum 3 11-22-2005 01:45 PM
Page Title not shown in Result?? stefanw Troubleshooting 5 05-05-2004 12:31 AM
Can I limit the page title length, that gets saved? Wayne McBryde How-to Forum 1 01-11-2004 02:19 PM


All times are GMT -8. The time now is 08:09 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.