I want to provide this option in Drupal that users be able to put comment on each paragraph of an article beside putting comment on the whole article.
I use explode command to make an array which contains paragraphs:
$paragraphs = explode("<p>",render($content));
In order to put comment for the whole article I write:
print render($content['comments']);
I am trying to find the file where $content is defined, so I can add another array like $content[]['paragraphcomments'] for comments for each paragraph of an article. Does anyone know in which file $content is defined. Also does anyone have any suggestion?
Instead of print rendering the whole content in one step, you need to print render each field separately.
See this drupal answer for details.
Then if you have a particular field that needs to have a different way of rendering you might try creating a template for the field. see theme hooks on the naming conventions for creating this template.
Related
I can change a title by placing the next line into my template:
$doc->setTitle('my new title');
But is any method to modify an article's 'fulltext' in the same way?
Short answer: yes, with a content plugin.
Details
If you can use $doc->setTitle(), I assume that somewhere before that line there's a line which says:
$doc = JFactory::getDocument();
But the document refers to the whole page, so you're actually setting the html <title> tag.
If you want to change an article text, you're dealing with the result of a specific component, i.e. com_content, which is only a part of the whole document.
There are more than one ways to change it.
Change the whole page content
If you want to change the whole page content in your template, you have to do:
$buffer = $doc->getBuffer();
// ... do whatever modification to buffer
$doc->setBuffer($buffer)
Quite simple to do, but it's not a good idea to put this kind of logic in the template (if you ever want to change your template, you'll have to copy / paste the code).
Use a system plugin to change the buffer
The core of this solution is the same as before, but you put the logic in a system plugin, hooking on the onAfterRender event. You get the buffer, you modify it, you set the buffer.
Good solution for very simple modifications and/or if you want to make sure the modifications applies to any part of the page.
Use a content plugin
A content plugin applies only to articles body, product descriptions, and similar text parts.
You should use this if you want only to modify those parts.
I know that this is bit of a conceptual question but after searching alot i am unable to grab the concept that is why i am hoping to get help from this platform.
I often need to change some markup or styles etc on the elements let se in $page['highlight']
When i var_dump any variable in any .tpl file it gives just a basic information. Let say i have to add additional div element in a content that is set to be rendered in $page['highlight'] region. What would be the way that i grab that element and alter it before it rendered on page.
The same case happend to me when i made a page view in drupal. I had a custom .tpl file which was displaying the view and all records were getting displayed by a single variable like
print $rows
I am not specifically asking for the code but it would be helpful to many other users including me to grab the concept with a little example.
Thanks alot.
There are different ways to do the same things you say.
In views, you can customize your results by Theme: information option. Is's in the bottom-right part of the view configuration. Here you have the option to create a new file and customize the view results. In your case you need to create a new Row style output: (it contains the value of $row variable).
Here is a tutorial: https://www.ostraining.com/blog/drupal/views-templates/
About the $page variable. You have different options depends on the context. For example if you need to add a in all pages, the best option is to edit the page.tpl.php in your theme.
Another option is to change the template.php of your theme, but only if you need to add html in some cases.
Hope it helps.
Regards.
Here is an image of my comment format: http://oi40.tinypic.com/8w07jt.jpg
The hyperlink to each individual comment is the date and time with the url in the format of, for example: /nottingham/#comment-184
After going through my comment templates I found that these two functions do the following,
get_comments_link : Retrieves the link to the current post comments
AND
comments_link: Displays the link to the current post comments
The problem is I have no idea where to include these functions so it creates a hyperlink to every comment within every comment. Once this link has been created I'd also like to assign a div to it so I can format it to be in the bottom right corner of each comment.
My final goal is to manipulate the link so rather than the comment link itself it will automatically work in the facebook.com/sharer.php which I feel I can do myself once I figure out the previous part. Essentially it will be a share on facebook button, but I have found no plugins which do this yet and thought describing it as a hyperlink would be an easier way to explain what I'm trying to do.
Elsewhere I've been told the following: but not sure how to implement this...
In functions.php I'd add a 'get_comments_link' filter to return the desired link, including the tag you need. Note that this is a filter, not a function. There is function with the same name, but it's part of WordPress itself. Use the filter to add a div to the existing link. Then style the new div to position it where you want it. I notice that the Photoria theme repositions the Reply link, which is coded at the bottom but displayed at the top. In the same way, your new will be coded at the top but displayed at the bottom. Also see add_filter in the Codex. Add the new div to $link before returning it. The new div will need a class attribute so that you can work with it in CSS to make it look the way you want.
I hope I've made the question clear, please ask if I haven't. Thanks in advance!
You need to edit your comment template in your Wordpress theme.
Default is located in /comments.php
Some more informations could be found here : http://codex.wordpress.org/Function_Reference/comments_template
Finally answered it myself, the code used to display the comment link was:
<img src=""
Which was inserted in my comments template file within my comments body div which I then put into another div so I could format it itself to where I wanted it positioned.
Currently in the process of making the link automatically share through the facebook sharer...
Hope this helps anyone with the same problem.
I'm trying to create an auto generated post excerpt from the current page's post content using a function in my theme's header file. The post excerpt will be used as the page's meta description. Can someone give me an idea of how you might go about this once you've got the post content into a string variable?
The somewhat tricky part is that, in order to predict a viable stopping point for the post excerpt, I'd like to specify that the cutoff point be the end of the first paragraph of text.
And for that reason, it does not make sense to load the entire post content into the string I'm using. Can I grab the first paragraph without having to load the entire post content string?
And I'm not certain how to test for that in php. Would regex be the only way?
You can't parse HTML with regex. Posts are stored formatted in HTML (i.e. <p></p> <br /> etc).
I'm also assuming you are implementing this on a blog with lots of existing posts.
What you can do is:
Retrieve the post and run it through an XML Parser. Grab the first paragraph. This is incredibly expensive for such a simple task.
Use a quick tag in the post to denote the excerpt stop point, strip HTML from everything to the left of it. Similar to the <-- more --> tag.
Store an excerpt with each post, I believe WP already has facilities for that.
It would be much, much easier if you could simply select the excerpt without having to do any additional fiddling in order to use it, so the time to handle it is when a post is saved.
So, if you can initially select each post, parse it, get the first paragraph and insert it into another table, then have your plugin do that when each new post is saved, you're home. Naturally, you'd update the same if a post was edited (making that optional).
Just please, please, please don't introduce a plugin in WP that uses regex to parse a context free language. Its just asking for trouble.
I am trying to change the HTML that is output when I print $search_box in my page.tpl.php file. I understand the process of overriding something in drupal but I have no idea how to do it for the search box.
This is the only bit of information that I have found that seems related but I don't known how to apply it to solving my problem: http://api.drupalecommerce.org/api/function/search_form/6-4
You should check search-block-form.tpl.php and search-theme-form.tpl.php located in modules/search, as well as their preprocess functions template_preprocess_search_block_form() and template_preprocess_search_theme_form().
You might also be interested in this post and the pages linked from there.