Drupal: How to override Advanced Forum topic list for one specific forum term - drupal

I'm using Drupal 7, and have the Advanced Forum module installed.
However, I want to show some Ubercart products in one section of the forum, called the Marketplace to make them more visible, and since users will be able to add their own products.
However, obviously in this section I want to show the forum topic list differently, including the price and other such fields.
Is there an easy way that I'd be able to do this, perhaps using Views? I'm really at a loss for what to do.

You should be able to just create a new View with a page display that displays things like you want them and then set the URL for the view to be the URL that is currently being used for the forum listing you want to override, so that the links to it still work without any additional work.

First of all, you should override the page template for one specific term by creating a new page like so:
page__forum_TERMID
To go more into details about what you need to show in this custom page, you may need to install the Devel & Theme Developer modules.
With Theme developer you will be able to inspect your Drupal output on various parts of the page in order to find out either which preprocess function or which template it originates from.
With Devel you will be able to output some of the variables you may need to act upon in order to generate your custom layout.
I would advise you to look at the implementation of the [Advanced Forum More Styles](http://drupal.org/project/advanced_forum_more_styles) in order to see how you could create your own Advanced Forum Style, which basically means a folder where you can store the various custom templates that will override the Advanced Forum templates.
Recently, I did something similar to what you're looking to achieve, I created a custom module to hold the various preprocess functions and that module contained a styles folder which was declared like so:
function YOURMODULENAME_ctools_plugin_directory($module, $plugin) {
if ($module == 'advanced_forum') {
return 'styles';
}
}
If you look at the styles in the AF module, you will see that they only override a few templates, so you may have to find the template you're looking for in the base style such as the "Naked" style.

Related

WordPress Left Navigation

This may be an odd question. I'm working on a website someone else built in WordPress. My understanding of the left navigation within the dashboard is that there are some default items that are there upon install like [pages], [posts], [plugins], and to get additional items to show up here you need to install a new plugin.
This site I'm working on has a few options in the left navigation [team members], [services] which do not appear to be tied to any particular 3rd party plugin.
In fact, it looks like they've used the plugin "Advanced Custom Fields" to create their own functionality so their users could easily add/remove team members from a custom built slider.
My Question
How do you get your own tab to show up in the dashboard's left navigation? Can you do this within a child theme, or do you need to modify the core WP files? Is there a particular folder or some documentation anyone could direct me to where I might learn more about how this is being connected behind the scenes?
Thank you kindly in advance.
I'll preface this by saying:
Never ever ever modify Core Files!
Whew! Now that that's out of the way, there may be a few plugins that do this for you, but I'm ultimately unfamiliar with any. The typical way to add Admin Items is with the add_menu_page() and add_submenu_page() functions. They're relatively straight forward to use.
Also, as a side note, when you add a Custom Post Type with register_post_type() (like what ACF does) there are options to add it to the menu, as well as what you want the labels and menu names to be.
If you're adding a Custom Post Type (like Team Members, Books, etc.) you'll almost certainly want to make use of the labels and show_in_menu arguments when you call register_post_type() to get the admin menu to show up. However, if you need to link to arbitrary URLs or custom dashboard pages, you'll want to make use of the add_menu/submenu_page functions above.
For instance, here's a simple snippet that will add a Stack Overflow link to the menu, you can drop this into a child theme, plugin, Must-Use plugin, etc:
function stack_overflow_admin_link(){
echo '<script>window.location.href = 'https://stackoverflow.com'; </script>';
}
add_menu_page( 'Stack Overflow', 'Stack Overflow', 'subscriber', 'stack-overflow', 'stack_overflow_admin_link', 'dashicons-external' );
Hope this helps!
Also I'll elaborate a little bit on my warning! Never ever modify core WordPress files. They will be overwritten with each and every WordPress update. WordPress is relatively well thought out and has countless Action Hooks and Filters that let you inject, modify, remove, and otherwise manipulate data and the user experience without ever touching core files.
As an example, take a look at this screenshot:
I'm currently rebuilding a software suite from the ground-up using WordPress, but the standard WP Admin interface doesn't make sense in many of the contexts we need it, so our interface (a work in progress) looks like this, and it's all handled by a Must-Use plugin and touches absolutely no core files, it just uses clever manipulation of the hooks and filters available throughout WordPress

Add dynamic content to a WordPress Page

I want to know the most elegant/best practice way to do the following:
Let's say I have some PHP that returns a string (today's weather, for example). I want to be able to include the string within a WordPress Page, but not by using a plug-in to allow PHP within a Page.
So for example:
This is content of the page that is editable via WordPress pages.
Today's weather is THE_WEATHER. This bit is also editable, but as
an editor I can't edit the PHP that just told us what the weather
is, the developer does that.
What is the best practice way to do this (preferably without using plug-ins)?
Offhand, it sounds like you want to define a shortcode that lets you invoke the PHP function you're talking about and insert its result into a page/post. This pretty much means that you're writing either a (very simple) plugin or you're incorporating the shortcode definition into the functions.php file associated with a theme (which can be a simple child theme of the one you're using).
Which to do probably depends on whether or not you're likely to change themes (if it's just one site) or whether or not you need to do the same thing on different sites that can have different themes. If either is the case, then you should write it as a plugin; otherwise you can just make it part of your theme.
Consult the Codex to learn how to define shortcodes.

