Hi I am trying to add html to the "t('Older Posts')" and "t('Newer Posts')" Is this possible ? I can figure it out ????
I am in a Drupal 6 template.php file.
This is the code I am trying to add as html -
<span>Newer Posts</span>
<span>Older Posts</span>
I need to replace the above in these spots located in the full function below ?
t('Older Posts')
t('Newer Posts')
I want to create something like this
t('<span>Older Posts</span>')
t('<span>Newer Posts</span>')
Full Function
function theme_views_mini_pager($tags = array(), $limit = 10,
$element = 0, $parameters = array(), $quantity = 9) {
global $pager_page_array, $pager_total;
// Calculate various markers within this pager piece:
// Middle is used to "center" pages around the current page.
$pager_middle = ceil($quantity / 2);
// current is the page we are currently paged to
$pager_current = $pager_page_array[$element] + 1;
// max is the maximum page number
$pager_max = $pager_total[$element];
// End of marker calculations.
$li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] :
t('Older Posts')), $limit, $element, 1, $parameters);
if (empty($li_previous)) {
$li_previous = " ";
}
$li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('Newer Posts')),
$limit,$element, 1, $parameters);
if (empty($li_next)) {
$li_next = " ";
}
if ($pager_total[$element] > 5) {
$items[] = array(
'class' => 'action back pager-previous',
'data' => $li_previous,
);
$items[] = array(
'class' => 'action pager-next',
'data' => $li_next,
);
return theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
}
}
I am trying to figure out if this is possible I have tried many things and nothing has worked yet.
You can use
$link = '<span>' . t('Older Posts') . '</span>';
OR
$link = t('!link_startOlder Posts!link_end', array(
'!link_start' => '<a href="" class="action back"><span>',
'!link_end' => '</span></a>',
));
Related
I am trying to add more data from API to my page. The API has been paginated due to memory concerns. I am using symfony and Twig templating to get a list of articles. The API call has filter of page number. Is there a way I can call this API multiple times in my display function to get the data from other pages.
Here is my code. In the controller I have the following display function
public function display(Application $app)
{
$lang = $app['filterLang'];
$years = [];
$activeYear = $this->getActiveYear($app['request']->get('year'));
$modelManagerFactory = $app['factories.model_manager'];
$articleCmsManager = $modelManagerFactory->create('ArticleManager');
$articles = $articleCmsManager->getList($lang, $activeYear);
$categories = $articleCmsManager->getCategories();
$cmsYears = $articleCmsManager->getCmsYears($lang);
$allYears = array_unique(array_merge($years, $cmsYears));
$oldActiveYear = $activeYear;
if (is_null($app['request']->get('year')) && empty($articles)) {
$activeYear = $oldActiveYear - 1;
$articles = $articleCmsManager->getList($lang, $activeYear);
}
$articleIssues = [];
foreach ($articles as $article) {
if (strpos($article->publicationDate, "$activeYear") !== false) {
$category = [
'en_US' => isset($categories['en_US'][$article->category]) ? $categories['en_US'][$article->category] : ''
];
if ('en_US' != $lang) {
$category[$lang] = isset($categories[$lang][$article->category]) ? $categories[$lang][$article->category] : '';
}
$articleIssues[] = [
'title' => isset($article->content->title) ? $article->content->title : '',
'category' => $category,
'image' => isset($article->image) ? $article->image : '',
'url' => isset($article->content->url) ? $article->content->url : '',
'date' => isset($article->publicationDate) ? $article->publicationDate : '',
'artist' => isset($article->artist) ? $article->artist : '',
'metadescription' => isset($article->content->metadescription) ? $article->content->metadescription : ''
];
}
}
return $app['twig']->render(
'archive/ArchivePage.html',
array(
'issues' => [],
'articles' => $articleIssues,
'years' => $allYears,
'activeYear' => $activeYear
)
);
}
The getList function which is responsible for the getting the data from the API is defined as
public function getList($lang = null, $activeYear = null)
{
// define a fallback language (locale)
$fallbackLang = '';
$filter = [
'filter[sort]=startdate_desc',
'page=0',
'per_page=100',
'filter[status]=published',
'filter[publicationDate]='.urlencode(date("Y-m-d H:i:s")),
'filter[year]='.$activeYear
];
$query = array(
'url' => '/cms/article?'.implode('&', $filter),
'data' => array()
);
$results = $this->repo->getList($query);
$articles = array();
foreach ($results as $article) {
if (!empty($article->displayInArchive)) {
if (isset($article->content->$lang->html) && !empty($article->content->$lang->html)) {
$article->content = $article->content->$lang;
$articles[] = $article;
} elseif (isset($article->content->$fallbackLang->html) && !empty($article->content->$fallbackLang->html)) {
$article->content = $article->content->$fallbackLang;
$articles[] = $article;
}
}
}
return $articles;
}
As you can see the view can only get a total of 100 results i.e all the articles on page 0. Now if I also want to show the articles on page 1,2 and so on the same view i.e archive how do I go about doing that without running into memory constraints.
I'm trying to create a simple shortcode for wordpress that has the following variables:
- username
- no_of_tweets
So a user could write [twitter_feed username="USERNAME" no_of_tweets="5"]
and it displays a list of 5 of their latest tweets. I have been using a plugin called Twitter Feed for developers - it does all the oAuth stuff and the idea is that you just write the code to output some front end html.
I have it working except for one annoying glitch - I can't get the no_of tweets to work.
This code works, but doesn't allow for users to specify the no_of_tweets variable:
extract( shortcode_atts(
array(
'username' => 'skizzar_sites',
'no_of_tweets' => '3',
), $atts )
);
// Code
$tweets = getTweets(3, $username);
...
If I were tochange the code to the following (i.e. change the "3" in the $tweets variable, the code stops working:
extract( shortcode_atts(
array(
'username' => 'skizzar_sites',
'no_of_tweets' => '5',
), $atts )
);
// Code
$tweets = getTweets($no_of_tweets, $username);
Is there any reason why this might not be working correctly?
See full code below:
<?php
// Add Shortcode
function skizzar_twitter_feed( $atts ) {
// Attributes
extract( shortcode_atts(
array(
'username' => 'skizzar_sites',
'no_of_tweets' => '5',
), $atts )
);
// Code
$tweets = getTweets($no_of_tweets, $username);//change number up to 20 for number of tweets
if(is_array($tweets)){
// to use with intents
echo '<script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>';
foreach($tweets as $tweet){
if($tweet['text']){
$the_tweet = $tweet['text'];
if(is_array($tweet['entities']['user_mentions'])){
foreach($tweet['entities']['user_mentions'] as $key => $user_mention){
$the_tweet = preg_replace(
'/#'.$user_mention['screen_name'].'/i',
'#'.$user_mention['screen_name'].'',
$the_tweet);
}
}
if(is_array($tweet['entities']['hashtags'])){
foreach($tweet['entities']['hashtags'] as $key => $hashtag){
$the_tweet = preg_replace(
'/#'.$hashtag['text'].'/i',
'#'.$hashtag['text'].'',
$the_tweet);
}
}
if(is_array($tweet['entities']['urls'])){
foreach($tweet['entities']['urls'] as $key => $link){
$the_tweet = preg_replace(
'`'.$link['url'].'`',
''.$link['url'].'',
$the_tweet);
}
}
echo $the_tweet;
echo '
<ul class="twitter_intents">
<li><a class="reply" href="https://twitter.com/intent/tweet?in_reply_to='.$tweet['id_str'].'"><i class="fa fa-reply"></i></a></li>
<li><a class="retweet" href="https://twitter.com/intent/retweet?tweet_id='.$tweet['id_str'].'"><i class="fa fa-retweet"></i></a></li>
<li><a class="favorite" href="https://twitter.com/intent/favorite?tweet_id='.$tweet['id_str'].'"><i class="fa fa-star"></i></a></li>
</ul>';
echo '
<p class="timestamp">
<a href="https://twitter.com/'.$username.'/status/'.$tweet['id_str'].'" target="_blank">
'.date('h:i A M d',strtotime($tweet['created_at']. '- 8 hours')).'
</a>
</p>';// -8 GMT for Pacific Standard Time
} else {
echo '
<br /><br />
Click here to read '.$username.'\'S Twitter feed';
}
}
}
}
add_shortcode( 'twitter_feed', 'skizzar_twitter_feed' );
Here is the getTweets function code:
/* implement getTweets */
function getTweets($username = false, $count = 20, $options = false) {
$config['key'] = get_option('tdf_consumer_key');
$config['secret'] = get_option('tdf_consumer_secret');
$config['token'] = get_option('tdf_access_token');
$config['token_secret'] = get_option('tdf_access_token_secret');
$config['screenname'] = get_option('tdf_user_timeline');
$config['cache_expire'] = intval(get_option('tdf_cache_expire'));
if ($config['cache_expire'] < 1) $config['cache_expire'] = 3600;
$config['directory'] = plugin_dir_path(__FILE__);
$obj = new StormTwitter($config);
$res = $obj->getTweets($username, $count, $options);
update_option('tdf_last_error',$obj->st_last_error);
return $res;
}
I am trying to theme particular pagers on the site and no matter what id I try it doesn't seem to get picked up. This is what I am using to theme all pagers now.
function Subtle_Hightlights_views_mini_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) {
global $pager_page_array, $pager_total;
// Calculate various markers within this pager piece:
// Middle is used to "center" pages around the current page.
$pager_middle = ceil($quantity / 2);
// current is the page we are currently paged to
$pager_current = $pager_page_array[$element] + 1;
// max is the maximum page number
$pager_max = $quantity;
// End of marker calculations.
$li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('')), $limit, $element, 1, $parameters);
if (empty($li_previous)) {
$li_previous = "";
}
$li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('')), $limit, $element, 1, $parameters);
if (empty($li_next)) {
$li_next = "";
}
if ($pager_total[$element] > 1) {
$items[] = array(
'class' => 'pager-previous-mini',
'data' => $li_previous,
);
if ($pager_current == 9){
$li_next = "";
}
$items[] = array(
'class' => 'pager-current-mini',
'data' => t('#current of #max', array('#current' => $pager_current, '#max' => $pager_max)),
);
$items[] = array(
'class' => 'pager-next-mini',
'data' => $li_next,
);
return theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
}
}
now this works to theme all mini pagers but when I try to apply the name of the view and block like this.
function Subtle_Hightlights_views_mini_pager__news_items__block_2($tags = array(), $limit = ``10, $element = 0, $parameters = array(), $quantity = 9) {
does nothing acts as though the code isnt there anymore. Anyone else tried this and it actually worked?
There is a good step by step instructions on how you can overwrite the pager (mini or full). The only step that I would suggest that you do different is when you get to list of theme function names that you can use to override your views pager inside your template.php file, just use this module: Theme developer. Once it's enabled it will provide in a much easier way the suggestions. If that fails, then just try the article's methods.
Drupal 6 Override views pager theme function
I am trying to make a module for Drupal 7 that provides a block and has certain configuration settings. Now what I want is that I want to provide 5 blocks to the user so that they can use different settings in each block. In other words, I want to provide each block a separate set of settings. How can I do that?
Edit:
Actually I have made a module that shows a single block. If you have used superfish menu module then you can see there that they allow us an option to choose how many block should be made available. So that for each block we can use different menu to show. I am talking about that functionality
Create a configuration page:
function my_module_admin_settings($form, &$form_state) {
$form['my_module_number_of_blocks'] = array(
'#title' => t('Post to Blog by default'),
'#description' => t('Should content post to blog by default or only when selected?'),
'#type' => 'select',
'#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10)),
'#default_value' => 2,
);
return system_settings_form($form);
}
You create blocks in a module using hook_block_info you define an array like:
hook_block_info() {
number_blocks = variable_get('my_module_number_of_blocks', 0);
$x=0
while ($x < number_of_blocks) {
$blocks['myblock-' . $x] = array(
'info' => t('Block ' . $x),
'cache' => DRUPAL_NO_CACHE,
);
}
return $blocks
}
You'll configure the values in hook_block_configure:
function hook_block_configure($delta = '') {
// This example comes from node.module.
$form = array();
$parts = explode($delta, '-');
if ($parts[0] == 'my_block') {
$form['my_block_' . $parts[1] . '_option1'] = array(
'#type' => 'select',
'#title' => t('Some option'),
'#default_value' => variable_get('my_block_' . $parts[1] . '_option1', 'first_option'),
'#options' => drupal_map_assoc(array('first option', 'second option')),
);
}
return $form;
}
Once you have defined your blocks you need to tell them how to display with hook_block_view. Something like:
function hook_block_view($delta = '') {
$block = array();
$parts = explode($delta, '-');
if ($parts[0] == 'myblock') {
$block['subject'] = t('Block' . $parts[1]);
$block['content'] = my_module_block_b_generate($parts[1]);
}
return $block;
}
Then you'll use the block number and configuration to determine the output:
my_module_block_b_generate($block_number) {
$option1 = variable_get('my_block_' . $block_number . '_option1', 'first_option');
return t('this is block ' . $block_number . '. It has chosen option ' . $option1 . ' for option1');
}
I am finishing some edits on a drupal project that was done by another programmer (I have no contact with him). I'm a newbie and trying to find out how the Paging module works. There are no numbers of pages showing. I suppose the programmer added some custom module or something.
I found a file named "pager.php" in the project's own theme folder with this function, that is probably doing the pagination:
function _my_pager_link($page, $text, $class, $title) {
$query = array();
$query[] = drupal_query_string_encode(array(
'page' => implode(',', $page)), array());
$querystring = pager_get_querystring();
if ($querystring != '') {
$query[] = $querystring;
}
$attributes['title'] = $title;
$attributes['class'] = $class;
return l("<span>$text</span>", $_GET['q'], array('html' => TRUE,
'attributes' => $attributes,
'query' => count($query) ? implode('&', $query) : NULL));
}
function my_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 5) {
global $pager_page_array, $pager_total;
$curr = $pager_page_array[$element];
$total = $pager_total[$element];
$output = '';
if ($total > 1) {
$output .= '<div class="pager">';
if ($curr > 0) {
$page_new = pager_load_array($curr - 1, $element, $pager_page_array);
$output .= _my_pager_link($page_new, t('‹ previous'), 'pager-prev', t('Go to previous page'));
}
if ($curr < $total - 1) {
$page_new = pager_load_array($curr + 1, $element, $pager_page_array);
$output .= _my_pager_link($page_new, t('next ›'), 'pager-next', t('Go to next page'));
}
$output .= '<div class="cleaner"></div>';
$output .= '</div>';
}
return $output;
}
Now there is just 'previous page' and 'next page' on the web. I would like it to be like this
'previous page '... 2 3 4 ... 'next page'
How can I add the list of pages there?
Thank You
Copy and paste http://api.drupal.org/api/function/theme_pager/6
Add salt and voila!
You need to set the global values like so:
global $pager_page_array, $pager_total;
$pager_page_array[0] = $your_page_count_goes_here;
$pager_total[0] = $your_page_total_goes_here;
And then you can call theme('pager', ...) or any custom paging theme function that you may have.