Joomla replace String in article content with PHP Code - joomla

I´m working on a Joomla 2.5 site. The goal is to give the authors an easy way to output a list of categories when editing an article.
For this I wrote a small PHP Script which querys the needed content from the Db:
switch ($year) {
case "2009":
$id = "42";
break;
...
$db->setQuery('
SELECT
#__categories.title
FROM
#__categories
WHERE
#__categories.parent_id =' . $id .'
ORDER BY #__categories.title ASC
'
);
$winners = $db->loadObjectList();
foreach($winners as $gewinner){
echo $gewinner->title . "<br />";
}
...
The Script takes a year as Input and uses it as $id.
I´ve now looking for a way to easily integrate this into joomlas article editor. Great would be if the authors could insert something like
###2011###
which then is converted to:
<?php
require_once '/homepages/16/d60007267/htdocs/content/testpage/templates/test/winners.php?j=2009';
?>
when the article is rendered. I thought I could make an com_content override. But haven´t found a good point where to search and replace within the content.
thanks for help,
tbook

You have to look at content plugins and maybe editors-xtd plugins.
The content plugin will detect the special markup you put into the article and do whatever you need it to do with it. That is your whole script code should go into this plugin, not the require_once stuff. Usually plugin markup uses { and }, but you could use anything you want. You just create a proper REGEX for it to detect.
If this works you can also look at an editors-xtd plugin. This will then create a button below the editor which allows your authors to input the markup into the editor.
For examples, you can look at one of the simpler existing plugins.

Related

How to edit page <title> tag in Joomla 2.5

I am using custom search module in joomla 2.5 and I need to add extra text to the title tag on module. But I cant seem to find where the tag is located in Joomla. Does any of you guys know where it is located and how can I override page title ? Thanks
#George Wilson is close, but the $this will only work depending on what context you are in/
Instead you can do something as simple as the following pretty much anywhere (though this should be something set by either the component or a plugin specifically meant to improve page titles globally in some way).
JFactory::getDocument()->setTitle('Set your title here');
Do note though that if you set this in a module or elsewhere, something else can come along later in the code and override this.
The title tag should NOT be set by a module - but by the component on the page. Having said that you can do it through:
<?php
$app = JFactory::getApplication();
$this->setTitle( 'This is the title that you wish to place' );
?>
Link here for more info
I guess you want this:
public_html/libraries/joomla/document/html/renderer/head.php
Take a look at that on LINE 102. You will be able to control everything... :-)
Add the following line:
JFactory::getDocument()->setTitle('Set your title here');
after
$app = JFactory::getApplication();
in the following file:
public_html/libraries/joomla/document/html/renderer/head.php

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

wordpress insert content before comment_template()

I am trying to inject content into the comment_template() similiar to how you can with comment_form().
For example:
<?php
$args = array("comment_notes_before" => myrp_api_ratings_form_table(null, true));
comment_form($args);
?>
This will make it so what is returned from the myrp_api_ratings_form_table function will appear before the comment form instead of after the submit button.
Is there any way to do something similiar but using the comment_template() function? I tried looking at the codex with no luck. Also, is there any good links to modifying the output of comment_template() any further?
Thank you
There is a lot of actions and filters that is available on the comment_template, you can use them to modify the template, or just build your own template. Here's a list of all the filters and actions available:
http://codex.wordpress.org/Plugin_API/Filter_Reference#Comment.2C_Trackback.2C_and_Ping_Filters
EDIT:
This thou only changes the data of each comment. If you want to change the display, and structure of the real template, I guess you have to create your own template. But it's not as hard as it sounds, there is a great guide in the codex with some nice examples: http://codex.wordpress.org/Function_Reference/wp_list_comments

Joomla, static text after every article

Is there anyone who knows how to add piece of code under every article of joomla. Joomla version 1.5.
Whitch files I should edit or maybe theres some plugin or component?
You can create a system/content plugin
which should work on onPrepareContent trigger
function onPrepareContent($item, $params, $limitstart)
{
// append text in $item->text
}
one other way can be in template you override the view of com_content and add some static text in there. Simple thing you can try is go to
\components\com_content\views\article\tmpl\ pick default.php from there and put it in templates\template_name\html\com_content\article\
now here change the default.php to contain that static text.
if you need some text/html (not php code), than you can use this plugin: http://extensions.joomla.org/extensions/style-a-design/articles-styling/7404
- it has a lot of configuration options

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