I'm trying to display a Joomla module or a div, but only on specific subpages.
Example: trying to display this
<div><?php echo $this['widgets']->render('module'); ?></div>
Only on www.example.com/products/item1 and other subpages of /products
But NOT on:
www.example.com/
or
www.example.com/products/
I can't find a PHP or JS script to do that, nor is it possible to do it with the native Joomla features.
How to do that?
You can use preg_match on the $_SERVER['REQUEST_URI']:
<?php if (preg_match("/products\/.+/", $_SERVER['REQUEST_URI'])): ?>
<div><?php echo $this['widgets']->render('module'); ?></div>
<?php endif; ?>
The expression /products\/.+/ sees if products is in the url and a slash and some content follows it.
Related
I've got a wordpress page with tabs on it, and I want to show in one of 'em a query of posts from a category.
I've got an active li like: where the tab info is shown
<li class="tab-pane active" id="ert_pane1-4">
All I came up with is:
<?php
$tab-id= getElementById("ert_pane1-4");
echo $tab-id;
if($tab-id =='<li class="active">'){
query_posts('cat=1');
} endif;
?>)
I know this will sound rather easy but I'm a newbie on php but up to learn.
There are some problems. First, endif; is not needed:
if($tab-id =='<li class="active">'){
query_posts('cat=1');
}
Also, getElementById is JavaScript not PHP. This wouldn't work anyway since the page hasn't loaded yet while PHP is running.
In my wordpress site, I have a page that has 3 sections. Every section contains posts from a specific category. I use this wordpress query to get the latest 3 posts in that category and load it in it's section(div). So, for "Novels" section, I use this query:
<? $novels = get_option('of_novels') ?>
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('category_name=$novels&posts_per_page=3'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="sliderunit">
<?php the_post_thumbnail(); ?>
<div class="novelsslidertitle">
<div class="arrow-left"></div>
<img class="cross" src="<?php bloginfo('stylesheet_directory'); ?>/images/cross.png"/>
<?php the_title(); ?>
<h3>رواية</h3>
</div>
</div>
<?php endwhile;?>
and that gets me the latest 3 posts in #novels category. Now, I have some buttons. I want to write some jequery to loop on this category and get previous and next posts, and reloads the new queries content to that #novels div, replacing the old query code in the html using
$("<div/>").replaceWith("// Replace with a function to get the code of new output");
to act as a slider without using pagination and reloading the page? I hope my problem is well declared, I appreciate any helpful clues, links or references.
I don't think $.replaceWith is really what you need here. You would just listen for when the user reaches a certain point, maybe the last in the currently loaded posts, or the second to last, then run $.ajax() or similar query, append that to your #sliderunit and it will make it so you be able to continue scrolling/sliding. By appending and not replacing, you can go back and forth if you want without having to reload anything. If you are concerned about memory management, you could use $.remove() at a certain threshold.
In case you need a little more info on how to do this, start by appending your new data, then using CSS manipulation such as $.animate() to perform the slide effect. You can either use layers to hide things you don't want showing, or I guess you could also call $.hide() on blocks you don't want shown.
I want to add a class to the body tag to all pages EXCEPT the homepage. Right now I have.
<?php body_class('interior'); ?>
But it adds 'interior' to ALL pages including the home page.
What is the best standard way of adding a class to the body tag to all interior pages except the 'home page'?
http://codex.wordpress.org/Function_Reference/is_home
<?php if (!is_home()) body_class('interior'); ?>
Unless you mean http://codex.wordpress.org/Function_Reference/is_front_page
<?php if (!is_front_page()) body_class('interior'); ?>
I think the best solution is write:
<body <?php if (!is_front_page()) body_class('interior'); ?> <?php body_class(); ?>>
In this way you add only class="interior" in all page except the front page, and you can save the class in the front page, otherwise in you use only the fist php code in the tag <body> in home you will not have class.
I have recently installed a new template(more specifically SquirrelTheme - a free template) in my wordpress blog. It happens that I would like to have two buttons on my front page. Let's say button X and button Y. For creating these buttons I use a plugin called "MaxButtons" which allows you to easily create and manage a button and it's functions. After creating the said button, it gives you a shortcode that you can insert in your posts and pages - lets say [maxbutton id="1"] - to display it.
Unfortunately, after editing the template to my liking(removing divs I didn't intend to display), I can't seem to display these two buttons as the template parses plain-text, unlike the pages/posts apparently.
In case you are wondering how I am inserting the shortcode for the buttons, the template can be easily modified through the dashboard, in which I inserted the following in the field that dictates what is displayed on the specific part of my homepage:
[maxbutton id="1"] [maxbutton id="2"]
Like I said before, instead of showing the buttons as intended, I just see exactly what I type in the box.
I believe this is caused by how the template parses the text, as it uses its own function(? - php _e('...')) to echo the text:
<div class="full_content">
<center>
<?php if (squirrel_get_option('squirrel_slidehead') != '') { ?>
<h1><?php echo stripslashes(squirrel_get_option('squirrel_slidehead')); ?></h1>
<?php } else { ?>
<h1><?php _e('We are scope, a design firm in England', 'squirrel'); ?></h1>
<?php } ?>
<?php if (squirrel_get_option('squirrel_slidedesc') != '') { ?>
<h2><?php echo stripslashes(squirrel_get_option('squirrel_slidedesc')); ?></h2>
<?php } else { ?>
<p><?php _e('Newfoundland dogs are good to save children from drowning, but you must have a pond of water handy and a child.', 'squirrel') ?></p>
<p><?php _e('From drowning, but you must have a pond of water handy and a child.', 'squirrel'); ?></p>
<?php } ?>
</center>
</div>
My question is, how can I get it to display the buttons or any other code.
Thanks in advance.
You can call the function do_shortcode() to do the proper shortcode processing on some text.
Example:
echo do_shortcode('This is a button: [maxbutton id="1"]');
I am working on a custom wordpress homepage.
I want that it is loading in a different div in the header.
The header now loads the #content div for every page. But i want to let it load #contenthome div if the homepage loads.
I'm using this php-code:
<?php if (is_page_template('template-home.php')) { ?>
<div id="contenthome">
<?php } else { ?>
<div id="content">
<? } ?>
I'm fairly new to php. so i hope you guys can help me :)
Thanks a lot.
Or this:
if(is_home())
{
<div id="contenthome">
<?php } else { ?>
<div id="content">
<? } ?>
Personally, I prefer writing things in shorthand when it comes to cases like these. Consider also using this to shorten your code:
<div id="<?php echo is_home() ? 'contenthome' : 'content'; ?>">
ADDITIONAL NOTES: If your <body> tag has the Wordpress body_class() added to it, you can pretty much target individual pages with CSS, even when they're using the same template. The homepage, like any other page, will have a unique body class applied that will then allow you to target that particular page.
So if your issue is simply a matter of being able to target any given page regardless of template with CSS, you won't necessarily NEED to apply any unique divs to your page. For example:
<style type="text/css">
#content{display:block;}
.home #content{display:none;}
</style>
This will hide the content div only on the homepage. It's probably not what you want it to do, but you can see how the page itself is being targeted to override the default behavior.
UPDATE: As per your latest question, if you need another particular page to use that conditional, use is_page() like so:
LONG CODE:
if(is_home() || is_page('posts_page_title'))
{
<div id="contenthome">
<?php } else { ?>
<div id="content">
<? } ?>
SHORTHAND:
<div id="<?php echo is_home() || is_page('posts_page_title') ? 'contenthome' : 'content'; ?>">
If you prefer, you may also use is_page('posts_page_ID') or is_page('posts_page_slug'). Play around with it and see what works best for you. More information here: http://codex.wordpress.org/Function_Reference/is_page
With reference to this post Try this one....
$pagename = get_query_var('pagename');
if ($pagename = 'template-home.php') {
<div id="contenthome">
<?php } else { ?>
<div id="content">
<? } ?>
it seems like you already created a file in your theme just for the homepage and you called it template-home.php
from this point you have two options:
1) you can just define a constant (or variable) and decide what div to use only when it is defined; if you will use a variable remember that in header.php you are in fact inside a function (get_header) and you will need to use global to have access to it
2) if you foresee any other differences between the structure of the header between the main page and the rest of your wordpress you could use another file for the header. to do this, in your template-home.php file give a parameter to the get_header function, like get_header('home')
if you do this header-home.php will be loaded instead of header.php