Custom Title Tages for Albums/Categories? Custom Title Tages for Albums/Categories?
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Custom Title Tages for Albums/Categories?

Started by Walkinman, January 28, 2013, 04:47:12 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Walkinman

Hey Folks,

A couple of years ago I had some work done on my cpg code to allow me to write a custom Title tag and meta description tags for Albums and Categories. It worked fine, but during the last upgrade, that code got lost, and now my cpg pages simply write the default title tag form the album/catgeory name.

I have looked at the code from the old albmgr.php file and the newer one, but I don't know php, so I have no idea how to install it. Is this pretty straightforward? I can upload a txt file of both files if it helps.

Thanks so much.

Cheers

Carl

PS: the person who did the original work doesn't seem to be around anymore.

Walkinman

Update:

I edited these files thumbnails.php, edit_one_pic.php, index.php, db_input.php, modifyalb.php, catmgr.php, displayimage.php and editpics.php, as well as as added a fix.php file that seems to have worked correctly.

I'll mark it solved in a day or 2 when I make sure everything is working correctly.

Cheers

Carl

Αndré

I guess you will share your code for interested users?

Walkinman

Hey André

I'll try ... though I'll probably mess it up. I didn't write the code myself .. someone else did, and I just tried to hack it from the old files they modified, and integrate it into the new ones. So, OK .. here goes nothing;

index.php:

   lines 1127 -> 1140
       get_cat_list($breadcrumb, $cat_data, $statistics);

    if ($cat > 0)
    {
          $result = cpg_db_query("SELECT page_title, meta_description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '{$cat}'");
        if (mysql_num_rows($result) > 0)
        {
            $rowX             = cpg_db_fetch_row($result);
            $page_title       = $rowX['page_title'];
            $meta_description = $rowX['meta_description'];
            $BREADCRUMB_TEXT  = $page_title ? $page_title : $BREADCRUMB_TEXT;
            $addition_meta    = "<meta name=\"description\" content=\"".addslashes($meta_description)."\" />"."\n";
        }
    }


