I convert a HTML template to wordpress theme and I've a trouble.
I just want to add some right padding to reply comments.
The wp_list_comments() function add child comments into a div with parent comment.
Wordpress function output:
<div>
<div class="comment-1"> // comment 1
<div class="comment-2"></div> // reply 1
<div class="comment-3"></div> // reply 2
</div>
<div class="comment-4"> // comment 2
</div>
What I need for my template is:
<div>
<div class="comment-1"></div> // comment 1
<div class="comment-2" class="reply"></div> // reply 1
<div class="comment-3" class="reply"></div> // reply 2
<div class="comment-4"> // comment 2
</div>
You need to customise the comments loop using comments.php in your theme. The code is somewhat extensive requiring use of your functions.php file.
Check out this WP Tuts article on making use of the files to override the default output.
Related
I'm using SilverStripe 3.5.3 I want to customize content ($Content) of the Security/login page. How do I do it?
You can also modify the page template by putting a template file named Security_login.ss in your templates/Layout directory.
The contents of one i've used in a previous project is:
<div class="row security-spacer">
<div class="large-12 columns">
<h1>$Title</h1>
<div class="typography">$Content</div>
<div class="row">
<div class="large-6 columns">
$Form
</div>
</div>
</div>
</div>
You can also create templates for
Security_changepassword.ss
Security_lostpassword.ss
Security_passwordsent.ss
You could extend the LoginForm class and create your own LoginForm anyway you like. You could base it off of the MemberLoginForm.php class.
Check out this article here which may help.
I know the OP asked specifically for its theme, but in case someone wants to know how to do it on the code side of things, you can use the request object to determine that, like this:
/mysite/code/Page.php
public function anyMethod() {
$value = 'default';
if (Controller::curr()->getRequest()->getURL() === 'Security/login') {
$value = 'something else';
}
return $value;
}
(On SilverStripe 4.1.0, anyway)
I'm writing a Stylish user style sheet, and am trying to see if something is possible. I am customizing a page that has a structure like this:
<div class="main">
<div class="someExtraLayers">
<div class="page">
1
</div>
</div>
<div class="someOtherLayers">
<div class="post">
blah blah
</div>
<div class="post">
foo foo
</div>
<div class="post">
bar bar
</div>
</div>
</div>
Where 'someExtraLayers' and 'someOtherLayers' indicate a few levels of divs inside divs. I'm not fully replicating the page's structure here for brevity's sake.
I have this in my user CSS:
div.post:nth-child(1) {
display:block !important;
}
Essentially, I'm making visible the first post element, and this does most of what I want to do. The thing I want to add is that I only want to make that element visible if the content of the page class is 1. If it's not 1, then I don't want to display the first post element.
CSS doesn't seem to offer conditionals, or boolean ANDs, that work this way. But I'm still new-ish to CSS, so I might be missing something. If I have to use a Greasemonkey script instead, I'll do that, but I was hoping there's some CSS trickery that will let me accomplish this.
Stylish cannot do this because Stylish just injects CSS and CSS does not have a selector for text content.
To do what you want, you will have to install Greasemonkey (Firefox) or Tampermonkey (Chrome) and then a userscript can set that visibility.
Assuming that div contains only 1, then something like this complete GM/TM script will do what you want. It uses the awesome power of jQuery selectors.
You can also see a live demo of the code at jsFiddle. :
// ==UserScript==
// #name _Show the first post on page 1
// #include http://YOUR_SERVER.COM/YOUR_PATH/*
// #require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// #grant GM_addStyle
// ==/UserScript==
var pageHasOne = $("div.main:has(div.page:contains(1))");
pageHasOne.each ( function () {
var jThis = $(this); //-- this is a special var inside an .each()
var pageDiv = jThis.find ("div.page:contains(1)");
if ($.trim (pageDiv.text() ) == "1") {
//--- Show the first post div. !important is not needed here.
jThis.find ("div.post:first").css ("display", "block");
}
} );
Given the logic that jQuery javascript must use, we can see part of the reason why CSS doesn't attempt to provide selectors for this. It's beyond mission scope for CSS, but the kind of thing that javascript was made for.
Also note that this is for a static page. If the page uses AJAX for its content, the logic becomes a bit more involved.
CSS can not access HTML content.
To solve the problem, you will also need to add a class so CSS can "see" it:
HTML:
<div class="main one">
<div class="someExtraLayers">
<div class="page">
1
</div>
</div>
<div class="someOtherLayers">
<div class="post">
blah blah
</div>
<div class="post">
foo foo
</div>
<div class="post">
bar bar
</div>
</div>
</div>
CSS:
.one .post:nth-child(1) {
display:block !important;
}
I would like to know how can I define a post template and adding automatically the html layout when we are creating a post?
Do I have to use custom fields?
For example:
Post content:
Title
Description 1
Description 2
With links and social media
Html layout result:
<h1 class="work-title">Title</h1>
<div class="description">Description 1</div>
<div class="description">Description 2</div>
<div class="details">With links and social media</div>
</div>
Thanks
You could alter the output of the function the_content() by using (in functions.php) something like:
function alter_content($content) {
// Alter the $content variable here
return $content;
}
add_filter( 'the_content', 'alter_content', 6);
Which will alter the content before the paragraphs are added. And if you don't want paragraphs at all use:
remove_filter('the_content', 'wpautop');
Check out the codex page on apply_filters() for more info on the function.
I have created the following shortcode code:
<?php
function box_handle($atts, $content='')
{
extract(
shortcode_atts(array(
'size' => 'narrow'), $atts));
return '<div class="box '.$size.'">'.$content.'</div>';
}
add_shortcode('box', 'box_handle');
?>
And this:
[box]<h2>Title</h2>
Content
Content
Content[/box]
Gives me
<div class="box narrow"><br>
<h2>Title</h2>
<p>Impingement<br>
Content<br>
Content<br>
Content</p></div>
<p></p>
The problem here being the extra <br> at the top, after the opening tag. Keep reading and you will find a second error, the unwarranted <p></p>... How can I fix this? Naturally, I have gone through the HTML code in the admin panel and tried to weed out any new lines and other things around the markup which may cause this but I have not been able to fix it.
There is a plugin, which should let you disable the wpautop()-function on a per-post-basis. I didn't tested that plugin yet.
http://plugins.trac.wordpress.org/wiki/TextControl
While I was creating my custom template for node, I found out that Drupal adds extra html.
so I changed page.tpl.php like below to test
<div style='height:300px'>
<?php print render($page['content']); ?>
</div>
and then changed node.tpl.php to
hello
the output is:
<div style='height:300px'>
<div class="region region-content">
<div id="block-system-main" class="block block-system">
<div class="content">
hello </div>
</div>
</div>
</div>
where do all those extra tags come from?
I actually expected <div style='height:300px'>hello</div>
drupal_render() can be used to render so called renderable arrays. These are self-contained, they tell render() which theme function/template to use.
Try dpm($page['content']), that should then have a '#theme' key that contains that information.
Nice one with the dpm.
To print the h2 and body you could write something like this in the page.tpl.php.
<?php print render($page['content']['system_main']['nodes'][1]); ?></div> ?>