Joomla Module, get "Show / Hide Module Title" parameter - php

I'm overwriting the mod_menu default.php and want to receive the "show_title" parameter from the module option. Using Joomla 3!
<?php
$doc = JFactory::getDocument();
$page_title = $doc->getTitle();
$menu = &JSite::getMenu();
$active = $menu->getActive();
$menuname = $active->title;
$parentId = $active->tree[0];
$parentName = $menu->getItem($parentId)->title;
if ($params->get('show_title')):
?>
<h2><?php echo $module->title; ?><?php #echo $params->get('title'); #$parentName; ?></h2>
<?php
endif;
?>
That's a part of my code.
Unfortunately "show_title" doesn't work. What am I doing wrong?

The solution was:
if($module->showtitle):

Related

Joomla: display page heading of menu item

I want to display the page heading of a Joomla menu item if this is filled. I've tryed with this code wothout success:
<h1 class="title">
<?php
if (null === ($this->params->get('page_heading')))
{
$mydoc = JFactory::getDocument();
$mytitle = $mydoc->getTitle();
echo $mytitle;
}
else
{
$active = JFactory::getApplication()->getMenu()->getActive();
echo $active->params->get('page_heading');
}
?>
</h1>
Any suggestion?
I've solved myself this way:
<h1 class="title">
<?php $menu = JFactory::getApplication()->getMenu();
$active = $menu->getActive();
$mydoc = JFactory::getDocument();
$mytitle = $mydoc->getTitle();
$pageHeading = $active->params->get('page_heading');
if($pageHeading != "")
{
echo $pageHeading;
}
else
{
echo $mytitle;
}
?>
</h1>
I had similar need and noticed this code doesn't work in Joomla 4.
Here is my solution:
Joomla 3
$menu = JFactory::getApplication()->getMenu()->getActive();
$title = $menu->title;
$page_heading = $menu->params->get('page_heading');
echo $page_heading ?? $title;
Joomla 4
$menu = JFactory::getApplication()->getMenu()->getActive();
$title = $menu->title;
$page_heading = $menu->getParams()->get('page_heading');
echo $page_heading ?? $title;
The only difference between these 2 is how you get the menu item params, params in J3 vs getParams() in J4.

wordpress if not index echo something else

I'd like to give my title <?php echo get_the_title(); ?> conditional statement. If not HOMEPAGE just display whatever it is = <?php echo get_the_title(); ?>. if HOMEPAGE display THIS IS + <?php echo get_the_title(); ?>
so the syntax should be
<?php
$path = $_SERVER['REQUEST_URI'];
$page = basename($path);
$page = basename($path, '.php');
?>
<?php if($page == 'index')
{echo 'This is'. get_the_title(); }
else
{echo get_the_title();}
?>
the problem is I dont really know in wordpress do we use the same way or something smarter or easier.
OH, FORGOT!
Actually, my index/homepage is not real index, it is the page called "HOMEPAGE "
setting from Reading Settings -> a static page, front page => HOMEPAGE
Thanks for any advice.
place your code in functions.php
function title_edit($title){
if(!is_front_page() || get_post_type() != 'page') return $title;
$title = 'Home: '.$title;
return $title;
}
add_filter('the_title','title_edit');
Problem solved thanks #silentboy
<?php if(is_front_page())
echo 'This is'.get_the_title();
else echo get_the_title(); ?>

add live ID to BODY with PHP

I'm using the php code:
<body id="<?php echo str_replace("index.php?","",(basename($_SERVER['REQUEST_URI'],".php"))); ?>">
and
<?php
if(isset($_GET['start'])){
include('includes/start.php');
}else if(isset($_GET['help'])){
include('includes/help.php');
}else{
include('includes/start.php');
}
?>
It works great - cutting index.php?help to "help" and index.php?start to "start" in body ID. But when I enter index.php in body ID is "index" not "start". Is there any way to tell index.php with included start.php to display "start" id body ID?
UPDATE
It should work dynamically - body ID is name of included .php file, something like this code:
<?php
$page = str_replace(array( 'server_name', 'index', '?', '/', '.php'), '', $_SERVER['REQUEST_URI']);
$page = $page ? $page : 'start';
?>
<body id="<?php echo $page ?>">
Am not sure i get you 100% but you can try
$id = $_SERVER['QUERY_STRING'];
$bodyID = $id;
switch ($id) {
case "help" :
include ('includes/help.php');
break;
default :
$bodyID = "start";
include ('includes/start.php');
break;
}
printf("<body id=\"%s\" >", $bodyID);
If you run index.php?help it would include include ('includes/help.php'); and also output
<body id="help" >
It would be best to use this instead:
<?php
$ids = 'start,help,something';
$ids = explode(',',$ids);
$included = 0;
foreach ($ids as $id) {
if (isset($_GET[$id])) {
include('includes/'.$id.'.php');
$included = 1;
break;
}
}
if (!$included) include('includes/'.$ids[0].'.php');
?>
Then:
<body id="<?php echo $id; ?>">

