Hide frontpage content on homepage - Joomla 3.0 - Gantry - joomla3.0

I have a joomla site that I just want to have module content on the homepage. I have found other solutions but they seem to work on joomla 3.0 and the Gantry framework. Does anyone have an updated solution for this?
This is the code that I need to hide for the hompage:
<?php /** Begin Main Body * */ ?>
<?php echo $gantry->displayMainbody('mainbody', 'sidebar', 'standard', 'standard', 'standard', 'standard', 'standard'); ?>
<?php /** End Main Body * */ ?>
I am wondering if there is a way to use a conditional to hide this code only for the hompage like in this post:
Same idea for joomla 1.5 post

Add this code to the beginning of your template file right before the html part (but inside php tags):
$app = JFactory::getApplication();
$menu = $app->getMenu();
$isFrontPage = $menu->getActive() == $menu->getDefault();
and then you can replace line with this:
<?php if (!$isFrontPage) echo $gantry->displayMainbody('mainbody', 'sidebar', 'standard', 'standard', 'standard', 'standard', 'standard'); ?>

One possible solution is to add a new position called disable_content and check if there are active modules in there.
If so you don't display the content.
To add a position edit you templateDetails.xml in <positions>
<positions>
..
<position>disable_content</position>
Now to check if you have active modules in there simply use :
$disable_content = (bool) $this->countModules('disable_content');
So now you can use
<?php if (!$disable_content) : ?>
<?php echo $gantry->displayMainbody('mainbody', 'sidebar', 'standard', 'standard', 'standard', 'standard', 'standard'); ?>
<?php endif; ?>

Related

wordpress loop with pagination only showing two pages

I've created a loop with pagination, to show three posts per page. The pagination is only showing two pages of posts, whereas it should be showing four, as there are 11 posts altogether. The code that I'm using is taken from the WordPress Codex. I'm only just starting out with WordPress development and PHP, so my knowledge is still quite basic. Any help would be appreciated. This is what I have at the moment:
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'posts_per_page' => 3,
'paged' => $paged
);
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<p><?php the_title(); ?></p>
<?php endwhile; ?>
<!-- pagination -->
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
<?php else : ?>
<!-- No posts found -->
<?php endif; ?>
Try removing posts_per_page from the query and setting this in the "Blog pages show at most" section in the Reading area in Settings.
Then in your next_post_link(), add the following conditions so it looks like this:
next_posts_link( 'Next Page »', $the_query->max_num_pages );
Note that the first argument can say whatever you want it to say. The second argument is what allows the pagination to work properly. Hope this helps.

Using Meta Description in the right place CakePHP 3

I am trying to use meta tags and description in cakephp 3. It is working so far, but I am facing the problem that I can´t put it in the of my page, because my .ctp files are rendered in my default.ctp
So for example I have my menu, footer etc. in my default.ctp and my page for the faq is in the faq.ctp How can I push those
<?php
echo $this->Html->meta('description','enter any meta description here');
?>
metadescription in the head tag? Do I need a template language like smarty and use blocks?
In layout:
<?php
echo $this->Html->meta('description',$description);
?
in your faq.ctp or faq() method:
<?php
$this->set('description','enter any meta description here');
?
add this in your ctp file (there is NO echo )
<?php $this->Html->meta('description', 'some text here', ['block' => true]);?>
and this line into your layout
<?php echo $this->fetch('meta');?>
see also similar question with title: $this->set('title', 'Title Name'); not working in CakePHP 3.x

Show calendar to specific users based on custom field

