Concrete5 - avoiding duplication in multiple page lists on the same page - concrete5

Apologies if the title is a bit confusing, but this is a problem specific to the CMS Concrete5.
I am working on a news/media related site, which consists of a main page which has 3 seperate pagelist blocks, with a layout as shown in the mockup attached.
For a page to appear in the featured pagelist (highlighted green), it needs to have the page attribute is_featured set to true. The 6 block pagelist (highlighted in red) is set to show ALL pages, including featured. Both pagelists are set to order by date, with the newest showing first.
The problem I'm having, is that when a content writer publishes a new page that is featured, I get immediate duplication with the same page listed in the top left of the 6 block pagelist. Given perhaps a day or so, as new 'non-featured' content gets added, the 'duplicated' page issue becomes less of a problem as it moves down the list, and onto the 2nd page (I have pagination on for the red block).
I'm using the standard Concrete5 pagelist block, and have custom templates which are just view.php files for the various lists (featured, 6 pages and sidebar list).
To remove the duplication, I tried adding some code in the view.php of the 6 pages template which would 'filter out' any featured page published in the last 24 hours. Whilst this does work, what I found was that I was then the 6 page pagelist would then show just 5 pages, and an empty gap for the 'filtered out' page.
My question is, is there a clean and better way of preventing duplication across pagelists? I don't want to have to set pagelists to only show certain categories (thus having no overlap whatsoever), but there must be a way to implement something that takes this particular issue into account?

In your "6 item pagelist" Page List block custom template, add the following code above your foreach ($pages as $page) {...} loop.
$list->filterByIsFeatured(false);
$list->setItemsPerPage(6);
$pagination = $list->getPagination();
$pages = $pagination->getCurrentPageResults();
What this does is take the existing $list (Concrete\Core\Page\PageList object) and gets 6 non-featured pages from the page results. The options, sorting, and filtering set in the Page List block form should be preserved by reusing $list.
The $list object is set here:
https://github.com/concrete5/concrete5/blob/develop/concrete/blocks/page_list/controller.php#L225

Related

How to get a WordPress template file to insert different images based on the current page?

I have a number of pages (100) which are all build individually in a visual editor (DIVI). They each have a set of 10-15 different images on, inserted into an identical 'wrapper'. Other than the images, the pages are identical - This was my first website and so I knew no better than this approach when I began. As I now understand, I could use a custom page template for these pages to allow scalability/re-design with much greater ease.
I understand how a template.php page could be created that pulls necessary page metadata to populate the title/subheadings etc for each page. I am thinking of writing a for loop to insert each image for the page into the repeating 'wrapper'. However, I am not sure how the template would know which images to pass into this loop based on the page visited?
I had a few thoughts on how this could be done (I am very inexperienced):
a) Re-structure my wp-uploads folder to match my sitemap and get the template to insert all images in the path that matches the slug
b) Upload all images for each page to the page in the back-end (not sure if this is possible) and get the template to insert all images associated with the page in question
c) Get the template to loop through a database table containing all of the image names matched to the page id on which they should be found and only insert those that match the current page id
If this changes anything, all 100 pages are child-pages of pageX and their slug begins with a common word. eg:
mysite.com/pageX/commonword-page1/
mysite.com/pageX/commonword-page2/
Since you have so many pages, I wouldn't use an if statement. The best way to handle this would be to use Advanced Custom Fields and set up an image field to show on the pages post type. Then, in your code, call the custom field and that way every page dynamically show their respective image. You can find ACF in the Plugins repository on your WordPress site or download it directly from their website.
Here is the image field documentation:
https://www.advancedcustomfields.com/resources/image/
The cleanest way is to set the field to use the URL of the image. Here is what would go in your code:
<?php if( get_field('field_slug') ): ?>
<img src="<?php the_field('field_slug'); ?>" />
<?php endif; ?>

Issue on CPT Custom Menu Position in WP

