Editing certain parts of page template in User mode - php

I have a web page I am working on in WP which needs some customization.
Firstly I have created a page template that will be used over and over again, only changing parts of the content. I am wondering about available options for me when enabling this fact, through the Admin panel in the HTML Editor(if possible)...
Hope my question is clear enough for you all.
Let me add some code to show what I am trying to accomplish.
<div id="header-style">
<?php get_header();?>
</div>
<div id="content">
<div id="about">
//This is what i want to be able to edit
</div>
<div id="features">
//This is what i want to be able to edit
</div>
</div>

Dino:
There are lots of ways you could do this. The main question I would ask you is, who is going to be adding/editing this content? If you're going to have a community of people adding content, the input needs to be stripped and sanitized (to avoid injecting tags or other harmful content). If its just going to be you, then here's the easiest/fastest solution:
Use custom fields. If you can't see them in the post/page edit screen, go to the little tab on the top right of the post-edit screen that says Screen Options (or something like that) and click "Custom Fields".
Once you can see the Custom Fields edit box, you can add as many fields as you want. These are stored as post meta data. You can use the <?php the_meta(); ?> function in the loop to display all of your custom fields.
You can access a specific field by using get_post_meta(). You pass in the postID and the key of the meta field:
<?php echo get_post_meta(get_the_ID(), 'my_key'); ?>
So, for your example, you would add in the post-edit screen:
about: Some text to go in the about section.
features: Some text to go in the features section.
Then, you would access these on your page like so:
<div id="header-style">
<?php get_header();?>
</div>
<div id="content">
<div id="about">
<?php echo get_post_meta(get_the_ID(), 'about'); ?>
</div>
<div id="features">
<?php echo get_post_meta(get_the_ID(), 'features'); ?>
</div>
</div>

Related

Display parent div only if populated with content

Is there a way to only display a parent (wrapping) if it's actually been populated with content?
The reason I ask is in Wordpress I'm using Advanced Custom Fields to create additional text areas on the homepage of the website. The content is added to the page inside divs, like this:
<section class="band">
<div class="wrap">
<?php the_field('services'); ?>
</div>
</section>
If the field is left blank, obviously the markup that surrounds remains on the page and due to the margin/padding they have set on them it leaves a big empty stripe across the page.
I know little Wordpress (and PHP in general), I assume this must be possible? I've had a play around with if/else statements but had no luck.
Can anyone advise on this?
You could do it this way:
<?php if( get_field('services') ) : ?>
<section class="band">
<div class="wrap">
<?php the_field('services'); ?>
</div>
</section>
<?php endif; ?>

Cakephp, adding a view to a sidebar

I'm struggling trying to understand cakephp's views, blocks and layouts.
I need everypage to show a left and right sidebar which content might change. At this moment I have the right sidebar defined in /pages/home.ctp but I'm guessing it would be better to extend that sidebar since it has to appear in everypage. Correct me if that thought is wrong.
Then, I have this view add.ctp for the 'usuarios' table, it practically shows the fields login and password. I want to show this view in the sidebar, but I'm really lost as how to do that.
Thanks in advance.
Lets make this thing easy. Like #patrick said, there is a lots of way.
Start with layout file. Rearrange your default.ctp layout like-
default.ctp layout
<div id="container">
<div id="header">
<?php echo $this->element('header');?>
</div>
<div id="left-sidebar">
<?php echo $this->element('left-sidebar');?>
</div>
<div id="content">
<?php echo $this->Session->flash(); ?>
<?php echo $this->fetch('content'); ?>
</div>
<div id="right-sidebar">
<?php echo $this->element('right-sidebar');?>
</div>
<div id="footer">
<?php echo $this->element('footer');?>
</div>
</div>
Now create elements ctp files as header.ctp, left-sidebar.ctp, right-sidebar.ctp and so on and place them to app/View/Elements.
Your left-sidebar.ctp file may looks like this...
left-sidebar.ctp
// to show login form //
if you just need to show on view.ctp place few logic here for login form.
//end login form//
show other sidebar contents
There are a couple ways to do it, depending on your Cake version. If you're using >=2.1 (which I assume you are since you asked about blocks), then you should try those to see if they work for your setup. The way I usually do things is that if all views for a controller need common markup then those view files would extend a base view within the Controller directory, e.g.
#/View/Posts/index.ctp
<?php
$this->extend('_skel'); //arbitrary filename, I use '_skel' since that makes sense
echo $this->Html->para(null, 'Hello');
#/View/Posts/_skel.ctp
<?php
echo $this->Html->div('sidebar', 'Sidebar for posts...');
echo $this->fetch('content'); // This gets all output from the Posts/index.ctp view
Then all your Posts views which extend _skel will have the sidebar automatically.
Your login module might make sense as an element - something that could be used anywhere in your views.

PHP Variables URL news page

