Ajouter une fonction "image à la une" dans son administration
Fermé
gwen007
Messages postés
75
Date d'inscription
mardi 24 février 2015
Statut
Membre
Dernière intervention
23 juin 2023
-
15 sept. 2019 à 13:45
gwen007 Messages postés 75 Date d'inscription mardi 24 février 2015 Statut Membre Dernière intervention 23 juin 2023 - 15 sept. 2019 à 19:01
gwen007 Messages postés 75 Date d'inscription mardi 24 février 2015 Statut Membre Dernière intervention 23 juin 2023 - 15 sept. 2019 à 19:01
A voir également:
- Ajouter une fonction "image à la une" dans son administration
- Fonction si et - Guide
- Comment agrandir une image - Guide
- Créer une image iso - Guide
- Légender une image - Guide
- Ajouter une signature sur word - Guide
2 réponses
gwen007
Messages postés
75
Date d'inscription
mardi 24 février 2015
Statut
Membre
Dernière intervention
23 juin 2023
4
15 sept. 2019 à 15:02
15 sept. 2019 à 15:02
J ai trouvé, https://www.codexworld.com/upload-image-create-thumbnail-using-php/
Juste impossible à intégrer sans faire buger tout le site.
Juste impossible à intégrer sans faire buger tout le site.
gwen007
Messages postés
75
Date d'inscription
mardi 24 février 2015
Statut
Membre
Dernière intervention
23 juin 2023
4
15 sept. 2019 à 19:01
15 sept. 2019 à 19:01
Donc l'idée, le but est d'afficher une miniature des articles. J'ai une sidebar qui affiche les Nouveaux articles et Populaire mais qu 'en texte.
J'ai 5 facons de commencer un article : normale - avec image - en video - en son ou en blockpot. Mais c'est beaucoup trop long à expliquer... htmly www.htmly.com est disponible en téléchargement.
Vraiment je tiens à dire que j ai vraiment essayer beaucoup de chose, c'est pas la premiere fois que j essais. Au finale je comprend pas bien le code, et je ne comprend pas toujours à quoi il correspond.
J ai 4 script à montrer, dont trois qui ce situe dans themes/blog, je pense que c'est suffisant pour ceux qui comprenne le php :
La page themes/blog/layout.php ou s'affiche la page index du site
Et après je perds le fil car j' ai 2 pages pareils (mains.php et post.php), elles représentent l administration du cms.
Page themes/blog/mains.php
Page themes/blog/post.php
Et pui la page upload :
J'ai 5 facons de commencer un article : normale - avec image - en video - en son ou en blockpot. Mais c'est beaucoup trop long à expliquer... htmly www.htmly.com est disponible en téléchargement.
Vraiment je tiens à dire que j ai vraiment essayer beaucoup de chose, c'est pas la premiere fois que j essais. Au finale je comprend pas bien le code, et je ne comprend pas toujours à quoi il correspond.
J ai 4 script à montrer, dont trois qui ce situe dans themes/blog, je pense que c'est suffisant pour ceux qui comprenne le php :
La page themes/blog/layout.php ou s'affiche la page index du site
<!DOCTYPE html> <!--[if IE 8]> <html lang="en" class="ie8"> <![endif]--> <!--[if IE 9]> <html lang="en" class="ie9"> <![endif]--> <!--[if !IE]><!--> <html lang="en"> <!--<![endif]--> <head> <?php echo head_contents();?> <title><?php echo $title;?></title> <meta name="description" content="<?php echo $description; ?>"/> <link rel="canonical" href="<?php echo $canonical; ?>" /> <?php if (publisher()): ?> <link href="<?php echo publisher() ?>" rel="publisher" /><?php endif; ?> <link href="//fonts.googleapis.com/css?family=Lato:300,400,300italic,400italic" rel="stylesheet" type="text/css"> <link href="//fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css"> <link href="//fonts.googleapis.com/css?family=Crimson+Text:400,400italic" rel="stylesheet" type="text/css"> <!-- Global CSS --> <link rel="stylesheet" href="<?php echo site_url();?>themes/blog/css/bootstrap.min.css"> <!-- Plugins CSS --> <link rel="stylesheet" href="<?php echo site_url();?>themes/blog/css/font-awesome.min.css"> <!-- Theme CSS --> <link id="theme-style" rel="stylesheet" href="<?php echo site_url();?>themes/blog/css/styles.css"> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> <![endif]--> </head> <?php if (isset($_GET['search'])) { $search = $_GET['search']; $url = site_url() . 'search/' . remove_accent($search); header("Location: $url"); } ?> <body class="<?php echo $bodyclass; ?>" itemscope="itemscope" itemtype="http://schema.org/Blog"> <div class="hide"> <meta content="<?php echo blog_title() ?>" itemprop="name"/> <meta content="<?php echo blog_description() ?>" itemprop="description"/> </div> <?php if (facebook()) { echo facebook(); } ?> <?php if (login()) { toolbar(); } ?> <!-- ******HEADER****** --> <header class="header"> <div class="container"> <div class="logo pull-left"><img class="logo-image" src="<?php echo site_url();?>themes/blog/images/logo.png"/></div> <div class="branding pull-left"> <?php if (is_index()) {?> <h1 class="name"><a href="<?php echo site_url();?>"><?php echo blog_title();?></a></h1> <?php } else {?> <h2 class="name"><a href="<?php echo site_url();?>"><?php echo blog_title();?></a></h2> <?php } ?> <p class="desc"><?php echo blog_tagline();?></p> <ul class="social list-inline"> <li><a href="<?php echo config('social.twitter');?>"><i class="fa fa-twitter"></i></a></li> <li><a href="<?php echo config('social.google');?>"><i class="fa fa-google-plus"></i></a></li> <li><a href="<?php echo config('social.facebook');?>"><i class="fa fa-facebook"></i></a></li> <li><a href="<?php echo config('social.tumblr');?>"><i class="fa fa-tumblr"></i></a></li> <li><a href="<?php echo site_url();?>feed/rss"><i class="fa fa-rss"></i></a></li> </ul> </div><!--//branding--> <nav id="main-nav" class="main-nav navbar-right" role="navigation" > <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div> <div id="navbar" class="menu navbar-collapse collapse pull-right"> <ul class="nav navbar-nav navbar-right"> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-search"></i></a> <div class="dropdown-menu searchbox" role="menu"> <form id="search" class="navbar-form search" role="search"> <div class="input-group"> <input type="search" name="search" class="form-control" placeholder="Type to search"> <span class="input-group-btn"><button type="submit" class="btn btn-default btn-submit"><i class="fa fa-angle-right"></i></button></span> </div> </form> </div> </li><!-- /.searchbox --> </ul> <?php echo menu('navbar-nav navbar-right');?> </div> </nav> </div><!--//container--> </header><!--//header--> <div class="container sections-wrapper"> <div class="row"> <div class="primary col-md-8 col-sm-12 col-xs-12"> <?php echo content();?> </div><!--//primary--> <div class="secondary col-md-4 col-sm-12 col-xs-12"> <aside class="aside section"> <div class="section-inner"> <h2 class="heading">About</h2> <div class="content"> <?php echo blog_description();?> </div><!--//content--> </div><!--//section-inner--> </aside><!--//section--> <aside class="recent-posts aside section"> <div class="section-inner"> <!-- Tab nav --> <ul class="nav nav-tabs" role="tablist"> <li role="presentation" class="active"><a href="#recent-posts" aria-controls="recent-posts" role="tab" data-toggle="tab">Recent Posts</a></li> <?php if (config('views.counter') === 'true') :?> <li role="presentation"><a href="#popular-posts" aria-controls="popular-posts" role="tab" data-toggle="tab">Popular Posts</a></li> <?php endif;?> </ul> <!-- Tab content --> <div class="tab-content"> <div role="tabpanel" class="tab-pane active" id="recent-posts"> <h2 class="hide">Recent Posts</h2> <?php $lists = recent_posts(true);?> <?php $char = 60;?> <?php foreach ($lists as $l):?> <?php if (strlen(strip_tags($l->title)) > $char) { $recentTitle = shorten($l->title, $char) . '...';} else {$recentTitle = $l->title;}?> <div class="item"> <h3 class="title"><a href="<?php echo $l->url;?>"><?php echo $recentTitle;?></a></h3> <div class="content"> <p><?php echo shorten($l->body, 75); ?>...</p> <a class="more-link" href="<?php echo $l->url;?>"><i class="fa fa-link"></i> Read more</a> </div><!--//content--> </div> <?php endforeach;?> </div> <?php if (config('views.counter') === 'true') :?> <div role="tabpanel" class="tab-pane" id="popular-posts"> <h2 class="hide">Popular Posts</h2> <?php $lists = popular_posts(true);?> <?php $char = 60;?> <?php foreach ($lists as $l):?> <?php if (strlen(strip_tags($l->title)) > $char) { $recentTitle = shorten($l->title, $char) . '...';} else {$recentTitle = $l->title;}?> <div class="item"> <h3 class="title"><a href="<?php echo $l->url;?>"><?php echo $recentTitle;?></a></h3> <div class="content"> <p><?php echo shorten($l->body, 75); ?>...</p> <a class="more-link" href="<?php echo $l->url;?>"><i class="fa fa-link"></i> Read more</a> </div><!--//content--> </div> <?php endforeach;?> </div> <?php endif;?> </div> </div><!--//section-inner--> </aside><!--//section--> <?php if (disqus()): ?> <aside class="comments aside section"> <div class="section-inner"> <h2 class="heading">Comments</h2> <div class="content"> <?php echo recent_comments() ?> <style>.dsq-widget-list {padding:0;}li.dsq-widget-item {color:#434343;border-bottom: 1px dotted #d9d9d9;margin: 0 0 10px;padding-bottom: 10px;font-size:14px;}li.dsq-widget-item:last-child{border-bottom:none;margin-bottom:0;}a.dsq-widget-user {font-weight:normal;}img.dsq-widget-avatar {margin-right:10px; }.dsq-widget-comment {display:block;padding-top:5px;}.dsq-widget-comment p {display:block;margin:0;padding:0!important;font-size:14px!important;}p.dsq-widget-meta {padding-top:5px!important;margin:0;font-size:14px!important;}#dsq-combo-widget.grey #dsq-combo-content .dsq-combo-box {background: transparent;}#dsq-combo-widget.grey #dsq-combo-tabs li {background: #DDDDDD;}</style> </div><!--//content--> </div><!--//section-inner--> </aside><!--//section--> <?php endif; ?> <aside class="archive aside section"> <div class="section-inner"> <h2 class="heading">Archive</h2> <div class="content"> <?php echo archive_list();?> </div><!--//content--> </div><!--//section-inner--> </aside><!--//section--> <aside class="category-list aside section"> <div class="section-inner"> <h2 class="heading">Category</h2> <div class="content"> <?php echo category_list();?> </div><!--//content--> </div><!--//section-inner--> </aside><!--//section--> <aside class="tags aside section"> <div class="section-inner"> <h2 class="heading">Tags</h2> <div class="tag-cloud"> <?php $tags = tag_cloud(true);?> <?php foreach ($tags as $tag => $count):?> <a class="more-link" href="<?php echo site_url();?>tag/<?php echo $tag;?>"><?php echo tag_i18n($tag);?></a> <?php endforeach;?> </div><!--//content--> </div><!--//section-inner--> </aside><!--//section--> </div><!--//secondary--> </div><!--//row--> </div><!--//masonry--> <!-- ******FOOTER****** --> <footer class="footer"> <div class="container text-center"> <?php echo copyright();?> </div><!--//container--> </footer><!--//footer--> <!-- Javascript --> <script type="text/javascript" src="<?php echo site_url();?>themes/blog/js/jquery-latest.min.js"></script> <script type="text/javascript" src="<?php echo site_url();?>themes/blog/js/bootstrap.min.js"></script> <?php if (analytics()): ?><?php echo analytics() ?><?php endif; ?> </body> </html>
Et après je perds le fil car j' ai 2 pages pareils (mains.php et post.php), elles représentent l administration du cms.
Page themes/blog/mains.php
<?php if (!empty($breadcrumb)): ?> <div class="breadcrumb"><?php echo $breadcrumb ?></div> <?php endif; ?> <?php if (config('category.info') === 'true'):?> <?php if (!empty($category)): ?> <div class="section"> <div class="section-inner"> <div class="content"> <div class="item"> <h2 class="title"><?php echo $category->title;?></h2> <div class="text-left"> <?php echo $category->body; ?> </div><!--//desc--> </div><!--//item--> </div><!--//content--> </div> </div> <?php endif; ?> <?php endif; ?> <?php $i = 0; $len = count($posts); ?> <?php foreach ($posts as $p): ?> <?php if ($i == 0) { $class = 'post first'; } elseif ($i == $len - 1) { $class = 'post last'; } else { $class = 'post'; } $i++; ?> <section class="post section <?php echo $class ?>" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting"> <div class="section-inner"> <div class="content"> <div class="item"> <?php if (!empty($p->image)) { ?> <div class="featured featured-image"> <a href="<?php echo $p->url ?>"><img itemprop="image" src="<?php echo $p->image; ?>" alt="<?php echo $p->title ?>"/></a> </div> <?php } ?> <?php if (!empty($p->video)) { ?> <div class="featured featured-video embed-responsive embed-responsive-16by9"> <iframe class="embed-responsive-item" src="https://www.youtube.com/embed/<?php echo $p->video; ?>" frameborder="0" allowfullscreen></iframe> </div> <?php } ?> <?php if (!empty($p->audio)) { ?> <div class="featured featured-audio embed-responsive embed-responsive-16by9"> <iframe class="embed-responsive-item" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=<?php echo $p->audio;?>&auto_play=false&visual=true"></iframe> </div> <?php } ?> <?php if (!empty($p->quote)) { ?> <div class="featured featured-quote"> <blockquote class="quote"><i class="fa fa-quote-left"></i> <?php echo $p->quote ?> <i class="fa fa-quote-right"></i></blockquote> </div> <?php } ?> <div class="info text-left"> <?php if (!empty($p->link)) { ?> <h2 class="title" itemprop="headline"><a target="_blank" href="<?php echo $p->link ?>"><?php echo $p->title;?> <i class="fa fa-external-link"></i></a></h2> <?php } else {?> <h2 class="title" itemprop="headline"><a href="<?php echo $p->url;?>"><?php echo $p->title;?></a></h2> <?php } ?> <p class="meta"> <span class="date" itemprop="datePublished"><?php echo date('d F Y', $p->date) ?></span> - Posted in <span itemprop="articleSection"><?php echo $p->category;?></span> by <span itemprop="author"><a href="<?php echo $p->authorUrl;?>"><?php echo $p->author;?></a></span> <?php if (disqus_count()) { ?> with <span><i class="fa fa-comments"></i> <a href="<?php echo $p->url ?>#disqus_thread"> comments</a></span> <?php } elseif (facebook()) { ?> with <i class="fa fa-comments"></i> <a href="<?php echo $p->url ?>#comments"><span><fb:comments-count href=<?php echo $p->url ?>></fb:comments-count> comments</span></a> <?php } ?> </p> </div> <div class="desc text-left" itemprop="articleBody"> <?php echo get_teaser($p->body, $p->url) ?> </div><!--//desc--> <div style="position:relative;"> <?php if (config('teaser.type') === 'trimmed'):?> <span class="more"><a class="btn btn-cta-secondary" href="<?php echo $p->url;?>">Read more</a></span> <?php endif;?> <span class="share pull-right"> <a target="_blank" class="first" href="https://www.facebook.com/sharer.php?u=<?php echo $p->url ?>&t=<?php echo $p->title ?>"><i class="fa fa-facebook"></i></a> <a target="_blank" href="https://twitter.com/share?url=<?php echo $p->url ?>&text=<?php echo $p->title ?>"><i class="fa fa-twitter"></i></a> <a target="_blank" class="last" href="https://plus.google.com/share?url=<?php echo $p->url ?>"><i class="fa fa-google-plus"></i></a> </span> <div style="clear:both;"></div> </div> </div><!--//item--> </div><!--//content--> </div><!--//section-inner--> </section><!--//section--> <?php endforeach; ?> <?php if (!empty($pagination['prev']) || !empty($pagination['next'])): ?> <div class="pagination"><?php echo $pagination['html'];?></div> <?php endif; ?> <?php if (disqus_count()): ?> <?php echo disqus_count() ?> <?php endif; ?>
Page themes/blog/post.php
<?php if (!empty($breadcrumb)): ?> <div class="breadcrumb"><?php echo $breadcrumb ?></div> <?php endif; ?> <section class="inpost post section" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting"> <div class="section-inner"> <div class="content"> <?php if (login()) { echo tab($p); } ?> <div class="item"> <?php if (!empty($p->image)) { ?> <div class="featured featured-image"> <a href="<?php echo $p->url ?>"><img itemprop="image" src="<?php echo $p->image; ?>" alt="<?php echo $p->title ?>"/></a> </div> <?php } ?> <?php if (!empty($p->video)) { ?> <div class="featured featured-video embed-responsive embed-responsive-16by9"> <iframe class="embed-responsive-item" src="https://www.youtube.com/embed/<?php echo $p->video; ?>" frameborder="0" allowfullscreen></iframe> </div> <?php } ?> <?php if (!empty($p->audio)) { ?> <div class="featured featured-audio embed-responsive embed-responsive-16by9"> <iframe class="embed-responsive-item" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=<?php echo $p->audio;?>&auto_play=false&visual=true"></iframe> </div> <?php } ?> <?php if (!empty($p->quote)) { ?> <div class="featured featured-quote"> <blockquote class="quote"><i class="fa fa-quote-left"></i> <?php echo $p->quote ?> <i class="fa fa-quote-right"></i></blockquote> </div> <?php } ?> <div class="info text-left"> <?php if (!empty($p->link)) { ?> <h1 class="title" itemprop="headline"><a target="_blank" href="<?php echo $p->link ?>"><?php echo $p->title;?> <i class="fa fa-external-link"></i></a></h1> <?php } else { ?> <h1 class="title" itemprop="headline"><?php echo $p->title;?></h1> <?php } ?> <p class="meta"> <span class="date" itemprop="datePublished"><?php echo date('d F Y', $p->date) ?></span> - Posted in <span itemprop="articleSection"><?php echo $p->category;?></span> by <span itemprop="author"><a href="<?php echo $p->authorUrl;?>"><?php echo $p->author;?></a></span> </p> </div> <div class="desc text-left" itemprop="articleBody"> <?php echo $p->body; ?> </div><!--//desc--> <div style="margin-top:30px;position:relative;"> <span class="tags"><i class="fa fa-tags"></i> <?php echo $p->tag;?></span> <?php if (disqus_count()) { ?> <span><i class="fa fa-comments"></i> <a href="<?php echo $p->url ?>#disqus_thread"> comments</a></span> <?php } elseif (facebook()) { ?> <i class="fa fa-comments"></i> <a href="<?php echo $p->url ?>#comments"><span><fb:comments-count href=<?php echo $p->url ?>></fb:comments-count> comments</span></a> <?php } ?> <span class="share pull-right"> <a target=" " class="first" href="https://www.facebook.com/sharer.php?u=<?php echo $p->url ?>&t=<?php echo $p->title ?>"><i class="fa fa-facebook"></i></a> <a target=" " href="https://twitter.com/share?url=<?php echo $p->url ?>&text=<?php echo $p->title ?>"><i class="fa fa-twitter"></i></a> <a target=" " class="last" href="https://plus.google.com/share?url=<?php echo $p->url ?>"><i class="fa fa-google-plus"></i></a> </span> <div style="clear:both;"></div> </div> <div style="margin-top:30px;position:relative;"> <hr> <?php if (!empty($next)): ?> <span class="newer"><a href="<?php echo($next['url']); ?>" rel="next"><i class="fa fa-long-arrow-left"></i> Next Post</a></span> <?php endif; ?> <?php if (!empty($prev)): ?> <span class="older pull-right"><a href="<?php echo($prev['url']); ?>" rel="prev">Previous Post <i class="fa fa-long-arrow-right"></i></a></span> <?php endif; ?> <div style="clear:both;"></div> </div> <?php if (disqus()): ?> <?php echo disqus($p->title, $p->url) ?> <?php endif; ?> <?php if (disqus_count()): ?> <?php echo disqus_count() ?> <?php endif; ?> <?php $tags = get_related($p->related, true, config('related.count'));?> <?php $char = 30; $total = count($tags); $i = 1; if ($total >= 1) { ?> <div class="related related-posts" style="margin-top:30px;position:relative;"> <hr> <h2 class="heading">Related Posts</h2> <?php foreach ($tags as $t):?> <div class="item col-md-4"> <?php if (strlen(strip_tags($t->title)) > $char) { $relatedTitle = shorten($t->title, $char) . '...';} else {$relatedTitle = $t->title;}?> <h3 class="title"><a href="<?php echo $t->url;?>"><?php echo $relatedTitle;?></a></h3> <div class="content"> <p><?php echo shorten($t->body, 60); ?>... <a class="more-link" href="<?php echo $t->url;?>">more</a></p> </div><!--//content--> </div> <?php if ($i++ >= config('related.count')) break; ?> <?php endforeach;?> <div style="clear:both;"></div> </div> <?php }?> </div><!--//item--> </div><!--//content--> </div><!--//section-inner--> </section><!--//section--> <?php if (facebook() || disqus()): ?> <section class="comment-wrapper post section"> <div class="section-inner"> <div class="content"> <div id="comments"> <h2 class="heading">Comments</h2> <?php if (facebook()): ?> <div class="fb-comments" data-href="<?php echo $p->url ?>" data-numposts="<?php echo config('fb.num') ?>" data-colorscheme="<?php echo config('fb.color') ?>"></div> <?php endif; ?> <?php if (disqus()): ?> <div id="disqus_thread"></div> <?php endif; ?> </div> </div><!--//content--> </div><!--//section-inner--> </section><!--//section--> <?php endif; ?>
Et pui la page upload :
<?php require 'system/includes/dispatch.php'; require 'system/includes/session.php'; // Load the configuration file config('source', 'config/config.ini'); // Set the timezone if (config('timezone')) { date_default_timezone_set(config('timezone')); } else { date_default_timezone_set('Asia/Jakarta'); } $whitelist = array('jpg', 'jpeg', 'png', 'gif'); $name = null; $dir = 'content/images/'; $error = null; $timestamp = date('YmdHis'); $path = null; if (login()) { if (!is_dir($dir)) { mkdir($dir, 0755, true); } if (isset($_FILES)) { if (isset($_FILES['file'])) { $tmp_name = $_FILES['file']['tmp_name']; $name = basename($_FILES['file']['name']); $error = $_FILES['file']['error']; $path = $dir . $timestamp . '-' . $name; $check = getimagesize($tmp_name); if($check !== false) { if ($error === UPLOAD_ERR_OK) { $extension = pathinfo($name, PATHINFO_EXTENSION); if (!in_array(strtolower($extension), $whitelist)) { $error = 'Invalid file type uploaded.'; } else { move_uploaded_file($tmp_name, $dir . $timestamp . '-' . $name); } } } else { $error = "File is not an image."; } } } echo json_encode(array( 'path' => $path, 'name' => $name, 'error' => $error, )); die(); } else { $login = site_url() . 'login'; header("location: $login"); }
15 sept. 2019 à 15:57
NB: Pour poster ton code sur le forum, merci d'utiliser les balises de code
https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
.
15 sept. 2019 à 16:30