Home N-13 News Forums Help Search
RegisterForgot password?
How to add image to post necklacesdiscou
Known bugs - 4.0.3 necklacesdiscou

Latest N-13 News 4.0.3

What is N-13 News?
Where can I get help?
Known bugs

Forums Help & Support Friendly URL alternative for title in the meta tags
Groefie
Posted on 05 Jul 2010, 22:16:45

Access: Member
Total Posts: 13
Joined: 2010-06-28

Hi Chris,

what's the friendly URL alternative for

<?php
if(!$_GET['id']){
// not viewing a single article, show normal title/description
echo '<title>Example.com - Home</title>';
}else{
// viewing a single article, show the title/description for it
require_once('news/db.php');
require_once('news/config.php');
$data = DataAccess::fetch(sprintf("SELECT title FROM %s WHERE id = ?", NEWS_ARTICLES), $_GET['id']);
$title = $data['0']['title'];
echo sprintf('<title>Example.com - %s</title>', strip_tags($title), PHP_EOL);
}
?>

I tried with

<?php
if($url['0']){
// not viewing a single article, show normal title/description
echo '<title>Example.com - Home</title>';
}else{
// viewing a single article, show the title/description for it
require_once('./content/db.php');
require_once('./content/config.php');
$data = DataAccess::fetch(sprintf("SELECT title FROM %s WHERE id = ?", NEWS_ARTICLES), $url['0']);
$title = $data['0']['title'];
echo sprintf('<title>Example.com - %s</title>', strip_tags($title), PHP_EOL);
}
?>

but then only the 'else'-part works, not the 'if'-part. When using if(!$url['0']){ it doesn't work at all.
#2620
Chris
Posted on 05 Jul 2010, 22:19:42

Access: Admin
Total Posts: 1395
Joined: 2006-05-19

Try this

Code:

<?php
require_once('./content/db.php');
require_once(
'./content/config.php');
if(
$url['0']){
    
// not viewing a single article, show normal title/description
    
echo '<title>Example.com - Home</title>';
}else{
    
// viewing a single article, show the title/description for it
    
$data = DataAccess::fetch(sprintf("SELECT title FROM %s WHERE id = ?", NEWS_ARTICLES), $url['0']);
    
$title = $data['0']['title'];
    echo 
sprintf('<title>Example.com - %s</title>', strip_tags($title), PHP_EOL);
}
?>


The $url array gets created by news/config.php, so you need to require those files first.
#2621
Groefie
Posted on 05 Jul 2010, 22:43:34

Access: Member
Total Posts: 13
Joined: 2010-06-28

Hi Chris,

I'm sorry, but even with

<?php
require_once('./content/db.php');
require_once('./content/config.php');
if(!$url['0']){
// not viewing a single article, show normal title/description
echo '<title>Example.com - Home</title>';
}else{
// viewing a single article, show the title/description for it
$data = DataAccess::fetch(sprintf("SELECT title FROM %s WHERE id = ?", NEWS_ARTICLES), $url['0']);
$title = $data['0']['title'];
echo sprintf('<title>Example.com - %s</title>', strip_tags($title), PHP_EOL);
}
?>

it only works on pages with an id. On the homepage for example it still says only 'Example.com -' instead of 'Example.com - Home', so the if-part doesn't work, it always outputs the else-part.
#2622
Chris
Posted on 05 Jul 2010, 23:20:28

Access: Admin
Total Posts: 1395
Joined: 2006-05-19

This should hopefully work

Code:
<?php
require_once('news/db.php');
require_once(
'news/config.php');
if(!
$url['0']){
    
// not viewing a single article, show normal title/description
    
echo '<title>Example.com - Home</title>';
}else{
    if(
is_numeric($url['0'])){
        
// viewing a single article, show the title/description for it
        
$data = DataAccess::fetch(sprintf("SELECT title FROM %s WHERE id = ?", NEWS_ARTICLES), $url['0']);
        
$title = $data['0']['title'];
        echo 
sprintf('<title>Example.com - %s</title>', strip_tags($title), PHP_EOL);
    }else{
        echo 
'<title>Example.com - Home</title>';
    }
}
?>
#2623
Groefie
Posted on 05 Jul 2010, 23:32:32

Access: Member
Total Posts: 13
Joined: 2010-06-28

Hi Chris,

it works like a charm now! :grin:

Thanks!
#2624
Network-13.com © 2013