Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

last three blog articles on the home page? #4

Open
dpertal opened this issue Jan 25, 2022 · 11 comments
Open

last three blog articles on the home page? #4

dpertal opened this issue Jan 25, 2022 · 11 comments

Comments

@dpertal
Copy link

dpertal commented Jan 25, 2022

Hello nakome!
how do i display the last three blog articles on the home page?
I'm waiting for any answer
Thanks

@monchovarela
Copy link
Collaborator

Hi, you can use this code maybe, i not use for last 4 years:

{? Barrio::actionRun("lastPosts",["3","blog"]) ?}

Or you can create new tag in Tpl class in Barrio.php

'{Home_posts}' => '<?php echo Barrio::actionRun("lastPosts","3","blog"]);?>'

@dpertal
Copy link
Author

dpertal commented Jan 25, 2022

thank you for the answer! I have created a "portfolio" category
how can I display the last three portfolios on the home page?
Screenshot (18)

@dpertal
Copy link
Author

dpertal commented Jan 25, 2022

actions.ext.php add

`Barrio::actionAdd('lastPortfolio', function ($num = 4,$name = '') {
    $articulos = Barrio::pages($name, 'date', 'DESC', ['index','404'], $num);
	$html = '<section class="portfolio">';
	foreach ($items as $articulo) {

		$html .= '<article class="portfolio-item">';

		// header
		$html .= '<hgroup class="portfolio-header">';
		$html .= '  <h3 class="portfolio-title"> <a href="'.$articulo['url'].'">'.$articulo['title'].'</a></h3>';
		$html .= '  <p class="portfolio-description">'.$articulo['description'].'</p>';
		$html .= '</hgroup>';

		// body
		$html .= '<footer class="portfolio-footer">
					<a href="'.$articulo['url'].'">Ver &rarr;</a>
				</footer>';
		$html .= '</article>';
	}
	$html .= '</section>';
    echo $html;
});
`

{? Barrio::actionRun("lastPortfolio",["3","erga"]) ?}
create new tag in Tpl class in Barrio.php

'{Home_Portfolio}' => '<?php echo Barrio::actionRun("lastPortfolio","3","erga"]);?>'

not work! what am I doing wrong?

@dpertal
Copy link
Author

dpertal commented Jan 27, 2022

any answer please

@monchovarela
Copy link
Collaborator

Wrong code my apologies.

<?php echo Barrio::actionRun("functionName",$arrayOrArguments); ?>

'{Home_Portfolio}' => '<?php echo Barrio::actionRun("lastPortfolio",["3","erga"]);?>'

@dpertal
Copy link
Author

dpertal commented Jan 28, 2022

https://streamable.com/g8y62o

not work! what am I doing wrong?

@dpertal
Copy link
Author

dpertal commented Jan 28, 2022

Barrio.php add
// last posts '{Home_Portfolio}' => '<?php echo Barrio::actionRun("lastPortfolio",["3","erga"]);?>', '{Home_posts}' => '<?php echo Barrio::actionRun("lastPortfolio","3","erga"]);?>',

extensions => actions => actions.ext.php add

`/** Ultimos Articulos
-------------------------------------------------*/
Barrio::actionAdd('lastPortfolio', function ($num = 4,$name = '') {
$articulos = Barrio::pages($name, 'date', 'DESC', ['index','404'], $num);
$html = '

';
foreach ($items as $articulo) {
	$html .= '<article class="portfolio-item">';

	// header
	$html .= '<hgroup class="portfolio-header">';
	$html .= '  <h3 class="portfolio-title"> <a href="'.$articulo['url'].'">'.$articulo['title'].'</a></h3>';
	$html .= '  <p class="portfolio-description">'.$articulo['description'].'</p>';
	$html .= '</hgroup>';

	// body
	$html .= '<footer class="portfolio-footer">
				<a href="'.$articulo['url'].'">Ver &rarr;</a>
			</footer>';
	$html .= '</article>';
}
$html .= '</section>';
echo $html;
});

@monchovarela
Copy link
Collaborator

Check this:

Create posts with templating
https://streamable.com/4ytpus

Create posts with actions
https://streamable.com/ltg5qy

Create custom action in func.php theme file
https://streamable.com/167vfq

@dpertal
Copy link
Author

dpertal commented Jan 28, 2022

what i want to do is have the last three projects appear on the home page, but within a frame
as in the image below
Screenshot_2

@dpertal
Copy link
Author

dpertal commented Jan 29, 2022

any answer please

@monchovarela
Copy link
Collaborator

Depends of Css Framework and only need:

<div class="frame">{Last_posts}</div>

Barrio::actionAdd('lastPosts', function ($num = 4,$name = '') {

    // Short text
    function shortText(string $text, int $chars_limit)
    {
        if (strlen($text) > $chars_limit) {
            $text = htmlentities(html_entity_decode($text));
            $new_text = substr($text, 0, $chars_limit);
            $new_text = trim($new_text);
            return $new_text.'...';
        } else {
            return $text;
        }
    }

    // Get pages 
    $articulos = Barrio::pages($name, 'date', 'DESC', ['index','404'], $num);

    // Frame is here
    $html = '<div class="container">';
    // row
    $html .= '<div class="row">';
    foreach ($articulos as $articulo) {
        $date =  date('d/m/Y', $articulo['date']);
        // col
        $html .= '<div class="col-md-4 col-lg-4">';
        // card
        $html .= '<div class="card mb-3">';

        // check if exists image url
        if ($articulo['image']) {
            // check if not a external link
            if (!preg_match('/http/s', $articulo['image'])) {
                // local image
                $html .= '<div class="card-image-top">
                        <img src="'.Barrio::urlBase().'/'.$articulo['image'].'"/>
                </div>';
            }else{
                // external image
                $html .= '<div class="card-image-top">
                    <img src="'.$articulo['image'].'"/>
                </div>';
            }
        }
        // card-body
        $html .= '<div class="card-body">';

        // card-title
        $html .= '<h5 class="card-title">'.$articulo['title'].'</h5>';
        // card-text
        $html .= '<p class="card-text">'.shortText($articulo['description'],50).'</p>';

        $html .= '</div>';// card-body

        // card-footer
        $html .= '<div class="card-footer text-right">';
        $html .= '  <a href="'.$articulo['url'].'" class="btn btn-sm btn-link text-dark text-end">More  &rarr;</a>';
        $html .= '</div>';// card-footer

        $html .= '</div>';// col
        $html .= '</div>';// card
    }
    $html .= '</div>';// row
    
    $html .= '</div>';// Frame is here

    echo $html;
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants