How to get News previous and next news in contao ? - contao

How to i get News previous and next news in contao ?
f.e
< Previous News | Current news ( id - 4) | Next News >
I want Previous and next news link in detail page..

You can use the following extension: [newspagination]
In case you are not using the default mod_newsreader template, you need to add the following line:
<?php echo $this->addNewsPagination() ?>
or just
<?= $this->addNewsPagination() ?>
with PHP 5.4+

Related

ModX Revo: TagLister: Display Tag name on Tag page

what is the correct way to display the tag name on the tag specific page and a link to it in Modx revo using tagLister? e,g, a post has tags Tag1, Tag2 and Tag3. Now you click on one of the tags and it brings to the target resource displaying al posts with that single tag. What code to put in that target resource so it shows that the user has landed on the specific single tag page. I want to display the name and the link of that exact single tag.
My tags target resource is the main blog resource: Here is the code:
<section>
[[The Code to Display the Tag name to put here]]
[[!getResourcesTag#Blog Pagination Hy?
  &elementClass=`modSnippet`
&element=`getResources`
&tpl=`Blog Post on Blog Page`
&hideContainers=`0`
&pageVarKey=`page`
&parents=`[[*id]]`
  &limit=`3`
&includeTVs=`1`
&includeContent=`1`
&cache=`0`
]]
<div class="PaginationContainer">
<span class="TotalPages">p [[+page]] (total. [[+pageCount]])</span>
<ul>
[[!+page.nav]]
</ul>
</div>
</section>
is it possible at all?
Finally found on the web.
If you got better solution, please put it here.
So the idea is to make a snippet which gets the tag and call the snippet where we want.
Step by Step.
Step 1. Make a new snippet and name it something, e.g. Tag Name,
Step 2. Put the snippet code in the snippet code placeholder,
Snippet code:
//-- Get all request string key/value pairs
$s = $_REQUEST;
if($s['key'] == 'tags'){
return $s['tag'];
} else {
return false;
}
Step 3. Call the snippet where you want the tag nam to show up, e.g. [[!Tag Name]]
It will show up the tag name on tag pages only.
Here is where I found it
https://forums.modx.com/thread/11108/dynamically-generated-list-of-documents-that-are-tagged-with-categories?page=2#dis-post-397237

i want to load next page with having same nav and panel as previous page have.

I want to load another page in same page with having all the function of current page.
For example i have page which have "navigation bar" "panel" , now what i want is next page should get load but only content gets change.not the whole page .
you should devid you page as ... (1) Header , (2) Main sections , (3) Footer
and include them using php include file examble >>> include 'filename';
check this out
So you have the same ( Header page ) and ( Footer page )
But only the Content page is changing
<?php
include 'header.php';
//only change this for the other pages
include 'main.php';
include 'footer';
?>

Pull in previous and next post featured images into single.php