SEF url from module in joomla

I am making a module and trying to figure out how to get the Search engine friendly url to articles from this module
this is the helper class today
public function getItems($amount)
{
$db = &JFactory::getDBO();
$query = 'SELECT * FROM `#__content`, `#__content_frontpage` WHERE `#__content_frontpage`.content_id = `#__content`.id AND `#__content`.state = 1 ORDER BY `#__content`.publish_up DESC LIMIT ' . $amount . '';
$db->setQuery($query);
$items = ($items = $db->loadObjectList())?$items:array();
return $items;
} //end getItems
And this is the default.php to display stuff
<ul class="frontpage_news">
<?php foreach ($items as $item) { ?>
<li>
<div class="frontpage_date"><?php echo JText::sprintf('DATE_FRONTNEWS', $item->publish_up); ?></div>
<div id="ffTitle" class="frontpage_title"><?php echo JText::sprintf('TITLE_FRONTNEWS', $item->title); ?></div>
<div id="ffRead" class="frontpage_readmore"><?php echo JText::sprintf('READ_MORE_FRONTNEWS'); ?></div>
</li>
<?php } ?>
</ul>
So how do I get the correct link to each article displayed in SEF format?
Thanks for any help!
For Joomla 1.5:
echo JRoute::_(ContentHelperRoute::getArticleRoute($article_id_and_alias, $category_id_and_alias, $section_id));
For Joomla 1.6/1.7:
echo JRoute::_(ContentHelperRoute::getArticleRoute($article_id_and_alias, $category_id));

wordpress site navigation

I'm using following code to display my 3 level menu:
if(!$post->post_parent){
// will display the subpages of this top level page
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
}else{
// diplays only the subpages of parent level
//$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
if($post->ancestors) {
// now you can get the the top ID of this page
// wp is putting the ids DESC, thats why the top level ID is the last one
$ancestors = end($post->ancestors);
$children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");
// you will always get the whole subpages list
}
}
if ($children) { ?>
<ul id="submenu">
<?php echo $children; ?>
</ul>
<?php } ?>
It lists pages in side bar, second level then 3rd level too. I would like to include very top level too so i would like to my structure to look as follow:
*A
-a
--a
-b
--b
-c
--c
Where as above code is not listing main page i.e. *A, i hope that make sense and someone will be able to help
Thanks,
I found this code snippet at the wordpress codex site, and I think it's exactly what you're looking for, I've pasted it in for convenience:
<?php
//if the post has a parent
if($post->post_parent){
//collect ancestor pages
$relations = get_post_ancestors($post->ID);
//get child pages
$result = $wpdb->get_results( "SELECT ID FROM wp_posts WHERE post_parent = $post->ID AND post_type='page'" );
if ($result){
foreach($result as $pageID){
array_push($relations, $pageID->ID);
}
}
//add current post to pages
array_push($relations, $post->ID); // <---- THIS IS INCLUDING THE PARENT
//get comma delimited list of children and parents and self
$relations_string = implode(",",$relations);
//use include to list only the collected pages.
$sidelinks = wp_list_pages("title_li=&echo=0&include=".$relations_string);
}else{
// display only main level and children
$sidelinks = wp_list_pages("title_li=&echo=0&depth=2&child_of=".$post->ID);
}
if ($sidelinks) { ?>
<h2><?php the_title() ;?></h2>
<ul>
//links in <li> tags
<?php echo $sidelinks; ?>
</ul>
<?php } ?>
It also has some built-in logic to not display everything if this is a highest-level page. Hope this helps!
<div id="breadcrumbs">
Home
<?php
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = ''.get_the_title($page->ID).'';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) echo ' / '.$crumb;
?>
</div>
<h1><?php the_title(); ?></h1>
credit : Ivovic
from : http://wordpress.org/support/topic/display-page-parent-on-page-with-title?replies=13

Categories