thumbnails.php

   lines 104
          $result = cpg_db_query("SELECT category, title, aid, keyword, description, alb_password_hint, page_title, meta_description FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = $album");

   line 141 - 142
       if ($cat < 0) {
        $result = cpg_db_query("SELECT category, title, aid, keyword, description, alb_password_hint, page_title, meta_description FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = " . (- $cat));


   line 209 - 219
      // after that add
$meta_description = $CURRENT_ALBUM_DATA['meta_description'] ? $CURRENT_ALBUM_DATA['meta_description'] : $CURRENT_ALBUM_DATA['description'];
if ($meta_description)
{
    $meta_keywords .= '<meta name="description" content="' . htmlspecialchars($meta_description) . '" />' . $LINEBREAK;
}

$section = $CURRENT_ALBUM_DATA['page_title'] ? $CURRENT_ALBUM_DATA['page_title'] : $section;


fix.php
      <?php
define('IN_COPPERMINE'TRUE);
include 'include/init.inc.php';
cpg_db_query("
    ALTER TABLE `
{$CONFIG['TABLE_CATEGORIES']}`
    ADD `page_title` TEXT NOT NULL ,
    ADD `meta_description` TEXT NOT NULL
    "
);

?>


editpics.php

   line 151 - 152
          array($icon_array['title'] . 'Page Title', 'page_title', 0, 255),
    array($icon_array['description'] . $captionLabel, 'caption', 2, $CONFIG['max_img_desc_length']),


   line 224
          $page_title       = get_post_var('page_title', $pid);

   line 27
               $update .= ", page_title = '$page_title'";

edit_one_pic.php

   line 78

          $page_title = cpgSanitizeUserTextInput($superCage->post->getEscaped('page_title'));
   line 119
          $update .= ", page_title = '{$page_title}'";

   line 369
          $result = cpg_db_query("SELECT *, p.title AS title, p.page_title as page_title, p.votes AS votes FROM {$CONFIG['TABLE_PICTURES']} AS p INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS a ON a.aid = p.aid WHERE pid = '$pid'");


   lines 510 - 517
<tr>
        <td class="tableb" style="white-space: nowrap;">
            {$icon_array['title']}Page Title
        </td>
        <td width="100%" class="tableb" valign="top">
            <input type="text" style="width: 100%" name="page_title" maxlength="255" value="{$CURRENT_PIC['page_title']}" class="textinput" />
        </td>
</tr>

displayimage.php

   lines 500 - 503
      $rowX = cpg_db_fetch_row(cpg_db_query("SELECT page_title FROM {$CONFIG['TABLE_PICTURES']} WHERE pid = '{$CURRENT_PIC_DATA['pid']}'"));
    $page_title = $rowX['page_title'] ? $rowX['page_title'] : $picture_title;

   pageheader($page_title . ' | ' . $album_name, $meta_keywords, false);

db_input.php

   lines 377 - 378
  $page_title = $superCage->post->getEscaped('page_title');
    $meta_description = $superCage->post->getEscaped('meta_description');

   line 423
          $query = "UPDATE {$CONFIG['TABLE_ALBUMS']} SET title = '$title', description = '$description', category = $category, thumb = $thumb, comments = '$comments', votes = '$votes', visibility = $visibility, alb_password = '$password', alb_password_hint = '$password_hint', keyword = '$keyword', page_title = '{$page_title}', meta_description = '{$meta_description}'";


catmgr.php
   
   lines 67
$sql = "SELECT rgt, cid, parent, name, pos, page_title, meta_description FROM {$CONFIG['TABLE_CATEGORIES']} ORDER BY lft ASC";

   lines 515
$result = cpg_db_query("SELECT cid, name, parent, description, thumb, page_title, meta_description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = $cid");


   lines 544-545
$page_title       = $superCage->post->getEscaped('page_title');
    $meta_description = $superCage->post->getEscaped('meta_description');

   lines 553 - 557
if (!in_array($parent, $children)) {
         cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent = $parent, name = '$name', description = '$description', page_title = '{$page_title}', meta_description = '{$meta_description}', thumb = $thumb, lft = 0 WHERE cid = $cid");
   } else {
        cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET name = '$name', description = '$description', page_title = '{$page_title}', meta_description = '{$meta_description}', thumb = $thumb, lft = 0 WHERE cid = $cid");
    }


   lines 762 - 777
          <tr>
            <td width="40%" class="tableb">
                Page Title
            </td>
            <td width="60%" class="tableb" valign="top">
                <input type="text" style="width: 100%" name="page_title" value="{$current_category['page_title']}" class="textinput" />
            </td>
        </tr>
        <tr>
            <td class="tableb" valign="top">
                Meta Description
            </td>
            <td class="tableb" valign="top">
                <textarea name="meta_description" rows="5" cols="40" style="width: 100%;" class="textinput">{$current_category['meta_description']}</textarea>
            </td>
        </tr>

modifyalb.php

   lines 94 - 95
          array('Album - Page Title', 'page_title', 0),
    array('Album - Meta Description', 'meta_description', 3),


There's probably much easier, cleaner and more efficient ways to do it .. it would seem to me it should be a pretty simple mod .. but that's what I have in my cpg gallery. It's not perfect .. I seem to get 2 meta description tags, which I don't know how to resolve. I also end up with "| Stock photos" as the end part of every title tag, which I don't know how to remove.

But this code gives me the option to write a custom Title Tag for each album and category. A custom field opens up when I edit or create a new album/category.

I hope this is of some help to anyone else. If it's apparent I've overlooked part of the code in copying it here, let me know and I'll see if I can find anything else that has been edited.

Cheers

Carl

Αndré

I hadn't looked at the code changes, as I always prefer "find foo and replace with bar" instead of "line foo = bar".


Quote from: Walkinman on January 29, 2013, 10:07:08 PM
I also end up with "| Stock photos" as the end part of every title tag, which I don't know how to remove.

In displayimage.php, find
pageheader($page_title . ' | ' . $album_name, $meta_keywords, false);
and replace with
pageheader($page_title, $meta_keywords, false);

Walkinman

Hey André

Thanks .. I found I also had to edit my theme.php file

lines 1724-1745 for me

/******************************************************************************
** Section <<<theme_page_title>>> - START
******************************************************************************/
// Creates the title tag for each page
// For the sake of search engine friendliness, the dynamic part $section should come first
function theme_page_title($section)
{
    global $CONFIG;
    $superCage = Inspekt::makeSuperCage();
    if (strpos($superCage->server->getRaw('PHP_SELF'), 'index.php') !== FALSE && ! $superCage->get->getInt('cat'))
    {
        $return = strip_tags(bb_decode($section)) . ' | ' . $CONFIG['gallery_name'] . ($CONFIG['gallery_description'] ? " | " . $CONFIG['gallery_description'] : '');
    }
    else
    {
        $return = strip_tags(bb_decode($section)) . ' | ' . $CONFIG['gallery_name'];
    }
    return $return;
}
/******************************************************************************
** Section <<<theme_page_title>>> - END
******************************************************************************/


but remove this " . ' | ' . $CONFIG['gallery_name']" to


else
    {
        $return = strip_tags(bb_decode($section));
    }
[code]

Now it's working well enough.

How can I make it so  [code] | stock photos
will still appear on the Image Search Results thumbnails .. but only on those meta pages, not on the regular categories/albums? I looked on the search.php file; line

pageheader($lang_search_php['title']);

rigt now, the title tag would be something like:

QuoteImage Search Results ="mount blackburn"

and I would like it to be
QuoteImage Search Results ="mount blackburn" | Stock Photos

I assume I have to put this

$page_title . ' | ' . $album_name

back in somewhere .. but I can't see where. Is that possible?

Thanks so much.

Cheers

Carl

PS I realise this is kind of a 2nd question, but I figure it's (hopefully) related enough it doesn't require its own thread.

Αndré

Is "Stock Photos" your gallery name or somehow related to this mod?

Walkinman

It's what I have filled in the config for "Gallery Name".

Αndré

So it's not related to this mod. Please start a new thread and describe exactly what should be displayed where (I currently understood that you want to hide the gallery name in the page title everywhere, but in the search results).

Walkinman


Walkinman

Hey Folks,

I've been trying to get rid of duplicate meta tag for description mentioned here, and I can't figure it out .. in my thumbnails.php file I have



// after that add
$meta_description = $CURRENT_ALBUM_DATA['meta_description'] ? $CURRENT_ALBUM_DATA['meta_description'] : $CURRENT_ALBUM_DATA['description'];
if ($meta_description)
{
    $meta_keywords .= '<meta name="description" content="' . htmlspecialchars($meta_description) . '" />' . $LINEBREAK;
}

$section = $CURRENT_ALBUM_DATA['page_title'] ? $CURRENT_ALBUM_DATA['page_title'] : $section;

pageheader($section, $meta_keywords);


and so I get two description tags in the html output ... see here

example.com/stock/thumbnails-2-Camping-photos.html

replace example.com with http://www.skolaiimages.com

I get


<meta name="description" content="Professional stock photos of camping, backcountry backpacking and hiking campsites, tentsites, tents, pictures from Georgia and the Appalachian Trail, Denali National Park and Wrangell St. Elias National Park in Alaska. Camping in the Arctic National Wildlife Refuge, ANWR, Alaska images." />
<meta name="description" content="Photos and images of campsites, tents, tentsites, backpackers, backpacking and camping. Backcountry campsites in Alaska, including ANWR (the Arctic National Wildlife Refuge, Denali and Wrangell - St. Elias National Parks), as well as the southern Appalachian mountains. .  Page 1 " />


The description content I actually want is the stuff in the first of these 2 tags .. it's not the description from the page, but a custom field to write a tag. however, whenever I delete one of those 2 sections in the above php code, from thumbnails.php, I always get the 2nd tag show up, the one ending in "Page 1" .. that's not what I want. I would like to be able to write a longer page description, and keep the meta tag shorter and customized to fit the page title a bit better.

I'm sorry to bring this up again. I thought I had fixed it but seemingly not .. this doesn't happen on the category pages, or image display pages, just the album display thumbnail pages.

I do get another meta tag from template.html I commented out, so I'm not worried about that. Once I resolve this I'll just delete it, rather than leave it commented.

I THINK I understand (kinda) what is going on; the code is calling the description, then saying if there is no description, it calls the 2nd one instead, is that correct? Is there somewhere else maybe, in another file, i need to modify something to fix this perhaps?

Thanks for your help.

Cheers

Carl

Αndré

As far as I can see stock Coppermine doesn't add
<meta name="description"
to the HTML output. I assume you've installed a plugin which adds the second meta tag?

Walkinman

Ha ha .. nailed it . I'd forgotten all about that plugin, thanks. I uninstalled it and the problem seems resolved.

Thanks for your help, as always.

Cheers

Carl