My previous and next posts are set on an infinite loop so there is always a previous and next post. I.E. for the newest article the "next" post would be go to the oldest post. And if we're viewing the oldest post, the "previous" post would go to the newest post.
I need to pull in the featured images of the next and previous posts to be the background for the pagination navigation.
I've got the images pulling in when there truly is a next or previous post. However, when the infinite loop is necessary, i.e. next being the oldest post, or previous being the newest post, my code breaks down.
My code is below. I believe the issue is that I'm not actually capturing the ID of what I need in $first_id and $last_id. I've tried using get_queried_object_id() $first->post->ID and various combinations to get the post ID of what is being pulled in since .previous-title is working correctly.
<div class="post_nav">
<?php if( get_adjacent_post(false, '', true) ) :
$previous_post = get_previous_post(); ?>
<div class="previous-img"><?php echo get_the_post_thumbnail( $previous_post->ID );?></div>
<p class="previous-title"><?php previous_post_link('Previous Story<br> %link','%title');?</p>
<?php else:
$first = new WP_Query('posts_per_page=1&order=DESC'); $first->the_post();
$first_id = $first->ID; ?>
<div class="previous-img"><?php echo get_the_post_thumbnail( $first_id );?></div>
<?php echo '<p class="previous-title">Previous Story<br>' . the_title() . '</p>';
wp_reset_query(); ?>
<?php endif; ?>
<?php if( get_adjacent_post(false, '', false) ) :
$next_post = get_next_post(); ?>
<div class="next-img"><?php echo get_the_post_thumbnail( $next_post->ID ); ?></div>
<p class="next-title"><?php next_post_link('Next Story<br> %link','%title');?></p>
<?php else:
$last = new WP_Query('posts_per_page=1&order=ASC'); $last->the_post();
$last_id = $last->ID; ?>
<div class="next-img"><?php echo get_the_post_thumbnail( $last_id );?></div>
<?php echo '<p class="next-title">Next Story<br>' . the_title() . '</p>';
wp_reset_query(); ?>
<?php endif; ?>
You're right, $first and $last are not posts, but queries. You could either use get_the_ID() or grab the ID directly.
$last_id = get_the_ID();
( since you've made it the active loop )
or
$last_id = $last->posts[0]->ID;
which means you wouldn't need to set up the loop for $last, in which case you'd also need to get the permalink and title via functions taking the ID as a parameter. This is a minor optimization, if you get confused here go with the first option.
Also, your next-title and previous-title in the else paths seem to be switched with each other. Or perhaps the entire code blocks are.

Wordpress displaying custom post types and their fields

I have set up a Custom Post Type called 'RELEASES' - think music cd release.
This post type has fields named 'release_artist', 'release_title', 'release_date', 'release_artwork' and 'release_tracklisting' for entering all of the relevant music cd information.
I am having real trouble actually displaying this information in my Wordpress template.
I have really only had luck outputting a list of the titles and none of the other data.
Any idea what I put in the LOOP to display all of the information? Preferably each in its own LIST item so I can style each separately?
Any thoughts greatly appreciated.
You can use get_post_meta to pull in your fields as needed. Inside your loop, you can start with the following:
<?php
$release_artist = get_post_meta($post->ID, 'release_artist', true);
$release_title = get_post_meta($post->ID, 'release_title', true);
?>
<ul>
<li class="release_artist">
<?php echo $release_artist; ?>
</li>
<li class="release_title">
<?php echo $release_title; ?>
</li>
</ul>
Are those custom fields? If yes, try what codex.wordpress.org is saying. Better yet, try ACF plugin.
-- edit
If you want to display parts of your pages on other ones (eg. on your home), you need to use query_posts. This is fairly simple function. For your loop, try something like this:
<?php
global $wp_query;
query_posts(array(
'post_type' => 'releases'
));
while(have_posts()) : the_post(); ?>
<?php $key = get_post_meta($post->ID, 'Opis nazwy'); ?>
<li <?php post_class(); ?>><?php if($key) { echo $key[0]; } else { the_title(); }; ?></li>
<?php
endwhile;
wp_reset_query();
?>
$key is a single value, here set to release_artists. It's purely for testing. If it works - feel free to define your own variables.
You should use:
<?php the_field('field_name') ?>
inside your loop. Hope it helps!
From most of the documentation I've seen online, query_posts shouldn't be the go-to function for creating custom queries and loops. The following code snippet might be a good starting point. You should be able to use this inside or outside of the main loop of your themes template files.
$args = array(
'post_type' => 'release', //remember this is-case sensitive
'posts_per_page' => -1,
);
$releaseQuery = new WP_Query( $args );
if ( $releaseQuery->have_posts() ) :
while ( $releaseQuery->have_posts() ) :
$releaseQuery->the_post();
// Fetching the post ID for demonstration and for use later
$c_id = get_the_ID();
// After running the_post(), alot of the Wordpress functions (not all) can now be used without supplying the post ID.
echo get_the_title();
// You could also have used get_the_title($c_id);
// Then:
echo get_post_meta($c_id, 'release_title', true);
echo get_post_meta($c_id, 'release_artist', true);
endwhile;
endif;
// Return to the current page's main query
wp_reset_query();
// This should now display the page's title
the_title();
About your ID's question:
Every item, like posts and pages in WordPress have an "ID", but they are not normally shown in the lists of them. There are a number of plugins that will add an "ID" column in your admin. Search Wordpress.org for "show ids" and pick one you like. Install it. Activate it. You'll see the ids.
https://wordpress.org/plugins/search.php?q=show+id

How to add headers in specific pages pdfkit generated pdfs

I'm currently using pdfkit in a 3.0.5 rails application to generate reports of user activity.
The pdf document is simple, first page it has some details about the user, a summary then
it has a table containing all the user's activity of the selected period.
First page is ok, but when I show the table the next pages must start with that header column titles in every page with the activity table header. (it remind a bank statement)
Something like this:
|user |action | source | destination |date-time |
xxx 1 1 2 2011-04-01 hh:mm:ss
....
====================page break=================================
#after page break the column titles must be printed again
|user |action | source | destination |date-time |
xxx 5 4 5 2011-04-05 hh:mm:ss
Does anybody know how could I can do that?
You should be able to use some javascript to alter the contents of the header, but only on certain pages.
in your header html have a hidden div with your table headers, but your first page header by default. Then with a javascript onload function do something like this:
<html>
<head>
<script type='text/javascript'>
function swap_header() {
var pages = document.getElementsByClassName('header');
for (var i=0; i<pages.length; ++i) {
if ( i > 0 ) {
pages[i].innerHTML = '<table><thead><th>user</th><th>action</th></thead></table>';
}
}
}
</script>
</head>
<body onload='swap_header()'>
<div class='header'>Normal 1st page header</div>
<table>
<tr><td>foo</td><td>bar</td></tr>
</table>
</body>
</html>
You could also render out 2 different pdfs, and combine them programmatically with pdftk.

Resources