I use the calendar plugin from http://tri.be/ on a worpress website for a private website (it’s like an intranet..).
On this calendar I put all the planned meetings, but I would like that the current logged in user can see only the events he/she is supposed to join.
I thought that I can create a custom field, named, for example, “mustjoin” and put there a list of registered usernames as values.
Then do a check on the page.
If the current logged in username is in that list, he/she can see the event on the calendar.. otherwise not.
Something like :
if ( $current_user->user_login == get_field(mustjoin)) { ?>
//CODE IF OK
<?php } else { ?>
//CODE ELSE<?php } ?>
This of course is working when I have only one username in the ACF box, as soon as I put more than one username.. it doesn't work anymore because it is not an Array..
How can I create an array with ACF? what function and how can I interrogate that array?
This is the part of the code I need to show IF the current user username is in the value list ‘mustjoin’
<?php while ($day['events']->have_posts()) : $day['events']->the_post() ?>
<?php tribe_get_template_part('month/single', 'event') ?>
<?php endwhile; ?>
On another forum a guy told me to use this snippet :
function searchForName($name, $array) {
foreach ($array as $key => $val) {
if ($val['nickname'] === $name) {
return true;
}
}
return null;
}
$current_user = wp_get_current_user();
if(searchForName($current_user->user_login,get_field('mustjoin'))):
//CODE GOES HERE
endif;
But it doesn't work..
Thank you for your comment. This is the code, and it works at 99%.
<?php $current_user = wp_get_current_user(); ?>
<?php global $user_login;
get_currentuserinfo(); ?>
<?php $lookforuser = get_field('mustjoin') ?>
<?php if (strpos($lookforuser, $user_login) !== false) { ?>
<?php while ($day['events']->have_posts()) : $day['events']->the_post() ?>
<?php tribe_get_template_part('month/single', 'event') ?>
<?php endwhile; ?>
<?php } ?>
But I need to ask you if this code is "clean" or if I can make it better/faster.
Because when I open the calendar page, I can't see anything.. as soon as I refresh the page, all the events (where I am supposed to join) appear.
How can I fix it? (I tried with different computers/browsers, no changes..)
Thank you.
Thanks to another guy on another website, finally it works at 100%!
I just needed to check the user before the events loop :
<?php $current_user = wp_get_current_user(); ?>
<?php global $user_login;
get_currentuserinfo(); ?>
<?php while ($day['events']->have_posts()) : $day['events']->the_post(); ?>
<?php $lookforuser = get_field('mustjoin'); ?>
<?php if (strpos($lookforuser, $user_login) !== false)
tribe_get_template_part('month/single', 'event'); ?>
<?php endwhile; ?>
Thank you anyway for the right suggestion and help.

Using Wordpress, how can I display posts that are in multiple categories?

I am trying to retrieve posts in Wordpress that belong in two categories. Each post must belong in both categories.
Here is my query:
<?php $myPosts = new WP_Query('category_name=featured+news&posts_per_page=10'); ?>
<?php if($myPosts->have_posts()) : ?>
<?php while($myPosts->have_posts()) : $myPosts->the_post(); ?>
<article>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</article>
<?php endwhile; ?>
<?php endif; ?>
In this example, 'featured' and 'news' are the slugs of two categories. I am using the plus symbol (+) with the 'category_name' parameter in my query to indicate that posts must be in both categories, as suggested here.
For some reason, this isn't working and I'm not sure why. I am getting this error:
PHP Warning: urldecode() expects parameter 1 to be string
It's referencing the query.php file:
wp-includes/query.php
Why can the query not interpret featured+news as a string? I figure I must be missing something. Any help is very much appreciated.
I'm not sure why the plus symbol (+) isn't working but using category__and instead works.
$featuredID = get_category_by_slug('featured')->term_id;
$newsID = get_category_by_slug('news')->term_id;
$myPosts = new WP_Query(array('category__and' => array($featuredID, $newsID), 'posts_per_page' => 10));

Yii file upload is not validating file type

I am validating the file type to be uploaded. The validation rule does not seem to work. I only want to accept jpg files but when I try putting pdf files, it still accepts it and does not give any error. Please help. I don't know what I'm doing wrong.
View:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'document-form',
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
'clientOptions'=>array('validateOnSubmit'=>true), //This is very important
'htmlOptions'=>array('enctype'=>'multipart/form-data'),)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'barangay_clearance'); ?>
<?php echo $form->fileField($model,'barangay_clearance'); ?>
<?php echo $form->error($model,'barangay_clearance'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
Model:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('barangay_clearance', 'file', 'allowEmpty'=>true, 'types'=>'jpg', 'message'=>'Jpg files only', 'on'=>'insert'),
array('barangay_clearance, barangay_status, zoning_clearance, zoning_status, sanitary_clearance, sanitary_status, occupancy_permit, occupancy_status, fire_safety, fire_safety_status', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('document_id, business_id, barangay_clearance, barangay_status, zoning_clearance, zoning_status, sanitary_clearance, sanitary_status, occupancy_permit, occupancy_status, fire_safety, fire_safety_status', 'safe', 'on'=>'search'),
);
}
Controller: (Note: I haven't really changed the controller yet except for activating the ajaxvalidation function and creating an instance of another model)
public function actionCreate($id)
{
$model=new Document;
$busModel = Business::model()->findByPk($id);
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['Document']))
{
$model->attributes=$_POST['Document'];
if($model->save())
$this->redirect(array('view','id'=>$model->document_id));
}
$this->render('create',array(
'model'=>$model,
'busModel'=>$busModel,
));
}
This should work perfectly.
array('barangay_clearance', 'file','types'=>'jpg', 'allowEmpty'=>true, 'on'=>'update', 'on'=>'insert'),
You didn't assign any scenario to model. If model you use in form widget is instance of Document then this:
$model=new Document;
has to be replaced with this:
$model=new Document('insert');
since rule declaration
array('barangay_clearance', 'file', 'allowEmpty'=>true, 'types'=>'jpg', 'message'=>'Jpg files only', 'on'=>'insert'),
says that it will be applied only on "insert" scenario.
I hope it helps.

Resources