Get custom advanced parameter from article in my module in Joomla - php

I have a small news module on the home page in my website. It shows the news articles added from the Joomla admin.
It shows the article title in the module section.
But I do not want to show article title in the news module on the home page. I need to show some other text in the news module instead of the news title.
For this I have added a new custom parameter called "News title" in the article manager.
This new custom parameter is getting saved and updated properly with the other article content.
But I am having problems while retrieving the value of this custom parameter in the news module.
Below is the code which is used to get the title of the article in the module.
// getting content
$this->content = $newsClass->getNewsStandardMode($categories, $sql_where, $this->config, $this->config['news_amount']);
//
$this->SIDTab = $this->content['SID'];
$this->titleTab = $this->content['title'];
$this->textTab = $this->content['text'];
$this->idTab = $this->content['ID'];
$this->cidTab = $this->content['CID'];
Below is my code used to show article title.
function render(&$params)
{
$content = array();
//
for($i = 0; $i < count($this->idTab); $i++)
{
$content[$i] = '';
//
if($this->config['links'] == 1)
{
$url = $this->idTab[$i].'&Itemid='.$this->config['item_id'];
if ($this->config['url'] != ""){
$content[$i] .= '<a href="'.$this->config['url'] .'">';
} else {
$content[$i] .= '<a href="'.JRoute::_(ContentHelperRoute::getArticleRoute($url, $this->cidTab[$i], $this->SIDTab[$i])).'">';
}
}
// some more code }
Please help.
Thanks.

When the module is getting the parameters, it is pull the module parameters, not the parameters from the article. The parameters for the article are stored in the attributes fields in the jos_content table. You'll need to get your text from there.
There is an easier way to do this without hacking the core. I noticed that you do not have any intro text in your article. It would be much easier to put the text you want to use at the beginning of the article content and insert a read more break after it. Now the text you want will be processed as intro text by Joomla. You can set it to display in the module and to be hidden in the article view. This prevents you from having to hack the core so you can update easily and should make it easier to display the content you want.

Related

How can I automatically HREF the articles of my MongoDB database to each article specific page?

I'm working on a site which is more of a DB project that anything else. Currently I mainly using my mongoDB database to show the previews of those articles after querying them with these functions (which are in 2 different files)
//this one is from the functions file which i load in all the various pages of the site
function article_recordset() {
require 'vendor/autoload.php';
$client = new MongoDB\Client("mongodb://localhost:27017");
$i = 0;
$SiteArticles = $client->SiteArticles;
$articoli=$SiteArticles->Articles;
$cursor = $articoli->find();
return $cursor;
foreach ($cursor as $articolo) {
$recordset = array(
$i=$i+1 => array(
"title" => $articolo["title"],
"description" => $articolo["content"],
"article" => "",
)
);
}
}
//this is the index.php file so the homepage where i display the articles which i stored into an array and then i display with an echo later
include("funzioni.inc.php");//name of the functions file
$ARR_articles = article_recordset();
$STR_article = NULL;
foreach($ARR_articles as $index => $article){
$STR_article .= get_article_item_html(
$img_path = "img/article/".$index.".jpg",
$title = $article["title"],
$description = $article["content"]
);
}
The display works fine and all but what I'm trying to do is to HREF each displayed article preview to their own article page
So article 1 is displayed and is linked to the page of localhost/folder/article1.php for example
Now the href I want to do is somewhat automatic so it links to each article page which I manually created already just like it does the foreach for the query of all the article contents
So like it's going to store each article in the array which I display later while also like setting an href to each one
For example:
Query article 1, store into array, display that array content for article 1 and href it to it's own page, and so on for each article
Note: I want to ""automate"" just the HREF of each queried article not automate the article page creation since I have those pages already created and it's for a small project and nothing too serious

How do I use category-specific colours?

The Wordpress theme I am using (Multinews) comes with the ability to assign colour schemes to entire categories, so that all posts within that category take on the colour scheme that is assigned to that category.
However, I have added a couple of features to the design (ie a coloured dropcap on the first letter of the article) and would like to assign the category-colours to them, too.
For example, at http://www.mediatoday.org.uk/media/television-and-radio/2014/10/25/evan-davis-interview-with-russell-brand-was-fifteen-minutes-of-television-gold/ you'll see orange is the category colour, but the dropcap (the large R) is currently blue.
If you could please advise me on how to add the category-colour style to other features, I'd really appreciate it.
By chance I worked on the same theme recently so I know what you're trying to find out. The thing is - the theme authors have that color built into their framework. They get the color selected depending on if the page or a category is being displayed and then they literally put it into the underneath the menu.
If you inspect the HTML of your menu - the cat color is inside the HTML - it's not in any CSS atributes.
Try looking at the code of the menu and use the same principal:
if ($item->object == 'category') {
$cat_ID = $item->object_id;
$cat_data = get_option("category_".$cat_ID);
$cat_color = isset($cat_data['color']) ? $cat_data['color'] : '' ;
if ($cat_color != '') {
$cl = $cat_color;
}
} elseif ($item->object == 'page') {
$page_color = get_post_meta($item->object_id, 'mom_page_color', true);
if ($page_color != '') {
$cl = $page_color;
}
}
it's the menu.php file under multinews\framework\menus folder

Joomla get content by ajax

How to get joomla content using ajax? (I want to show content of specyfic page in popup), this is my code: (called by ajax)
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
if ($option=="com_content" && $view=="article") {
$ids = explode(':',JRequest::getString('id'));
$article_id = $ids[0];
$article =& JTable::getInstance("content");
$article->load($article_id);
echo '<h2>'.$article->get("title").'</h2>';
echo $article->get("introtext"); // and/or fulltext
}
This works fine only for artilces, but the problem is when for example I want to show category, or component
Please see your if condition it checks if option is equal to com_content & view is equal to article only. If view contains category it won't work. So add the conditions in if statement so that your code gets executed.
for category you need to add view=category & like for other components as well.

Handling of "Back to Home" population with PHP in WordPress

I'm attempting to have a Title and URL populate based off the parent child relationship. I've been able to work with other developers here on Stackoverflow (ref: Echo the subtitle of a PARENT page within WordPress - Part (2)) to mimic a similar function based off of data gathered from tables, however, this will be static information that is populated.
What I need to be done:
If you are on the Homepage or using the "Default" template for the page, the Title will be "Homepage" and the URL will be "http://example.com". In this scenario the page id will be "0" for the homepage and any children will share this relationship based off of "0".
If you are on a Sub-brand homepage or a page using this template, the Title will be "Sub-brand" and the URL will be "http://example.com/sub". In this scenario the homepage id will be "67" and any children will share this relationship based off of "67".
Current version of the function:
<?php
if ($post->post_parent!=67) {
// Sub-brand - children
echo = "Sub brand child";
$title .= "Sub-brand";
$link .= "\nhttp://example.com/sub";
} elseif($post->ID==0||count(get_pages('child_of='.$post->ID))!=67) {
// Sub-brand - home
echo = "Sub brand home";
$title .= "Sub-brand";
$link .= "\nhttp://example.com/sub";
} else {
// Homepage and children
echo = "Everything else";
$title .= "Homepage";
$link .= "\nhttp://example.com/";
}
?>
Current issue(s):
The homepage is being categorized under the initial "if" statement instead of "else"
The child pages that are using the "Homepage" as the parent are being
associated with the "elseif" statement instead of "else"
What's working:
The Sub-brand homepage is properly being populated by the initial
"if" statement
The child pages that use "Sub-brand" as the parent are being
associated with the "elseif" statement
Any help would be appreciated with getting the associations correct. Be aware, I've been working with PHP for less than a week and I'm learning as I go.

Joomla : how to get the url of a specific Menu itemID?

Friends a newbie question.........I need help in getting the URL of a specific Menu itemID. The situation is like this:
I am running Joomla and asking for a user to input for a menu ID and choose a layout for that menu ID.
I want to do something else with this URL of the Menu itemID.
How can I get the URL of this Menu itemID provided by the user?
For Example if the user input is liek $this->get ('menulayoutid'>; and he inputs and ID of 54 then how do I get the URL for Menu ID 54.
Please note: I want to get this URL from within my PHP file and not in the browser so that I can use the value of that URL for some other purpose.
Kindly help.
$itemid = JRequest::getVar('Itemid');
$application = JFactory::getApplication();
$menu = $application->getMenu();
$item = $menu->getItem($itemid);
$link = new JURI($item->link);
$link->setVar('ItemId', $itemid);
Source: http://forum.joomla.org/viewtopic.php?p=1836005
However, we get the Itemid from anywhere (user input, from our own developed module using the "menu item" field type in the xml file as described in the Joomla Docs - Standard form field types)
// get the menuItemId from wherever...
// as described above or as in other posts here and do whatever with that!
$menuItemId = 'fromWherever'; // as an example "107";
// build the link to the menuItemId is just easy and simple
$url = JRoute::_('index.php?Itemid=' . $menuItemId);
i think if we need only a link to a specific menu id, this is the best solution, because we have absolutely less requests and a clean code
this works also in Joomla 3.0, 3.1
I just want to add that if you need to target a specific menu you pass the menu name as an argument to getMenu().
$itemid = JRequest::getVar('Itemid');
$application = JFactory::getApplication();
$menu = $application->getMenu( 'menu-name' );
$item = $menu->getItem($itemid);
$link = new JURI($item->link);
$link->setVar('ItemId', $itemid);
I'm not sure if Joomla changed the way this works since 2.5 or even 1.7 but I spent the worse half of 2 hours looking for this.
Hopefully it helps someone.
$menuID = $params->get('menuItem'); // from module field menu ex. '105'
$js = new JSite;
$menu = $js->getMenu();
$link = $menu->getItem($menuID)->route;
//Returns URL Friendly Link -> menu/article
//Then format it ->
$link = 'http://www.yoursite.com/index.php/'.$link;
echo 'Borrowed Menu Link Path";
When you need to get your active menu item ID in Joomla to display some specific content for only that menu item or just to show the ID of the menu item, insert the following code where you wish to display the active menu item ID:
<?php
$currentMenuId = JSite::getMenu()->getActive()->id;
echo $currentMenuId;
?>

Categories