I have Two CPT as "Dress" and "Casual" and I would like to position them close to each other exactly after the "Dashboard" in the Menu.
I have this code in my custom post type for both:
'menu_position' => 2
how ever the result is displaying as:
the "Post" positions after the "Dress"! can you please let me know why this is happening and how I can keep all CPT after each other before the "Post".(I have 5 Custom Post Type)
Thanks
If Wordpress already has a menu item in the menu_position that you declare then it is moved to the next free position. Your issue is that Dashboard is in position 2 and then a separator is in position 4, so the second of your Post Types is moved to the next free position which is 6 (Posts is in position 5).
Note that Menu items are added in the order in which they are registered, so if they have the same menu_position, Post Types registered first will appear closer to the top of the menu.
However, you can move the default WP menu items if you so wish, thus achieving your desired display.
If you specify your menu_position as 6 and 7 for your custom Post Types, you can add this to move the separator to position 8 and Posts to position 9 -
add_action('admin_head', 'my_edit_admin_menu');
function my_edit_admin_menu(){
global $menu;
$menu[8] = $menu[4]; // Copy 'separator1' to a new menu location
unset($menu[4]); // Unset separator1 (from original position)
$menu[9] = $menu[5]; // Copy 'Posts' to a new menu location
unset($menu[5]); // Unset Posts (from original position)
ksort($menu); // Sort the menu
}
Note - the action admin_head is called after your custom Post Types are registered (using the init action). Because of this, you must ensure that your given menu_position values do clash with those of default menu items. If there is a clash, WP will move them before you get a chance to reorder the default items.
See the docs for menu_position in the Arguments section of the Function Reference for register_post_type() for the current WP default menu positions (although I believe that it is currently out of date for version 3.8). If you are ever unsure how the menu is organised, add this to the above code to output the full menu in the admin area -
echo '<pre>WP Admin Menu: '; print_r($menu); echo '</pre>';
FYI - I notice that you are using an image as the icon for you custom Post Types. As of WP 3.8, these were removed from the default admin dashboard in favour of DashIcons.
To make your Post Types look as pretty as the rest simply use the menu_icon argument, picking any of the icons from this page. To get the relevant name, click one and then look at the top of the page; the first icon is called dashicons-menu, for example.
if two menu items use the same position attribute, one of the items may be overwritten so that only one item displays! Risk of conflict can be reduced by using decimal instead of integer values, e.g. 2.3 instead of 2.
check here https://wordpress.stackexchange.com/questions/8779/placing-a-custom-post-type-menu-above-the-posts-menu-using-menu-position

Wordpress - How can I create my own template outside of the expected hierarchy of templates and feed a query to it?

BACKGROUND
I have used WordPress custom post types to create a newsletter section for my website. Newsletters consist of Articles (dm_article), which are grouped by the Issues taxonomy (dm_issues).
1) I have created an index of all of my newsletter Articles. I am using a template called taxonomy-dm_issues.php to loop within a selected Issue and display each Article's title, excerpt and a link to the full content, which is managed by single-dm_article.php. This is working great.
2) I would also like to create second taxonomy-based template for Issues. This is going to act as a print-friendly option: "print entire newsletter". I would like the template to loop through and display each Article title, excerpt, and long description. Some of the look and feel will also be different.
For #2, let's assume I've created a template called print-dm_issues.php. It currently looks identical to taxonomy-dm_issues.php, except it has the additional long description data for each Article and contains some different styling.
I want to setup this "print friendly" option without making the WordPress admin have to jump through any hoops when Issues and Articles are created. I also do not want to have to create a new template each time a new Issue is created.
CORE QUESTION:
What I am asking for may boil down to this: How can I create my own WordPress template outside of the expected hierarchy of templates and feed a query to it? Do note I am using the "month and name" common permalink structure, so I'll have to muck with my htaccess.
ALTERNATIVES:
1) My fallback is to have taxonomy-dm_issues.php contain the information for both variations and use style to handle the different view states. I know how to do this. But, I'd rather not do this for sake of load times.
2) Using Ajax to fetch all of the Article long descriptions (the_content()) with a single click is an option, but I don't know how.
3) ???
With or without clean URLs, you can pass variables based on your taxonomies through the links query string if you want to only return a single taxonomy term and style the page differently depending on the term.
$taxonomyTerm = $_GET['dm_issues'];
$args=array(
'post_type' => 'dm_article',
'dm_issues' => $taxonomyTerm,
'post_status' => 'publish',
);
There is reference to this int he Wordpress 'query_posts' documentation by passing variable into your query parameters: http://codex.wordpress.org/Function_Reference/query_posts#Example_4
For instance in the link below, the title is generated based on the sting in the URL.
http://lph.biz/areas-we-serve/service-region/?region=Conestoga
You can set up a parameter that will return a default value if the page is reached without the variable being defined. See below:
if (empty($taxonomyTerm)) {
$taxonomyTerm = 'Default Value';
}
You can create a separate page template. Define the template name at the top of your PHP document:
<?php
/*
Template Name: Printed Page Template
*/
Place your custom query, including all of the content that you need output in this page template... In your WP admin, create a new blank page and assign your new 'Printed Page Template' template to this page. Save it and view the page.

