This tip follows on from my previous one about making Category Names linkable in blog listings and on content items.
I'll try to make it short by simply posting the (commented) code. Changes are actually straightforward.
Once again, please correct any errors and point out any implications or trip-wires I have missed. I must admit, I haven't thought through on this one what will happen if you have more than one Blog - Content Section menu link for the same Section, but it can't be worse than the status quo(!)...
So; you can also make
Section Names linkable on Content Items. This is
extremely useful. Why?
You will have noticed that if you create
Table - Content Section menu items in a hidden menu in order to normalize ItemIDs when you are primarily using blog-style listings on your site, this screws up your
pathway.
It also screws up
active menu highlighting. A Section Blog highlights OK, as does a (child) Category Blog, but you lose the highlighting when you click through to a Content Item, because the Content Item takes its ItemID from the hidden
Table - Content Section menu item.
So, ideally, you need to provide an alternative way of showing your visitor where they are in the site - to which section and category the article they are reading belongs.
This is ONLY an issue if you have set up your site in a certain way, using blog listings. It won't apply to everyone, but is quite common.
If you
show and
make linkable both Section Name and
Category Name in the parameters of each of your Content Items, (and assuming you have made the changes in my previous tip,) you effectively have a replacement pathway which works...
ALMOST.Unfortunately, the
Section Name link picks up its ItemID from the
Table - Content Section menu item in the hidden menu, which is not what we want. We want the link to take us back to our Section
Blog listing, which is the visible menu item from which we came to the article.
I made the following changes (which incorporate those from the previous Category Name Link tip - everything is commented):com_content/content.phpCode:
<?php //Helps forum to do code highlighting - not relevant to solution
// loads the link for Section name
if ( $params->get( 'section_link' ) ) {
$query = "SELECT a.id"
. "\n FROM #__menu AS a"
. "\n WHERE a.componentid = ". $row->sectionid.""
. "\n AND a.type = 'content_blog_section'" /** Kper added this line so that a content_blog_section itemid is
used for this particular link. This ties in with the change to the Category name link, below.
The intention is to use these links as a replacement for the Pathway when using blog listings
togeher with a LIST-SECTION menu item in a hidden menu for ItemID normalization.
*/
;
$database->setQuery( $query );
$_Itemid = $database->loadResult();
// Kper changed task=section to task=blogsection in the next line. See note under Category Name, below.
$link = sefRelToAbs( 'index.php?option=com_content&task=blogsection&id='. $row->sectionid .'&Itemid='.$_Itemid );
$row->section = '<a href="'. $link .'">'. $row->section .'</a>';
}
// loads the link for Category name
if ( $params->get( 'category_link' ) ) {
$query = "SELECT a.id"
. "\n FROM #__menu AS a"
. "\n WHERE a.componentid = ". $row->catid.""
;
$database->setQuery( $query );
$_Itemid = $database->loadResult();
/** Kper replaced the following $link line with the one below it so that linked category names in section blogs
and on content items go to a category BLOG listing rather than a category TABLE listing. Otherwise there
are problems with ItemIDs for the content items. This way, a LIST-SECTION menu item can be published
and ALL the content item links will pick up their ItemIDs from that.
If the linked category name is a TABLE rather than a BLOG listing (as it is by default), the content item links
in it will take their ItemIDs from that TABLE-CATEGORY listing (which will, in fact, get NO ItemID if such a
menu link is not already published), whilst the content item links in the original section blog will take their
ItemIDs from either that section blog or (if one is published) the LIST-SECTION menu item for that section.
Arrrrgh!
$link = sefRelToAbs( 'index.php?option=com_content&task=category§ionid='. $row->sectionid .'&id='. $row->catid .'&Itemid='.$_Itemid );
*/
$link = sefRelToAbs( 'index.php?option=com_content&task=blogcategory&id='. $row->catid .'&Itemid='.$_Itemid );
$row->category = '<a href="'. $link .'">'. $row->category .'</a>';
}
EDIT for stupidity: I don't know what I was thinking with this. I have now changed the SQL above from
ORDER BY a.type to
AND a.type = 'content_blog_section'com_content/content.html.phpCode:
<?php //Helps forum to do code highlighting - not relevant to solution
/**
* Writes Section - class="categorynamelinkable" added by Kper for styling of Section names
* when they are displayed on content items
*/
function Section( $row, $params ) {
if ( $params->get( 'section' ) ) {
?>
<span class="categorynamelinkable">
<?php
if ( $params->get( 'category' ) ) { echo "Section: "; } //Kper added this line
echo $row->section;
// writes separator between Section & Category Name when both are active
if ( $params->get( 'category' ) ) {
echo ' > '; // I prefer this to a dash. nbsp is because I have padding on the spans via css
}
?>
</span>
<?php
}
}
/**
* Writes Category - class="categorynamelinkable" added by Kper for styling of Category names
* when they are displayed on content items and in blog listings
*/
function Category( $row, $params ) {
if ( $params->get( 'category' ) ) {
?>
<span class="categorynamelinkable">
<?php
if ( !$params->get( 'section' ) ) { echo "Section: "; } //Kper added this line. I know it is a category, not a section, but site visitors will perceive it as a sub-section.
echo $row->category;
?>
</span>
<?php
}
}
Hope that is of some use to someone.
Ok, I know it may be a stupid question, but, where do I place those hacks? In what line? Do I have to replace some code or not? Thanks!