To get it out of the way, I am learning php as I go and I am new to it. I am really trying to get my hands dirty in it on this project to learn and to make my life easier!
I have a scenario, and I would love for someone to help me out through it and point me in the right direction.
My scenario is:
I have a latest news page on my 'static' website.
I am using php includes on the header, navbar and footer for every page.
I am using includes to grab the latest news information I have in assets/news/form/news1.php. This is the following:
<?php
if (!defined("ACCESS"))
{
die ("Don't waste your time trying to access this file!! Please head to the families relief home page and donate!!");
}
?>
<?php
$header = 'Article Header';
$date = 'June 1st 2013';
$url = '/news/articleName';
$body = 'Body in HTML';
?>
I then have another file in assets/news/news1.php containing:
<div id="appeal3" class="row-fluid">
<div class="well span12">
<div class="span3">
<div class="thumbnail">
<img src="/img/news-blank.jpg">
</div>
</div><!-- span3 -->
<div class="span9 appeals">
<p class="app-date"><?php echo $date?></p>
<h3><?php echo $header ?></h3>
<p><?php echo substr($body, 0, 200) ?><span class="readmore"> ...Read More ></span></p>
</div><!-- span9 -->
</div><!-- well span12 -->
</div><!-- appeal# -->
I then use the following code on my news overview page at /news/index.php to display the html with the variables entered:
<?php include("$_SERVER[DOCUMENT_ROOT]/assets/news/news1.php"); ?>
So what this gives me is an overview page, with the news article displayed around a wrapper in overview view.
I then have another page when the overview 'read more' is clicked.
Within this page, I have a full view news article page with a wrapper where I can echo the variables in.
Wha La! That is my news article structure.. Long winded isn't it!
Now, what I want!! I want to be able to include the variables from an article into my overview page and include the 2nd block of code above as the template. I then want the articles to fill out the variables. However, I have 5 articles on this page with identical variables. What is the best and most efficient way to do this??
Secondly, I have a full-view article page. How can I use this page as a template, and change the php it gets it's variables from. But, I don't want to create a new php page every time I have a new article.
What I had in mind, is something like the following:
domain.com/news/article/index.php?news1
I have been reading up on passing variables in a URL. I want to expand my knowledge on this. Could this be the solution to my problem. My issue is that I have NO idea how to go about this? Can someone please lecture me to solve this and hopefully teach me a little in between!
Thanks!

Dynamic data in header in a symfony project

I have a Symfony 1.4 project. As you know the Template layout is defined independently, in the apps' templates' folder and then it is universally applied to all other templates. My layout is very simple, something like this:
<div id = "header">
</div>
<div id = "content">
<?php echo $sf_content ; ?>
</div>
<div id = "footer">
</div>
$sf_content, as most symfonians would know, essentially spits out the template for whatever web page is being viewed at the moment. If I needed some specific data for my header, such as logout, logo etc, I would simply include it within my header. THis works great because it is static in nature. The challenge I am facing is how I can include data that is dynamic in nature and specific to a page within the header tag because the UI demands that I include it there.
For instance, one of my webpages requires user specific data to be loaded in a dropdown/select menu. This is dynamic and could range from 0 to 100 and is specific to each user. To create this dropdown menu is not an issue, and I already have that part done. The challenge is, how do I load it in the header, given that my data becomes part of $sf_content and that is spit out in my content div.
Is there a way for me to move a specific part of my $sf_content into the header div ?
In your actions.php:
$this->getResponse()->setSlot('someData', 'and its value');
In layout.php:
<div id="header">
<?php echo get_slot('someData'); ?>
</div>
<div id="content">
<?php echo $sf_content ; ?>
</div>
<div id="footer">
</div>
Slots work for this. They can either be set in the action as in the first answer above or you can define them in the templates themselves. This is what I've done where I have dynamic data to define for the layout.
In your example:
<div id="header">
<?php include_slot('some slot name')?>
</div>
<div id="content">
<?php echo $sf_content() ?>
</div>
<div id="footer">
</div>
In the templates you would define the following:
<?php slot('some slot name')?>
//your code goes here
<?php end_slot() ?>
When the layout is then rendered Symfony will place the code between the slot() and end_slot() into the point at which you defined by using include_slot().
For ease I created a global partial that is included in all templates that defines the various common slots used through out the application. There is more info on slots and their usage here

Using columns in Wordpress page that include header

I'm a little bit of a newb when it comes to PHP, but know enough to get around and would like to know if this can be done. sample
I want to break my wordpress page into 2 columns, but also want to have the header in the 1st column.... along with other text. I don't want the header floating over both columns...
The second column will house images only...
is that possible? In my head it makes sense, but then when I try and work it out, I'm just not sure....
And I just got thinking... I have my home page static with the smooth slider on it, so that is now going to cause more grief.
Any help, advice or pointers would be greatly appreciated.
Thanks in advance
This is more CSS/HTML than PHP, however that's fine. The first thing you need to do is understand how to make a two column layout. Then you will need to have the post title in the first column, something like this:
<article>
<div id="col1">
<h1>Post Title</h1>
Lorem ipsum dolor sit amet...
</div>
<div id="col2">
<img src="" />
</div>
</article>
To make this into WordPress you will of course need to add the WordPress Tags:
<div id="col1">
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
</div>
Finally, adding the image(s) on the right. It can be done easily using WordPress' built in functionality, if you only need one image: (Note you will have to add something in your theme's functions.php file as per the WordPress Docs)
<div id="col2">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
}
?>
</div>
To add multiple images, it gets more complex and you'll have to start looking for a plugin to achieve that goal.

Categories