(Wordpress) Global variable to detect pagination?

I am showing 6 posts on one page. On the 7th post, pagination occurs on so on.
goal:
If there is more than one page (page 1, 2, 3, etc..), JavaScript is to add a specific div element. If there are only 6 posts or less, no pagination occurs, no div element is added.
The number of posts to show:
$showposts = get_query_var('showposts');
The current post number I can keep track of:
$post_count++;
Problem is I can keep track of posts 1-6 but how to tell if if it goes over to 7 and starts pagination? I thought there was a global variable that returns if pagination occurs, but I can't seem to find it.
(I know there is global to detect pagination via <!--nextpage--> but so far I can't find it's equivalent for index.php).
$paged is a global var that is set to the page number WP is displaying.

How to display a list of nodes and details of a single node in Drupal

I would like a page that displays a list of nodes (I can do this part with the Views module) and then also displays the details of a single node below the list. Ideally the details will update via Ajax when a node in the list is clicked, but reloading the page would be fine for a start.
I'm just starting to get into Drupal and the number of levels at which I can do stuff is somewhat overwhelming. For example should this be a View page with a customised block at the bottom? A page with two blocks (one for the list one for the item)? If so how would they communicate the node ID? Is there already a module that will do this for me? Maybe I should write my own module? And so on. If anyone with a better general understanding of Drupal could point me in the right direction it would be appreciated.
Edit:
Thanks for the answers so far, I think they point out that I missed out an important detail in my original question though. So, some more details:
I would like this page to effectively be a user's home page. As such my view is restricted to showing nodes that they've created. Editing the default node page would give me the problem of which node to send the user to when they log in (which may be possible I guess) and also would mean that I presumably couldn't view the node without also seeing the view?
I have been trying another tack which is to create page node which includes the View (called user_home) using some PHP. I have also set the View control to create a link for each node in the list and include the node id in that link e.g. http://localhost/drupal-6.10/?q=node/13/12 (where 13 is the node ID of the page I have created and 12 is the node ID of the item in the list).
<?php
//output the user_home view
print views_embed_view('user_home', $display_id = 'default');
?>
<br/>
<hr/>
<br/>
<?php
$queryparam = $_GET["q"];
// find the second /
$index = strpos($queryparam, '/');
$index = strpos($queryparam, '/', $index + 1);
$displayNodeId = substr($queryparam, $index + 1);
$displayNodeId = (int)$displayNodeId;
if ($displayNodeId > 0)
{
$displayNode = node_load($displayNodeId);
print node_view($displayNode);
}
?>
Now, this works, but I'm sure their's a more drupal friendly/compliant way of doing things (and the query string parsing is a nasty hack).
The canonical solution for this is to use a block in the "content top region" and the full node in content region.
The most basic way of achieving this is to simply display the node page normally and, with a theme having the content top region (Garland doesn't, Zen classic does), create a Views block containing the list you want and place it in that region. you can use the path as the argument to the View so its contents can depend on the currently displayed node. Then, define the visibility of the block to only match the conditions you want, probably to display only on node pages, or maybe on node pages of a specific content type. For this, use the PHP visibility mode for the block, and do something like
// Filter args for safety
if ((arg(0) == 'node') && is_numeric(arg(1)) {
$node = node_load(arg(1);
return is_object($node) && ($node->type == 'the_content_type_i_want');
}
else {
return FALSE;
}
That way the block will be displayed only when you want it.
If your theme does not have this feature, Panels provide a way for you to divide the page and place the view in one panel and the full node in an other one.
I would do that as following. Set Page specific visibility settings for your Views block with nodes list to be shown only on that nodes, Pathauto module can be helpful here also for managing bunch of nodes paths.
The custom pager might work for you.
http://drupal.org/project/custom_pagers
You first create a View for the pager to work on; this could be all posts by a certain user or whatever you want -- it's as flexible as any other View.
You don't need to provide forward-back links like a standard pager (and the default) -- with custom_pagers you get a $nav_array variable to play with that contains all the nodes in your view.
With that you should be able to create a table or list of links.
Generating secondary menu based on node titles

Resources