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

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.

Related

if title contains string 'aaa','bbb' or ,'ccc' replace field {category[1}

Hello gods of Stackoverflow,
Now i hate to be "that guy" who didnt search properly but i am running into a problem that i need a fix for and can't find a solution i can work with because of my lack in coding skills, my knowledge barely tickles the surface.
Here's the thing.
I am using a tool to import feeds into my website (WP all Import) as woocommerceproducts. But in the categorization the feed suppliers made errors which i want to tackle without emailing them everytime i stumble upon one.
i.e: the title contains words like satchel, bag, clutch etc but the product is categorized as 'jewellery > earrings' in the CSV or XML.
The import tool will ask me where to find the product category, i point it to the node {category[1]}
But when the category is missing or faulty i want it to check the title for certain words, and if present change the value of it to that found word.
something like:
[if ({title[1]}contains "satchel") {
category = "bags > satchel",
} else if ({title[1]} contains clutch) {
category = "bags > clutch",
} else {
category = {sub_category[1]} #the normal value if nothing was found
}]
I just can't find the pieces to put the formatting together. I might need to work towards a function that i could expand to generate categories based solely out of presence of certain words in the title but maybe when i get better that would be an option.
I hope i was able to provide a clear view on the problem. The "[ ]" is there because thats how the plugin wants code to be entered instead of a {fieldname[1]}, another example below:
The following was an example of a problem i was able to fix:
i needed to replace values like "0/3months/1/2months" to "0-3 months/1-2months" before i replaced the slash"/" with a pipe"|" for wordpress to recognize it as a seperate value.
[str_replace("/","|",
str_replace("0/3","0-3",
str_replace("1/2","1-2",
str_replace("3/6","3-6",{size[1]}))))]
The fields can also be used to call functions but only in the 'pro' version of the plugin.
Any help is very much appreciated, thanks in advance.
You could use strpos.
Example:
if (strpos($title, "satchel") !== false) {
$category = "bags > satchel";
}
So after an afternoon of poking around, testing stuff, and not knowing alot about php i came up with a solution with help from a friend.
Wp All Import does not allow custom php directly from the field itself, it does however support custom php functions and provides an editor for these on the bottom of the import configuration page. I did the following:
<?php
//Checks Title for keywords and
//uses those to create categories
//We are using our own Main categories so only
//sub and subsub categroies need to be created.
//Call function
[get_subcat_from_title({title[1]},{category[1]})]
//Function
function get_subcat_from_title($title,$defaultcat)
{
if (strpos($title,"Satchel") !== false) {
$cat = "Tassen";
} elseif (strpos($title,"Travel") !== false) {
$cat = "Tassen";
} elseif (strpos($title,"Gusset") !== false) {
$cat = "Tassen";
} else {
$cat = $defaultcat;
}
return $cat;
}
//Checks Title for keywords and uses those to create subcategories
//Call Function
[get_subsubcat_from_title({title[1]},{sub_category[1]})]
//Function
function get_subsubcat_from_title($title,$defaultcat)
{
if (strpos($title,"Satchel") !== false) {
$cat = "Satchel";
} elseif (strpos($title,"Travel") !== false) {
$cat = "Travel";
} elseif (strpos($title,"Gusset") !== false) {
$cat = "Gusset";
} else {
$cat = $defaultcat;
}
return $cat;
}
?>
On the Taxonomies, Tags, Categories option we can create our own hierarchical order like this:
[main category]
+[sub category]
++[sub sub category]
The main category field is given a name we use as our main category.
The sub category is filled with function SUBCAT
The subsub category is filled with function SUBSUBCAT
this way it will create a parent by our own name, a child that has the named 'Tassen' if any keyword is present, and a grandchild with the specific keyword as it's name.
This way i can expand the function using all kinds of statements when the right category isn't present in de provided feed.
thanks #sebastianForsberg for responding.
I hope this helps anyone who comes across a similar problem in the future..

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.

Drupal: How to display part of an author's profile in a node

I have been trying to do display a custom field I created in the manage fields section of user accounts for nodes in addition to the profile page. The problem I am having with this code is that it will display the first field it finds and display that for every user, not the field for that particular user.
And ideas? I believe it's finding the first value in the array and not the value for the particular user in the array.
Here is m setup so far:
Added this to my template.php of my theme:
function mythemename_preprocess_node(&$vars) {
global $user;
$user = user_load($user->uid); // Make sure the user object is fully loaded
$team = field_get_items('user', $user, 'field_team');
if ($team) {
$vars['field_team'] = $team[0]['value'];
}
}
Then, added this to my node.tpl.php in order to display it on nodes.
if (isset($field_team) && !empty($field_team)) :
echo '$field_team.'</div>';
endif;
UPDATE:
Found my own aswer here:
http://drupal.org/node/1194506
Code used:
<?php
$node_author = user_load($node->uid);
print ($node_author->roles[3]);
print ($node_author->field_biography['und'][0]['value']);
?>
You can use drupal's 'Author Pane' module for that. Try this:
http://drupal.org/project/author_pane

Get custom advanced parameter from article in my module in Joomla

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.

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