WordPress Plugin Development Idea? Is this possible? Am I on the right track?

I'm very new to WP development. I host a website which needs a list of trails (hiking, biking, etc) and I'd like to write a WordPress plugin to do it.
Can someone please tell me if I'm taking the right approach, and if what I'm proposing is possible.
I'd like the site to end up with an auto-generated and filtered index at http://example.com/trail-guide, and the discrete trail info pages at http://example.com/trail-guide/trailname. This data would all be stored in a single database table holding info for each trail, with an admin page for adding, editing, and deleting entries from here.
Is a WP plugin the best way to go about doing this, or should I be looking at something else?
From the way you're describing, your best bet would be to Register A Custom Post Type. This can be done by adding to your existing theme's Functions.php file, or by creating a plugin.
If you don't plan on changing themes, my advice would be to just hardcode everything into your functions.php file. Otherwise, creating a plugin for this particular job would be the safest alternative.
Using this functionality in tandem with Custom Meta Boxes and Custom Taxonomies will allow you to keep everything organized within the Wordpress Framework with your own special data.
This means that these new posts can also be queried at any time through the standard Wordpress Loop or search box.
If you are uncomfortable with writing your own functions to extend your existing framework, you might want to look into some plugins like GD Custom Posts And Taxonomies Tools to manage your own.
Hope this helps.

Drupal 6: Drupal Themer gives same candidate name for different type of content types

I'm a drupal newbie...
I have different type of contents like News, Events, etc. and their content is different. News detail page has title-content text-date. but Events detail page has title-date-content text-location-speaker-etc. So I need different layout page for these different types. So, I enabled Drupal Themer to get a candidate name. for events page, it gave me page-node.tpl.php and it gives same for News page as well :( how can I separate these pages? I expected sth like page-event-node.tpl , but no... :/ Drupal Themer also give unique candidate name for event page like page-node-18.tpl.php but it doesnt mean anything since I can not create a general layout for all events by this node name. :(
Appreciate helps so much!! Thanks a lot!!!
While using different node.tpl.php files as suggested by monkeyninja (+1) would be the 'normal' way, you could add the functionality you want by adding page template suggestions based on node type yourself, in a preprocess_page function within a custom module/theme:
function yourModuleOrTheme_preprocess_page(&$variables) {
// If this is a node page, add a page template suggestion based on node type
if (isset($variables['node'])) {
// Build the suggestion name ('.tpl.php' suffix will be added by the theming system)
$suggestion = 'page-type-' . $variables['node']->type;
// Add to end of suggestion array, thus keeping the fallback to other suggestions,
// if this specific version is not implemented by the theme
$variables['template_files'][] = $suggestion;
}
}
With this in place, you should be able to add e.g. a 'page-type-event.tpl.php' file, which should be used for all event node pages.
(NOTE: You'll need to trigger a rebuild of the theme registry after adding that function to get it recognized by the system)
I'm not familiar with Drupal Themer, but a slightly different approach would be to work with the node templates to style the content and use something like the excellent Context module (and possibly Panels module) to change the layout of any additional information on the page (eg the blocks).
To theme the different content types using node templates, just create templates based on node.tpl.php in the form node-content_type.tpl.php. So you'd have a template for your events nodes called node-events.tpl.php.
You could then define a context using the Context module that reacted when a page of the events content type was displayed and select which regions/blocks you wanted displayed.

Theming Drupal book hierarchies

I'm just getting round to converting our static HTML website to Drupal. Our website is currently structured into sections, each section having a header, then a list of sub-sections below (for an example see http://www.eurosafeuk.co.uk/services/).
This ties in very nicely with Drupal's "book" module, but I need to customise the display of child pages; by default they're printed as an unordered list of page titles, whereas what I need is to output:
A teaser image for each page
The page title
The page summary
I've looked through the .tpl files, and found that the children are stored in a $tree variable (already HTML formatted). My question is: where do I start if I want to modify this? Does anyone know of a pre-existing module that would do it, or do I need to dig into the code?
Instead of using the Book module which is specifically for a book structure, you might want to look into modules that are made for your case. I haven't looked very well but the Node Hierarchy module might be useful for you. . Here is an excerpt from its project page:
... allows nodes to be children of other nodes creating a tree-like hierarchy of content. The module offers:
1-Click creation of hierarchical menus
Hierarchical breadcrumbs
Automatic hierarchical urls using Pathauto (and token module)
(eg: q=aboutus/history/beginning).
Automatic creation of hierarchical menus if desired.
Optional Views integration.
Optional Node Access integration.
If you want to theme nodes in specific sections in different ways, it's probably a good idea to make separate .tpl files for every section. The way you name those .tpl files makes them applicable to nodes in a certain section.
Get the devel module, and turn on theme developer. This will tell you the template or function which is used to build the HTML and what templates you can create to override it.

Resources