Before I made the switch to Drupal (previously just static HTML), I had a div title in my header that changed depending on what page the user was on using the following code:
ABOUT PAGE
<?php
$title = "ABOUT US</span>";
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/includes/header.php";
include_once($path); ?>
The reason this worked, however, was because I was using static HTML... which means I had every page set to use its own Index.PHP, located at (for the About page, for example) public_HTML/about/index.php. Therefore, I could edit each page individually to my liking by editing its respective Index file...
Now, with Drupal.. instead of having so many Index.PHP files like I did before (which was messy IMO...), I want to have every page use the same page.tpl.php (with the exception of the front page, which uses page--front.tpl.php).
Can I somehow modify the above PHP code to display a different title using IF statements depending on what page the user is on?
For example... (I have no idea how to PHP code so this is just to give you experts an idea of what I would want..)
Ifpage=about, $title=About Us;
Ifpage=contact, $title=Contact Us;
Could this code all be in the same page.tpl.php?
Thank you so much!
Drupal 7 has a title field for each content type. Why don't you use that?
It shows by default and you can change it for every node.
It is this code in your template file.
<?php print render($title_prefix); ?>
<?php if ($title): ?>
<h1 class="title" id="page-title">
<?php print $title; ?>
</h1>
<?php endif; ?>
<?php print render($title_suffix); ?>
$title_prefix (array): An array containing additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template.
$title: The page title, for use in the actual HTML content.
$title_suffix (array): An array containing additional output populated by modules, intended to be displayed after the main title tag that appears in the template.
See https://api.drupal.org/api/drupal/modules!system!page.tpl.php/7 for all the variables available in your page.tpl template file.
If you want to style one part different from the other you could use an extra field for it.
Or if you need to do something with the value (I wouldn't suggest this!!!).
switch ($title) {
case "About Us":
// Do something with the title
break;
case "Contact Us":
// Do something with the title
break;
case 2:
// Do something with the title
break;
}
Here's a simple approach:
Add a new field for the content type
Call it title2
Render the two fields
Use css to inline align them and add styling
Here was my solution since I am unable to position a Drupal-based title block right next to a non-Drupal based logo DIV..
I created a div called .headertitle and positioned/styled it how I want.
My header.php is an PHP include file which is called by each page and the headertitle has a PHP condition..
<?php if(empty($headertitle)) $headertitle = "ASK REAL QUESTIONS, <br><span class='white'>GET FREE ANSWERS.</span>";
echo $headertitle; ?>
That way, if no text is declared for the .headertitle, it takes the default form of "ASK REAL QUESTIONS, GET FREE ANSWERS."
...Now, I had to figure out a way to actually declare text for the .headertitle depending on what page I was on...
I did this by using a custom template for each page (node) by using this file.. "page--node--nodeid.tpl.php".
So, for my ABOUT US page, I created a tpl.php file called "Page--node--7.tpl.php".. for this page, the 7 is the nodeid which is easy to find.
Then, I added the following PHP code to declare text for the .headertitle specifically on the ABOUT US page which looks like this...
<?php $headertitle = "ABOUT<span class='white'>.US</span>"; include('includes/header.php'); ?>
DONE AND DONE.
I'll do that for each page. :)
Related
In the midst of Customizing my new Wordpress site I would like to add next and previous portfolio post buttons to the single portfolio post page, and I've found that I can easily do so by pasting the following code:
<div><?php previous_post_link('%link', 'PREV'); ?> | <?php next_post_link('%link', 'NEXT'); ?></div>
Somewhere in the single-flv_portfolio.php page.
The only problem with this solution though is that I'm only able to place the links/buttons in the "portfolio frame" so to speak, and not in the actual content of every single post, which I would like to, for layout purposes.
I've tried pasting the same code within the contents of a portfolio post, using the backend editor, but to no avail. Wordpress, or my specific template (Wizard) seams not allow me using php at all - not even for something small like echoing out the current year in a dynamic copyright function.
Is it possible to maybe create the next and previous portfolio post functions in a custom .php-file, and then call them with an html anchor tag, and if so, how would I go about doing that?
Try something like this in your functions.php file:
function my_next_previous_link($content) {
$content .= 'some html here';
return $content;
}
add_action('the_content','my_next_previous_link');
I am relatively unfamiliar with Wordpress and I am creating a custom theme for a client. I would like to either display or remove the main menu depending on the page type. I have researched several options like removing the navigation from header.php and referencing it separately and also making the menu conditional which is preferable.
I have a custom page type in my theme called 'landing page' on which I would like the menu to be never be displayed, though it will be on every other page. Ultimately there will be a lot of these and I would rather I didn't have to intervene.
I would rather not duplicate my header.php file but I can only find reference to displaying the menu conditionally like below by page name or ID which seems ridiculous.
<?php
if (is_page('contact')){
<?php include(TEMPLATEPATH.'/headerA.php'); ?>
}
elseif (is_page('gallery')){
<?php include(TEMPLATEPATH.'/headerB.php'); ?>
}
else {
<?php include(TEMPLATEPATH.'/headerA.php'); ?>
}
?>
Rather than including files as above, I will put the whole thing into my header and just make the navigation conditional. Does anyone know how I should approach this using my custom page type landing page rather than by page name so every page created with that type will never have a menu?
Thanks
Are you talking about a Custom Post Type (CPT) or a page called landing-page?
They are completely different. See http://codex.wordpress.org/Post_Types
In any event, this will work for a custom post type or a page:
if ( !is_singular( 'custom-post-type-name-or-page-slug-here' ) ) {
get_template_part('menu');
}
It says: "If this page is not a single page or a CPT, load the file menu.php from the theme folder."
See also http://codex.wordpress.org/Include_Tags:
The get_template_part() tag includes the file {slug}.php or
{slug}-{name}.php from your current theme's directory, a custom
Include Tags other than header, sidebar, footer.
I'm trying to figure out how to hide the title of my nodes in drupal... I don't wanna use another module, I just want to change something in the node.tpl.php...
My attempt was to ask if the title is "" and if not, it should just post the title... I've did it like this:
Damn won't work to show the code here, got it in jsfiddle now: jsfiddle.net/8d6FR/
But it doesn't work. Has someone some suggestions why it won't work?
You code looks almost right, I've changed it slightly just to make it easier to understand:
<?php if($title!="<none>"){ print render($title_prefix); ?>
<h2<?php print $title_attributes; ?>><?php print $title; ?></h2>
<?php print render($title_suffix);} ?>
If that is not working then add the code:
var_dump($title!="<none>")
That will let you know how PHP is evaluating your if statement and will allow you to do some further debugging.
PHP in a JSFiddle, that is not gonna work :)...To hide your node titles you'll have to modify your tpl file indeed, or create one if it you need it for a certain content type or node, or manage the display of your nodes within Drupal admin. You may need Title to replace title field with a regular field in order to hide it with the "Manage display" interface or Display Suite.
Find your node.tpl.php or page.tpl.php (depends on your theme) using Theme Developper, and find something like print $title.
i am using joomla 3 for a web site, i don't use any content in the main page but the system output is on because i need to output contents on other pages of the site. the problem is i have a space in the middle of the page where normally the content comes. i know where this comes from but i have to disable it if there is no content on that selected page. i tried to check the
$this['template']->render('content')
which is actually used to render the specific content. but i was not able to use it in a conditional if. so i need to check if the loaded page has a content output. has anybody a idea how i could do that?
PS: i dont want do this with css.
You may check if you are showing the main page and render conditionally:
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
if ($menu->getActive() == $menu->getDefault()) {
$this['template']->render('content');
}
?>
For multilingual site check this link for detecting if you are on the default page:
http://docs.joomla.org/How_to_determine_if_the_user_is_viewing_the_front_page
Just curious... why don't use the <jdoc:type="component/>?
i have a yii site that contains main layout. in this main layout file i have a piece of code that prints the current page's output. here it is:
<?php echo $content; ?>
so the question is how to make other regions on the page?
for example i want to have a banners block, that will be printed out depending on the page. is there a way to write something like
<?php echo $banners; ?>
inside the main layout and this region will be filled with some data returned from a controller?
thanks/
Example
add main layout:
<?php $this->renderPartial('/site/_banners'); ?>
create view file (protected/views/site/_banners.php):
write banners code...