Run code if inside a specific category - joomla

Hi there I'm trying to display html code on certain pages in Joomla 3.0 depending on what category they're in - I've tried this but it won't work and displays nothing;
<?php $catid = JRequest::getInt('catid'); if ($catid == 14) {?>
HTML CODE GOES HERE
<?php } ?>
Any help would be greatly appreciated .

Rather than hardcoding this in to your site, just use Advance Module Manager and a Custom HTML module. This will make it trivial to change/add/delete what you want to display and where you want to display it.
First, create a menu item for each category if you don't already have one. If you do not want the links to show anywhere, create a new menu for the links and do not assign it to a module.
Next, install Advance Module Manager. For each category, create a new Custom HTML module with what you want to display. Then just assign the module to display for the menu item you created in the first step.

Related

Restricting Slideshow CK to certain pages within Joomla

I am trying to show Slideshow CK only on the homepage of my Joomla based site. I have gone into the 'assignment' section of the module and restricted it to 'Home' menu item and said 'no' to include on child items. This works fine. I only see the slideshow on my homepage. However, I have created a link to an article on one of my other menus. When that article is displayed, it shows the slideshow. I want to suppress it when it jumps to that link. I have been playing with various options but without much joy. I would appreciate it if somebody can clarify the control mechanism for selectively displaying the slideshow.
I have found a method of overcoming the problem but someone may suggest a better approach. I specifically went and excluded certain selected articles in the assignments. I had tried to exclude a 'hidden' category but that did not work for me. The downside of my approach is that every time I introduce a new article I have to exclude it.
If I understand correctly you are creating articles without menu items. Without a menu item you won't be able to control the module assignment so easily.
If you're comfortable editing your template an lternative approach would be to amend the template and load the module.
Locate the index.php file of your template. You should be able to do this via the template manager.
Create a custom module position e.g. slideshow-ck and assign the slideshow module only to the homepage.
Then in the template you would need to add some PHP as follows:
<?php
$menu = $app->getMenu();
$active = $menu->getActive();
if ($menu->getActive() == $menu->getDefault('en-GB')) && $this->countModules('slideshow-ck') ?>
<jdoc:include type="modules" name="slideshow-ck" style="html5" />
<?php endif; ?>
Basically what that does is only load the module position if it's assigned to the menu item AND the user is currently viewing the homepage.
https://docs.joomla.org/How_to_determine_if_the_user_is_viewing_the_front_page

Adding Joomla Article Order number inside an article

I am trying to create a Joomla site that would be showing the article order numbers (not Article ID) inside each article. that way I can handle it like a book.
Each page will show the article order number at the corner - like a page.
That way I will be able to have the site modeled by categories and pages will show with their page number (Article Order number) at the corner.
I want to give the user the ability to watch the pages like they are reading books by categories.
I would be happy to know - how can I add the article order number (for each category) inside the article itself.
I am sure that there is a PHP code that can do that.
Thanks so much for your help and assist.
Arye
You'll need to override the default article layout in your template.
If your template doesn't already have an article layout, you can copy the default layout from components/com_content/views/article/tmpl/default.php inside your template override templates\[YOURTEMPLATE]\html\com_content\article\default.php (replacing [YOURTEMPLATE] by your actual template name.
You can then display ordering where you require it within your template by using
<?php echo $this->item->ordering; ?>
You'll most likely want to either check for a certain condition (the article's category, perhaps) to determine whether you want to display the ordering.
Another option is to create an alternative layout instead of overriding the default one. You can rename default.php in your template to, let's say bookpage.php. You will then be able to pick the new layout as an alternative layout in your articles' options.
you can get article id by using
Request::getVar('id');
for more you can check the link
Joomla plugin : how to get article title and article id
for jquery you can do like this. you can create a function and call on every page load it will sort all your content accordingly. you can assign other attributes also in foreach loop.
<div id="allArticles">
<article id="3">Article 3</article>
<article id="1">Article 1</article>
<article id="2">Article 2</article>
</div>
$("#allArticles article").sort(function (a, b) {
return parseInt(a.id) > parseInt(b.id);
}).each(function(){
var elem = $(this);
elem.remove();
$(elem).appendTo("#allArticles");
});
more you can see the working example here http://jsfiddle.net/THMu3/

Joomla module position showing

I want to load a Joomla module in a specific position in a category, but I don't want to show it in an article page on that category.
I am making the assumption that you mean you are using the "Category Blog" or "Category List" feature, and wish a module to appear in the category listings view, but not the article view.
If this is for a single page then you can just set up a menu item for the problematic article using the "single article" menu item type. The listings will then redirect to that page instead of dynamically generating them. You can assign modules to individual menu items as normal.
If this is for every article, then one way to do this is to edit the module.
It will have a file called something like mod_yourmodule/mod_yourmodule.php
This will contain code like this
require JModuleHelper::getLayoutPath('mod_yourmodule',$params->get('layout', 'default'));
Change this to
$input = JFactory::getApplication()->input;
$view = $input->get('view');
if ($view != "article") {
require JModuleHelper::getLayoutPath('mod_yourmodule',$params->get('layout', 'default'));
}
This will then not render if you are on an article page. If this file is a core file, you are probably better adding similar code on your template, but using it to add a style sheet which hides the module. You should never change core files.

Joomla: Override Category Blog output multiple times?

Yes. I want to override output of Category Blog component to 2 different display styles.
For first style, i copied and edited blog_item.php & blog.php in [mytemplate]/html folder. Then i choose template style from dropdown in backend of my category blog. That's worked. The display of category blog change as i expected.
But if i want to create another style and use in another category blog. How could i do ? And how to i named my files ( I tried blog_1.php, blog_item_1.php ) but only see my first style display in backend.
I'm using joomla 2.5.
Please help me. Thank you very much !
=================================================================================
[UPDATED]
I solved this issue. Here my solution:
Clone my template to [my_template_2]
Go to [my_template_2]/html/com_content/category then edit blog.php, blog_item.php as my needs.
Go to backend, at my category blog menuitem, i assigned [my_template_2] as its template style.
Then it worked. Both my category blog have its own style.
This maybe not very good solution because i have to use multiple templates, but at this time it's quite enough for me.
Thank you, stackoverflowers.
=================================================================================
[UPDATED 2]
Now, with multiple template styles, I could create unlimited styles for my category blog component within just only one template. That's very much better.
As you may know, joomla doesn't let developers make different styles for its components.
I think you have to list all menus which are made by "category blog component" in template managing page and let users set each menu style at there.**
and at blog.php, check template setting and then load customized style...
** you have to develop a custom field element which list all "category blog component" menus.
* you can use this code to accessing template parameters in component's template :
$app =& JFactory::getApplication();
$template = $app->getTemplate(true);
$paramsTemplate = $template->params;
$style = $paramsTemplate->get('style');
You don't need to use multiple styles. What you need is to use alternate layouts and alternative menu layouts.
For alternative menu layouts in the html/componentname/category folder of your template make a new style with a unique set of names similar to the way blog already provides an alternative to category list in the article category layout folder. Also make a new xml file for each layout that you make, with a matching name.
When you create your menu item you will now get these alternatives along with your other normal choices. Just select the one you want.
Based on the learnings above here is my code for the /templates/mytheme/com_content/category/blog.php
And then in the Global Configuration > Article Manager Options > Category choose Blog as the override/ layout.
defined('_JEXEC') or die;
JHtml::addIncludePath(JPATH_COMPONENT.'/helpers');
$pageclass_sfx = trim($this->pageclass_sfx);
// so pick it on the page class in menu item
if (isset($pageclass_sfx) && $pageclass_sfx != '') {
echo $this->loadTemplate($pageclass_sfx);
} else {
echo $this->loadTemplate('default');
}
I can add multiple elseif if something else is needed, or it will look for 'blog_' . $this->pageclass_sfx . 'php'. It is always beginning blog_ as thats coded into the com_content. The old blog i moved to blog_default.php and blog_default_item.php

Joomla 1.5 How to divide joomla templet and use different page templet for different page

I am new in joomla and I am going to develop a web site with joomla 1.5.
For the site I have a html css template. Now I want to convert this into joomla template with different files (Header,Footer, sidebar etc).
Is it possible? if yes then how can i do this ?
and how can i make different page temples for my different page (such as about, Products etc)
Please help me....
I would recommend starting here:
http://docs.joomla.org/Creating_a_basic_Joomla!_template
http://docs.joomla.org/JDOC:Joomla!_1.5_Template_Tutorials_Project
I would also recommend visiting http://demo.yootheme.com or http://demo.rockettheme.com and finding one of their free templates (both have one or two, I believe) to download. That way you can analyze how a professional template is built and organized and apply it to your own project.
Your last question: To make different templates to apply to different pages. The simplest way is to follow the directions (above) to make/modify/install a second template. Then use the Joomla template manager and specify which pages apply to which template.
You can certainly create different files for each portion of a page but it's really not necessary in Joomla. There is only one "page" in Joomla, the index.php file. The entire website is built using that file. You can control the different parts - called positions in Joomla - of the website through 3 different methods
using conditional statements that determine whether they need to display at all
using modules to place content in the various positions
using CSS to control the display of each module
While it is technically possible to use multiple template in Joomla, it is almost always unnecessary. In the menu items used to create the pages in Joomla, you can specify a parameter called the page class suffix. You can insert this in to the body tag of your template giving you complete control of each page in the website through CSS rather than coding another template. Use this code to add the page class suffix to your body tag -
<?php
$menu = &JSite::getMenu();
$active = $menu->getActive();
$pageclass = "";
if (is_object( $active )) :
$params = new JParameter( $active->params );
$pageclass = $params->get( 'pageclass_sfx' );
endif;
?>
<body id="<?php echo $pageclass ? $pageclass : 'default'; ?>">
This is compatible with all the big frameworks as well.
If you want to show different header footer and sidebar on each pages. It can be easily possible in joomla. You have to simple create custom module in joomla and you control the display option of this module from the joomla administrator.

Resources